Skip to content

Commit

Permalink
Merge pull request #2 from GuyHoozdis/master
Browse files Browse the repository at this point in the history
Add support for python 3.5
  • Loading branch information
tabbedout-admin authored Mar 8, 2017
2 parents 0a22e91 + 5eaf025 commit 5536472
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 10 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,42 @@ Also see the [example response data](./tests/fixtures/ok.json).

### Testing

make test
open coverage/index.html
There are several ways to run the projects tests. The recommended approach
is to run `tox`, becuase your testing environment will be properly set-up.

For more thorough multi-Django version testing use:
For a thorough multi-Django version testing use:

tox
$ tox

To list the configured environments:

$ tox -l
py27-django15
py27-django16
py27-django17
py27-django18
py27-djangorq
py35-django18

You can execute a single test environment:

$ tox -e py35-django18

If you manage your own environment, you can run the `make test` command
yourself. It is recommened that you do this in a _virtualenv_.

$ pip install -r requirements.txt # Normally tox would install these
$ pip install "django<1.9" django-rq # Normally tox would install these
$ make test
$ open coverage/index.html

You can run a subset of tests by setting the `PACKAGES` variable:

$ make PACKAGES="tests.test_endpoint tests.test_service_resources"

To run a single test:

$ make PACKAGES=tests.test_endpoint:EndpointTestCase.test_status_endpoint_returns_200_on_success


### License
Expand Down
4 changes: 3 additions & 1 deletion canary_endpoint/resources/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def check(self):
result = super(Database, self).check()
try:
cursor = self.connection.cursor()
map(cursor.execute, self.statements)
for sql in self.statements:
cursor.execute(sql)

return dict(result, status=OK)
except (DatabaseError, MySQLError) as e:
return dict(result, status=ERROR, error=str(e))
Expand Down
8 changes: 8 additions & 0 deletions canary_endpoint/resources/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import requests
try:
from json.decoder import JSONDecodeError
except ImportError:
class JSONDecodeError(ValueError):
pass

from ..constants import OK, WARNING, ERROR
from ..decorators import timed
Expand Down Expand Up @@ -57,5 +62,8 @@ def check(self):
elif service_status == ERROR:
status = ERROR
return dict(result, status=status, result=service_result)
except JSONDecodeError:
error_message = 'No JSON object could be decoded'
return dict(result, status=ERROR, result=None, error=error_message)
except (AttributeError, ValueError) as e:
return dict(result, status=ERROR, result=None, error=str(e))
2 changes: 1 addition & 1 deletion canary_endpoint/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.0'
__version__ = '0.7.0'
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
classifiers=[
'Environment :: Web Environment',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
],
)
4 changes: 1 addition & 3 deletions tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ def setUp(self):
self.expected_data = self.get_fixture('ok.json')

def assert_content(self, content, status='ok', **overrides):
data = json.loads(content)
data = json.loads(content.decode('utf-8'))
expected_data = self.expected_data.copy()
expected_data['status'] = status
expected_data['resources'].update(**overrides)
# print data; print '*' * 80; print expected_data # DEBUG
self.assertEqual(data, expected_data)

# Assertions
Expand All @@ -28,7 +27,6 @@ def assert_content(self, content, status='ok', **overrides):
def test_status_endpoint_returns_200_on_success(self):
response = self.client.get('/_status/')
self.assertEqual(response.status_code, 200)
# print response.content # DEBUG uncomment when updating ok.json
self.assert_content(response.content)

def test_status_endpoint_returns_200_with_warning_on_timeout(self):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py27-django{15,16,17,18,rq}
py27-django{15,16,17,18,rq}, py35-django18

[testenv]
setenv =
Expand Down

0 comments on commit 5536472

Please sign in to comment.