diff --git a/tests/__init__.py b/tests/__init__.py index fc99f6b6..d75f2e89 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -23,3 +23,5 @@ ``python setup.py test``). """ +import warnings +warnings.simplefilter('error') diff --git a/tests/test_filtering.py b/tests/test_filtering.py index 0c3efe59..6ad71e0a 100644 --- a/tests/test_filtering.py +++ b/tests/test_filtering.py @@ -14,6 +14,7 @@ from datetime import datetime from datetime import time from unittest2 import skip +import sys # This import is unused but is required for testing on PyPy. CPython can # use psycopg2, but PyPy can only use psycopg2cffi. @@ -40,6 +41,11 @@ from .helpers import loads from .helpers import ManagerTestBase +if sys.version_info < (3, 0): + to_string = unicode +else: + to_string = str + #: The PostgreSQL class used to create a temporary database for testing. #: @@ -949,7 +955,7 @@ def test_to_many_filter_by_relation(self): self.session.add(article) for i in range(1, 3): comment = self.Comment(id=i) - tag = self.Tag(name=str(i)) + tag = self.Tag(name=to_string(i)) comment.article = article comment.tag = tag self.session.add_all([comment, tag]) diff --git a/tests/test_validation.py b/tests/test_validation.py index beca25de..7c7d3044 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -301,12 +301,9 @@ def test_create_absent(self): """ data = dict(data=dict(type='person')) response = self.app.post('/api/person', data=dumps(data)) - assert response.status_code == 400 - document = loads(response.data) - errors = document['errors'] - error = errors[0] - assert 'validation' in error['title'].lower() - assert 'email' in error['detail'].lower() + print(response) + print(response.data) + check_sole_error(response, 400, ['validation', 'email']) # Check that the person was not created. assert self.session.query(self.Person).count() == 0 @@ -321,12 +318,7 @@ def test_create_invalid(self): } } response = self.app.post('/api/person', data=dumps(data)) - assert response.status_code == 400 - document = loads(response.data) - errors = document['errors'] - error = errors[0] - assert 'validation' in error['title'].lower() - assert 'email' in error['detail'].lower() + check_sole_error(response, 400, ['validation', 'email']) # Check that the person was not created. assert self.session.query(self.Person).count() == 0 @@ -363,11 +355,6 @@ def test_update_invalid(self): } } response = self.app.patch('/api/person/1', data=dumps(data)) - assert response.status_code == 400 - document = loads(response.data) - errors = document['errors'] - error = errors[0] - assert 'validation' in error['title'].lower() - assert 'email' in error['detail'].lower() + check_sole_error(response, 400, ['validation', 'email']) # Check that the person was not updated. assert person.email == u'example@example.com'