From dbc1c3edbc529ea0276f19d35418317ecf458fb9 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 5 Oct 2016 20:32:10 -0700 Subject: [PATCH 1/2] Resurrect some tests This resurrect (and skip) some tests mostly in the hope that when minimal modification are made to the code base they can be unit tested. --- .travis.yml | 8 ++++++++ README.rst | 7 +++++++ reqoauth_test.py | 5 +++-- requirements-tests.txt | 3 +++ tools/apache_count.py | 10 ++++++---- tools/tests/test_apache_reader.py | 14 ++++++++------ 6 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 .travis.yml create mode 100644 requirements-tests.txt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..bf3622c3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python +python: + - '2.7' +install: + - pip install -r requirements-tests.txt -r requirements.txt +script: py.test + + diff --git a/README.rst b/README.rst index 79c107ca..6b2ab8d8 100755 --- a/README.rst +++ b/README.rst @@ -223,3 +223,10 @@ Users reporting stale data being displayed? Try: To see what fastly thinks it knows about a page (or how it's getting to you) try: curl -I -H 'Fastly-Debug: 1' https://pypi.python.org/pypi/setuptools + +Running the Tests +================= + +The dependencies necessary to run the tests are in the +``requirements-tests.txt`` file and can be installed with ``pip install -r +requirements-test.txt``. diff --git a/reqoauth_test.py b/reqoauth_test.py index e1450e14..2b6d91e4 100755 --- a/reqoauth_test.py +++ b/reqoauth_test.py @@ -2,8 +2,9 @@ #logging.basicConfig(level=logging.DEBUG) import requests -from requests.auth import OAuth1 +from requests_oauthlib import OAuth1 from urlparse import parse_qs +import pytest CONSUMER_KEY = u'sekrit' CONSUMER_SECRET = u'123' @@ -69,7 +70,7 @@ def register(): verify=False) print response.text - +@pytest.mark.skip(reason='This seem to be a utility function') def test(ACCESS_TOKEN, ACCESS_SECRET, **params): '''Access the test resource passing optional parameters. diff --git a/requirements-tests.txt b/requirements-tests.txt new file mode 100644 index 00000000..f33b86e9 --- /dev/null +++ b/requirements-tests.txt @@ -0,0 +1,3 @@ +requests_oauthlib +pytest>2.9 +egenix-mx-base diff --git a/tools/apache_count.py b/tools/apache_count.py index a6d9bb4b..606fe7ed 100755 --- a/tools/apache_count.py +++ b/tools/apache_count.py @@ -1,6 +1,8 @@ #!/usr/bin/python -import sys, os, re, psycopg, ConfigParser, urlparse, gzip, bz2 +from __future__ import print_function + +import sys, os, re, psycopg2, ConfigParser, urlparse, gzip, bz2 from mx.DateTime import DateTime from mx.DateTime.Timezone import utc_offset @@ -16,7 +18,7 @@ def main(argv): if len(argv) != 3: - print "Usage: apache_count.py configfile logfile" + print("Usage: apache_count.py configfile logfile") raise SystemExit # Read config file p = ConfigParser.ConfigParser() @@ -27,7 +29,7 @@ def main(argv): dbname = p.get('database', 'name') dbuser = p.get('database', 'user') dbpass = p.get('database', 'password') - dbconn = psycopg.connect(database=dbname, user=dbuser, password=dbpass) + dbconn = psycopg2.connect(database=dbname, user=dbuser, password=dbpass) cursor = dbconn.cursor() filename = argv[2] @@ -85,7 +87,7 @@ def main(argv): cursor.execute("update release_files set downloads=%s " "where filename=%s", (count, filename)) # Update the download timestamp - date = psycopg.TimestampFromMx(date) + date = psycopg2.TimestampFromMx(date) cursor.execute("update timestamps set value=%s " "where name='http'", (date,)) dbconn.commit() diff --git a/tools/tests/test_apache_reader.py b/tools/tests/test_apache_reader.py index 9f47dd88..f3af7f9d 100755 --- a/tools/tests/test_apache_reader.py +++ b/tools/tests/test_apache_reader.py @@ -5,6 +5,7 @@ from StringIO import StringIO import csv import shutil +import pytest # just to make sur we can launch it # from the top folder @@ -99,6 +100,7 @@ def _test_useragent(self): self.assertEquals(logs[45]['useragent'], 'Python-urllib/2.5 setuptools/0.6c7') + @pytest.mark.skip(reason="No clue how this one is supposed to work") def test_apache_count(self): # creating stats so they can be used by @@ -118,7 +120,7 @@ def read(self): # just to make sure it doesn't brake try: - main(config_file, log_sample) + main(('apache_count.py', config_file, log_sample)) finally: urllib2.urlopen = old_open @@ -215,7 +217,7 @@ def test_read_stats(self): read = stats.read_stats(results) first_entry = read.next() - self.assertEquals(first_entry['count'], '1') + self.assertEquals(first_entry['count'], 1) self.assertEquals(first_entry['packagename'], 'appwsgi') def test_compression(self): @@ -225,7 +227,7 @@ def test_compression(self): read = stats.read_stats(bz2_file) first_entry = read.next() - self.assertEquals(first_entry['count'], '1') + self.assertEquals(first_entry['count'], 1) self.assertEquals(first_entry['packagename'], 'appwsgi') def test_build_local_stats(self): @@ -237,7 +239,7 @@ def test_build_local_stats(self): read = stats.read_stats(stats_file) first_entry = read.next() - self.assertEquals(first_entry['count'], '1') + self.assertEquals(first_entry['count'], 1) self.assertEquals(first_entry['packagename'], '4Suite-XML') @@ -267,7 +269,7 @@ def read(self): read = stats.read_stats(url) first_entry = read.next() - self.assertEquals(first_entry['count'], '1') + self.assertEquals(first_entry['count'], 1) self.assertEquals(first_entry['packagename'], 'appwsgi') # checking that the cache is filled @@ -279,7 +281,7 @@ def read(self): # the cache should be activated now read = stats.read_stats(url) first_entry = read.next() - self.assertEquals(first_entry['count'], '1') + self.assertEquals(first_entry['count'], 1) self.assertEquals(first_entry['packagename'], 'appwsgi') From dc92c377ce1d10b2369d38ba58c139fa53095f64 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 17 Nov 2016 10:53:09 -0800 Subject: [PATCH 2/2] switch from skip to xfail. --- tools/tests/test_apache_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tests/test_apache_reader.py b/tools/tests/test_apache_reader.py index f3af7f9d..262413f0 100755 --- a/tools/tests/test_apache_reader.py +++ b/tools/tests/test_apache_reader.py @@ -100,7 +100,7 @@ def _test_useragent(self): self.assertEquals(logs[45]['useragent'], 'Python-urllib/2.5 setuptools/0.6c7') - @pytest.mark.skip(reason="No clue how this one is supposed to work") + @pytest.mark.xfail(reason="No clue how this one is supposed to work") def test_apache_count(self): # creating stats so they can be used by