Skip to content
This repository has been archived by the owner on May 30, 2020. It is now read-only.

Commit

Permalink
Resurrect some tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Carreau committed Oct 6, 2016
1 parent 984f26b commit dbc1c3e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: python
python:
- '2.7'
install:
- pip install -r requirements-tests.txt -r requirements.txt
script: py.test


7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
5 changes: 3 additions & 2 deletions reqoauth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests_oauthlib
pytest>2.9
egenix-mx-base
10 changes: 6 additions & 4 deletions tools/apache_count.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions tools/tests/test_apache_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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')


Expand Down Expand Up @@ -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
Expand All @@ -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')


Expand Down

0 comments on commit dbc1c3e

Please sign in to comment.