diff --git a/tests/helpers.py b/tests/helpers.py index b4451615..ac196aba 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -18,6 +18,8 @@ from json import JSONEncoder import sys import types +from unittest import skipUnless as skip_unless +from unittest import TestCase import uuid from flask import Flask @@ -29,7 +31,6 @@ has_flask_sqlalchemy = False else: has_flask_sqlalchemy = True -from nose import SkipTest from sqlalchemy import create_engine from sqlalchemy import event from sqlalchemy.dialects.postgresql import UUID @@ -71,60 +72,6 @@ def isclass(obj): return isinstance(obj, CLASS_TYPES) -def skip_unless(condition, reason=None): - """Decorator that skips `test` unless `condition` is ``True``. - - This is a replacement for :func:`unittest.skipUnless` that works with - ``nose``. The argument ``reason`` is a string describing why the test was - skipped. - - This decorator can be applied to functions, methods, or classes. - - """ - - def decorated(test): - """Returns a decorated version of ``test``, as described in the - wrapper defined within. - - """ - message = 'Skipped {0}: {1}'.format(test.__name__, reason) - - # HACK-ish: If the test is actually a test class, override the - # setup method so that the only thing it does is raise - # `SkipTest`. Thus whenever setup() is called, the test that - # would have been run is skipped. - if isclass(test): - if not condition: - def new_setup(self): - raise SkipTest(message) - - test.setup = new_setup - return test - - @wraps(test) - def inner(*args, **kw): - """Checks that ``condition`` is ``True`` before executing - ``test(*args, **kw)``. - - """ - if not condition: - raise SkipTest(message) - return test(*args, **kw) - - return inner - - return decorated - - -def skip(reason=None): - """Unconditionally skip a test. - - This is a convenience function for ``skip_unless(False, reason)``. - - """ - return skip_unless(False, reason) - - def parse_version(version_string): """Parses the Flask-SQLAlchemy version string into a pair of integers. @@ -270,7 +217,7 @@ def default(self, obj): return super(BetterJSONEncoder, self).default(obj) -class FlaskTestBase(object): +class FlaskTestBase(TestCase): """Base class for tests which use a Flask application. The Flask test client can be accessed at ``self.app``. The Flask @@ -278,7 +225,7 @@ class FlaskTestBase(object): """ - def setup(self): + def setUp(self): """Creates the Flask application and the APIManager.""" # create the Flask application app = Flask(__name__) @@ -316,20 +263,21 @@ def database_uri(self): return 'sqlite://' +@skip_unless(has_flask_sqlalchemy, 'Flask-SQLAlchemy not found') class FlaskSQLAlchemyTestBase(FlaskTestBase, DatabaseMixin): """Base class for tests that use Flask-SQLAlchemy (instead of plain old SQLAlchemy). - If Flask-SQLAlchemy is not installed, the :meth:`.setup` method will + If Flask-SQLAlchemy is not installed, the :meth:`.setUp` method will raise :exc:`nose.SkipTest`, so that each test method will be skipped individually. """ - def setup(self): - super(FlaskSQLAlchemyTestBase, self).setup() - if not has_flask_sqlalchemy: - raise SkipTest('Flask-SQLAlchemy not found.') + def setUp(self): + super(FlaskSQLAlchemyTestBase, self).setUp() + # if not has_flask_sqlalchemy: + # raise SkipTest('Flask-SQLAlchemy not found.') self.flaskapp.config['SQLALCHEMY_DATABASE_URI'] = self.database_uri() # This is to avoid a warning in earlier versions of # Flask-SQLAlchemy. @@ -339,7 +287,7 @@ def setup(self): self.db = SQLAlchemy(self.flaskapp) self.session = self.db.session - def teardown(self): + def tearDown(self): """Drops all tables and unregisters Flask-SQLAlchemy session signals. @@ -351,7 +299,7 @@ def teardown(self): class SQLAlchemyTestBase(FlaskTestBase, DatabaseMixin): """Base class for tests that use a SQLAlchemy database. - The :meth:`setup` method does the necessary SQLAlchemy + The :meth:`setUp` method does the necessary SQLAlchemy initialization, and the subclasses should populate the database with models and then create the database (by calling ``self.Base.metadata.create_all()``). @@ -362,12 +310,12 @@ class SQLAlchemyTestBase(FlaskTestBase, DatabaseMixin): """ - def setup(self): + def setUp(self): """Initializes the components necessary for models in a SQLAlchemy database. """ - super(SQLAlchemyTestBase, self).setup() + super(SQLAlchemyTestBase, self).setUp() engine = create_engine(self.database_uri(), convert_unicode=True) self.Session = sessionmaker(autocommit=False, autoflush=False, bind=engine) @@ -375,7 +323,7 @@ def setup(self): self.Base = declarative_base() self.Base.metadata.bind = engine - def teardown(self): + def tearDown(self): """Drops all tables from the temporary database.""" self.session.remove() self.Base.metadata.drop_all() @@ -396,11 +344,11 @@ class ManagerTestBase(SQLAlchemyTestBase): """ - def setup(self): + def setUp(self): """Initializes an instance of :class:`~flask.ext.restless.APIManager` with a SQLAlchemy session. """ - super(ManagerTestBase, self).setup() + super(ManagerTestBase, self).setUp() self.manager = APIManager(self.flaskapp, session=self.session) diff --git a/tests/test_bulk.py b/tests/test_bulk.py index 9dfcf2bc..0991e639 100644 --- a/tests/test_bulk.py +++ b/tests/test_bulk.py @@ -10,13 +10,14 @@ # License version 3 and under the 3-clause BSD license. For more # information, see LICENSE.AGPL and LICENSE.BSD. """Unit tests for the JSON API Bulk extension.""" +from unittest import skip + from sqlalchemy import Column from sqlalchemy import Integer from .helpers import dumps from .helpers import loads from .helpers import ManagerTestBase -from .helpers import skip @skip('Not yet implemented') @@ -30,8 +31,8 @@ class TestCreating(ManagerTestBase): """ - def setup(self): - super(TestCreating, self).setup() + def setUp(self): + super(TestCreating, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -72,8 +73,8 @@ class TestUpdating(ManagerTestBase): """ - def setup(self): - super(TestUpdating, self).setup() + def setUp(self): + super(TestUpdating, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -229,8 +230,8 @@ class TestDeleting(ManagerTestBase): """ - def setup(self): - super(TestDeleting, self).setup() + def setUp(self): + super(TestDeleting, self).setUp() class Person(self.Base): __tablename__ = 'person' diff --git a/tests/test_creating.py b/tests/test_creating.py index 87bfcb87..b71518d8 100644 --- a/tests/test_creating.py +++ b/tests/test_creating.py @@ -21,6 +21,7 @@ """ from __future__ import division from datetime import datetime +from unittest import skip import dateutil from sqlalchemy import Column @@ -50,7 +51,6 @@ from .helpers import ManagerTestBase from .helpers import MSIE8_UA from .helpers import MSIE9_UA -from .helpers import skip def raise_s_exception(instance, *args, **kw): @@ -77,14 +77,14 @@ def raise_d_exception(*args, **kw): class TestCreating(ManagerTestBase): """Tests for creating resources.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestCreating, self).setup() + super(TestCreating, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -835,8 +835,8 @@ def test_to_many_relationship_conflicting_type(self): class TestProcessors(ManagerTestBase): """Tests for pre- and postprocessors.""" - def setup(self): - super(TestProcessors, self).setup() + def setUp(self): + super(TestProcessors, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -889,14 +889,14 @@ class TestAssociationProxy(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask.ext.restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the models used in the test methods. """ - super(TestAssociationProxy, self).setup() + super(TestAssociationProxy, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -995,9 +995,9 @@ class TestFlaskSQLAlchemy(FlaskSQLAlchemyTestBase): """ - def setup(self): + def setUp(self): """Creates the Flask-SQLAlchemy database and models.""" - super(TestFlaskSQLAlchemy, self).setup() + super(TestFlaskSQLAlchemy, self).setUp() class Person(self.db.Model): id = self.db.Column(self.db.Integer, primary_key=True) diff --git a/tests/test_deleting.py b/tests/test_deleting.py index 2016543e..d3b0c8e3 100644 --- a/tests/test_deleting.py +++ b/tests/test_deleting.py @@ -18,6 +18,8 @@ specification. """ +from unittest import skip + from sqlalchemy import Column from sqlalchemy import ForeignKey from sqlalchemy import Integer @@ -33,20 +35,19 @@ from .helpers import ManagerTestBase from .helpers import MSIE8_UA from .helpers import MSIE9_UA -from .helpers import skip class TestDeleting(ManagerTestBase): """Tests for deleting resources.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestDeleting, self).setup() + super(TestDeleting, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -173,8 +174,8 @@ def test_related_resource_url(self): class TestProcessors(ManagerTestBase): """Tests for pre- and postprocessors.""" - def setup(self): - super(TestProcessors, self).setup() + def setUp(self): + super(TestProcessors, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -272,9 +273,9 @@ class TestFlaskSQLAlchemy(FlaskSQLAlchemyTestBase): """ - def setup(self): + def setUp(self): """Creates the Flask-SQLAlchemy database and models.""" - super(TestFlaskSQLAlchemy, self).setup() + super(TestFlaskSQLAlchemy, self).setUp() class Person(self.db.Model): id = self.db.Column(self.db.Integer, primary_key=True) diff --git a/tests/test_fetching.py b/tests/test_fetching.py index 6db73fa7..44c437db 100644 --- a/tests/test_fetching.py +++ b/tests/test_fetching.py @@ -19,6 +19,7 @@ """ from operator import itemgetter +from unittest import skip from sqlalchemy import Column from sqlalchemy import ForeignKey @@ -39,13 +40,12 @@ from .helpers import MSIE8_UA from .helpers import MSIE9_UA from .helpers import ManagerTestBase -from .helpers import skip class TestFetchCollection(ManagerTestBase): - def setup(self): - super(TestFetchCollection, self).setup() + def setUp(self): + super(TestFetchCollection, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -282,8 +282,8 @@ def test_sorting_null_field(self): class TestFetchResource(ManagerTestBase): - def setup(self): - super(TestFetchResource, self).setup() + def setUp(self): + super(TestFetchResource, self).setUp() # class Article(self.Base): # __tablename__ = 'article' @@ -402,8 +402,8 @@ def test_attributes_in_url(self): class TestFetchRelation(ManagerTestBase): - def setup(self): - super(TestFetchRelation, self).setup() + def setUp(self): + super(TestFetchRelation, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -513,8 +513,8 @@ def test_to_many_grouping(self): class TestFetchRelatedResource(ManagerTestBase): - def setup(self): - super(TestFetchRelatedResource, self).setup() + def setUp(self): + super(TestFetchRelatedResource, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -618,8 +618,8 @@ def test_nonexistent_relation(self): class TestFetchRelationship(ManagerTestBase): """Tests for fetching from a relationship URL.""" - def setup(self): - super(TestFetchRelationship, self).setup() + def setUp(self): + super(TestFetchRelationship, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -662,8 +662,8 @@ def test_relationship_url_nonexistent_relation(self): class TestServerSparseFieldsets(ManagerTestBase): """Tests for specifying default sparse fieldsets on the server.""" - def setup(self): - super(TestServerSparseFieldsets, self).setup() + def setUp(self): + super(TestServerSparseFieldsets, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -972,14 +972,14 @@ def test_exclude_relations(self): class TestProcessors(ManagerTestBase): """Tests for pre- and postprocessors.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestProcessors, self).setup() + super(TestProcessors, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -1438,14 +1438,14 @@ def modify_result(result=None, **kw): class TestDynamicRelationships(ManagerTestBase): """Tests for fetching resources from dynamic to-many relationships.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestDynamicRelationships, self).setup() + super(TestDynamicRelationships, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -1525,14 +1525,14 @@ class TestAssociationProxy(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask.ext.restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the models used in the test methods. """ - super(TestAssociationProxy, self).setup() + super(TestAssociationProxy, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -1610,9 +1610,9 @@ class TestFlaskSQLAlchemy(FlaskSQLAlchemyTestBase): """ - def setup(self): + def setUp(self): """Creates the Flask-SQLAlchemy database and models.""" - super(TestFlaskSQLAlchemy, self).setup() + super(TestFlaskSQLAlchemy, self).setUp() class Person(self.db.Model): id = self.db.Column(self.db.Integer, primary_key=True) diff --git a/tests/test_filtering.py b/tests/test_filtering.py index 928b5adc..b9cf4092 100644 --- a/tests/test_filtering.py +++ b/tests/test_filtering.py @@ -14,6 +14,7 @@ from datetime import datetime from datetime import time from operator import itemgetter +from unittest import skip # This import is unused but is required for testing on PyPy. CPython can # use psycopg2, but PyPy can only use psycopg2cffi. @@ -38,7 +39,6 @@ from .helpers import check_sole_error from .helpers import dumps from .helpers import loads -from .helpers import skip from .helpers import ManagerTestBase @@ -54,7 +54,7 @@ PostgreSQL = PGFactory(cache_initialized_db=True) -def teardown(): +def tearDown(): """Clears the cache in the :attr:`PostgreSQL` class.""" PostgreSQL.clear_cache() @@ -98,14 +98,14 @@ class TestFiltering(SearchTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask.ext.restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the models used in the test methods. """ - super(TestFiltering, self).setup() + super(TestFiltering, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -701,14 +701,14 @@ def test_to_many_relation(self): class TestOperators(SearchTestBase): - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask.ext.restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the models used in the test methods. """ - super(TestOperators, self).setup() + super(TestOperators, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -929,8 +929,8 @@ class TestNetworkOperators(SearchTestBase): """ - def setup(self): - super(TestNetworkOperators, self).setup() + def setUp(self): + super(TestNetworkOperators, self).setUp() class Network(self.Base): __tablename__ = 'network' @@ -941,15 +941,15 @@ class Network(self.Base): self.Base.metadata.create_all() self.manager.create_api(Network) - def teardown(self): + def tearDown(self): """Closes the database and removes the temporary directory in which it lives. """ - super(TestNetworkOperators, self).teardown() + super(TestNetworkOperators, self).tearDown() self.database.stop() - # We know this method will be called by `setup()` in the superclass, + # We know this method will be called by `setUp()` in the superclass, # so we can set up the temporary database here. def database_uri(self): """Creates a PostgreSQL database and returns its connection URI.""" @@ -957,7 +957,7 @@ def database_uri(self): #: #: This attribute stores a #: :class:`~testing.postgresql.Postgresql` object, which must be - #: stopped in the :meth:`.teardown` method. + #: stopped in the :meth:`.tearDown` method. self.database = PostgreSQL() return self.database.url() @@ -1096,14 +1096,14 @@ def test_contains_or_is_contained_by(self): class TestAssociationProxy(SearchTestBase): """Test for filtering on association proxies.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask.ext.restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the models used in the test methods. """ - super(TestAssociationProxy, self).setup() + super(TestAssociationProxy, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_functions.py b/tests/test_functions.py index 005fd9fd..7a5944a4 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -21,14 +21,14 @@ class TestFunctionEvaluation(ManagerTestBase): """Unit tests for the :class:`flask_restless.views.FunctionAPI` class.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`testapp.Person` and :class:`testapp.Computer` models. """ - super(TestFunctionEvaluation, self).setup() + super(TestFunctionEvaluation, self).setUp() class Person(self.Base): __tablename__ = 'person' diff --git a/tests/test_jsonapi/test_creating_resources.py b/tests/test_jsonapi/test_creating_resources.py index ef0e0cc7..a872d9d6 100644 --- a/tests/test_jsonapi/test_creating_resources.py +++ b/tests/test_jsonapi/test_creating_resources.py @@ -39,14 +39,14 @@ class TestCreatingResources(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestCreatingResources, self).setup() + super(TestCreatingResources, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_jsonapi/test_deleting_resources.py b/tests/test_jsonapi/test_deleting_resources.py index 936ae240..b7e712fc 100644 --- a/tests/test_jsonapi/test_deleting_resources.py +++ b/tests/test_jsonapi/test_deleting_resources.py @@ -31,7 +31,7 @@ class TestDeletingResources(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` @@ -39,7 +39,7 @@ def setup(self): """ # create the database - super(TestDeletingResources, self).setup() + super(TestDeletingResources, self).setUp() class Person(self.Base): __tablename__ = 'person' diff --git a/tests/test_jsonapi/test_document_structure.py b/tests/test_jsonapi/test_document_structure.py index 680d34ed..d8cab7fb 100644 --- a/tests/test_jsonapi/test_document_structure.py +++ b/tests/test_jsonapi/test_document_structure.py @@ -42,14 +42,14 @@ class TestDocumentStructure(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestDocumentStructure, self).setup() + super(TestDocumentStructure, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_jsonapi/test_fetching_data.py b/tests/test_jsonapi/test_fetching_data.py index fd7d30ff..8e6e9e1a 100644 --- a/tests/test_jsonapi/test_fetching_data.py +++ b/tests/test_jsonapi/test_fetching_data.py @@ -37,14 +37,14 @@ class TestFetchingData(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestFetchingData, self).setup() + super(TestFetchingData, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -387,8 +387,8 @@ class TestInclusion(ManagerTestBase): """ - def setup(self): - super(TestInclusion, self).setup() + def setUp(self): + super(TestInclusion, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -668,8 +668,8 @@ class TestSparseFieldsets(ManagerTestBase): """ - def setup(self): - super(TestSparseFieldsets, self).setup() + def setUp(self): + super(TestSparseFieldsets, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -795,8 +795,8 @@ class TestSorting(ManagerTestBase): """ - def setup(self): - super(TestSorting, self).setup() + def setUp(self): + super(TestSorting, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -976,8 +976,8 @@ class TestPagination(ManagerTestBase): """ - def setup(self): - super(TestPagination, self).setup() + def setUp(self): + super(TestPagination, self).setUp() class Person(self.Base): __tablename__ = 'person' diff --git a/tests/test_jsonapi/test_server_responsibilities.py b/tests/test_jsonapi/test_server_responsibilities.py index c0169da5..0d009f3e 100644 --- a/tests/test_jsonapi/test_server_responsibilities.py +++ b/tests/test_jsonapi/test_server_responsibilities.py @@ -18,6 +18,8 @@ .. _Server Responsibilities: http://jsonapi.org/format/#content-negotiation-servers """ +from unittest import skip + from sqlalchemy import Column from sqlalchemy import Unicode from sqlalchemy import Integer @@ -28,7 +30,6 @@ from ..helpers import dumps from ..helpers import loads from ..helpers import ManagerTestBase -from ..helpers import skip class TestServerResponsibilities(ManagerTestBase): @@ -39,8 +40,8 @@ class TestServerResponsibilities(ManagerTestBase): """ - def setup(self): - super(TestServerResponsibilities, self).setup() + def setUp(self): + super(TestServerResponsibilities, self).setUp() class Person(self.Base): __tablename__ = 'person' diff --git a/tests/test_jsonapi/test_updating_relationships.py b/tests/test_jsonapi/test_updating_relationships.py index aef72f8f..ca70a996 100644 --- a/tests/test_jsonapi/test_updating_relationships.py +++ b/tests/test_jsonapi/test_updating_relationships.py @@ -36,14 +36,14 @@ class TestUpdatingRelationships(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestUpdatingRelationships, self).setup() + super(TestUpdatingRelationships, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_jsonapi/test_updating_resources.py b/tests/test_jsonapi/test_updating_resources.py index d2258b5b..5843fe15 100644 --- a/tests/test_jsonapi/test_updating_resources.py +++ b/tests/test_jsonapi/test_updating_resources.py @@ -41,14 +41,14 @@ class TestUpdatingResources(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestUpdatingResources, self).setup() + super(TestUpdatingResources, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_manager.py b/tests/test_manager.py index d93d390e..dad1a54b 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -10,8 +10,9 @@ # License version 3 and under the 3-clause BSD license. For more # information, see LICENSE.AGPL and LICENSE.BSD. """Unit tests for the :mod:`flask_restless.manager` module.""" +from unittest import skip + from flask import Flask -from nose.tools import raises from sqlalchemy import Column from sqlalchemy import ForeignKey from sqlalchemy import Integer @@ -30,7 +31,6 @@ from .helpers import force_content_type_jsonapi from .helpers import loads from .helpers import ManagerTestBase -from .helpers import skip from .helpers import SQLAlchemyTestBase @@ -41,8 +41,8 @@ class TestLocalAPIManager(SQLAlchemyTestBase): """ - def setup(self): - super(TestLocalAPIManager, self).setup() + def setUp(self): + super(TestLocalAPIManager, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -56,13 +56,13 @@ class Article(self.Base): self.Article = Article self.Base.metadata.create_all() - @raises(ValueError) def test_missing_session(self): """Tests that setting neither a session nor a Flask-SQLAlchemy object yields an error. """ - APIManager(app=self.flaskapp) + with self.assertRaises(ValueError): + APIManager(app=self.flaskapp) def test_constructor_app(self): """Tests for providing a :class:`~flask.Flask` application in @@ -266,8 +266,8 @@ def test_override_url_prefix(self): class TestAPIManager(ManagerTestBase): """Unit tests for the :class:`flask_restless.manager.APIManager` class.""" - def setup(self): - super(TestAPIManager, self).setup() + def setUp(self): + super(TestAPIManager, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -292,13 +292,13 @@ class Tag(self.Base): # HACK If we don't include this, there seems to be an issue with the # globally known APIManager objects not being cleared after every test. - def teardown(self): + def tearDown(self): """Clear the :class:`flask.ext.restless.APIManager` objects known by the global functions :data:`model_for`, :data:`url_for`, and :data:`collection_name`. """ - super(TestAPIManager, self).teardown() + super(TestAPIManager, self).tearDown() model_for.created_managers.clear() url_for.created_managers.clear() collection_name.created_managers.clear() @@ -338,13 +338,13 @@ def test_url_for_explicitly_sets_primary_key_in_links(self): assert author_links['self'] == ( '/api/article/my_article/relationships/author') - @raises(ValueError) def test_url_for_nonexistent(self): """Tests that attempting to get the URL for an unknown model yields an error. """ - url_for(self.Person) + with self.assertRaises(ValueError): + url_for(self.Person) def test_collection_name(self): """Tests the global :func:`flask.ext.restless.collection_name` @@ -354,13 +354,13 @@ def test_collection_name(self): self.manager.create_api(self.Person, collection_name='people') assert collection_name(self.Person) == 'people' - @raises(ValueError) def test_collection_name_nonexistent(self): """Tests that attempting to get the collection name for an unknown model yields an error. """ - collection_name(self.Person) + with self.assertRaises(ValueError): + collection_name(self.Person) def test_serializer_for(self): """Tests the global :func:`flask.ext.restless.serializer_for` @@ -373,26 +373,26 @@ def my_function(*args, **kw): self.manager.create_api(self.Person, serializer=my_function) assert serializer_for(self.Person) == my_function - @raises(ValueError) def test_serializer_for_nonexistent(self): """Tests that attempting to get the serializer for an unknown model yields an error. """ - serializer_for(self.Person) + with self.assertRaises(ValueError): + serializer_for(self.Person) def test_model_for(self): """Tests the global :func:`flask.ext.restless.model_for` function.""" self.manager.create_api(self.Person, collection_name='people') assert model_for('people') is self.Person - @raises(ValueError) def test_model_for_nonexistent(self): """Tests that attempting to get the model for a nonexistent collection yields an error. """ - model_for('people') + with self.assertRaises(ValueError): + model_for('people') def test_model_for_collection_name(self): """Tests that :func:`flask.ext.restless.model_for` is the inverse of @@ -411,21 +411,21 @@ def test_disallowed_methods(self): response = func('/api/person') assert response.status_code == 405 - @raises(IllegalArgumentError) def test_missing_id(self): """Tests that calling :meth:`APIManager.create_api` on a model without an ``id`` column raises an exception. """ - self.manager.create_api(self.Tag) + with self.assertRaises(IllegalArgumentError): + self.manager.create_api(self.Tag) - @raises(IllegalArgumentError) def test_empty_collection_name(self): """Tests that calling :meth:`APIManager.create_api` with an empty collection name raises an exception. """ - self.manager.create_api(self.Person, collection_name='') + with self.assertRaises(IllegalArgumentError): + self.manager.create_api(self.Person, collection_name='') def test_disallow_functions(self): """Tests that if the ``allow_functions`` keyword argument is ``False``, @@ -437,30 +437,32 @@ def test_disallow_functions(self): assert response.status_code == 404 @skip('This test does not make sense anymore with JSON API') - @raises(IllegalArgumentError) def test_exclude_primary_key_column(self): """Tests that trying to create a writable API while excluding the primary key field raises an error. """ - self.manager.create_api(self.Person, exclude=['id'], methods=['POST']) + with self.assertRaises(IllegalArgumentError): + self.manager.create_api(self.Person, exclude=['id'], + methods=['POST']) - @raises(IllegalArgumentError) def test_only_and_exclude(self): """Tests that attempting to use both ``only`` and ``exclude`` keyword arguments yields an error. """ - self.manager.create_api(self.Person, only=['id'], exclude=['name']) + with self.assertRaises(IllegalArgumentError): + self.manager.create_api(self.Person, only=['id'], exclude=['name']) - @raises(AttributeError) def test_additional_attributes_nonexistent(self): """Tests that an attempt to include an additional attribute that does not exist on the model raises an exception at the time of API creation. """ - self.manager.create_api(self.Person, additional_attributes=['bogus']) + with self.assertRaises(AttributeError): + self.manager.create_api(self.Person, + additional_attributes=['bogus']) class TestFSA(FlaskSQLAlchemyTestBase): @@ -469,12 +471,12 @@ class TestFSA(FlaskSQLAlchemyTestBase): """ - def setup(self): + def setUp(self): """Creates the Flask application, the APIManager, the database, and the Flask-SQLAlchemy models. """ - super(TestFSA, self).setup() + super(TestFSA, self).setUp() class Person(self.db.Model): id = self.db.Column(self.db.Integer, primary_key=True) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 9e880deb..cb58e3d0 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -10,6 +10,8 @@ # License version 3 and under the 3-clause BSD license. For more # information, see LICENSE.AGPL and LICENSE.BSD. """Unit tests for metadata in server responses.""" +from unittest import skip + from sqlalchemy import Column from sqlalchemy import Integer @@ -17,19 +19,18 @@ from .helpers import loads from .helpers import ManagerTestBase -from .helpers import skip class TestMetadata(ManagerTestBase): """Tests for receiving metadata in responses.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person`. """ - super(TestMetadata, self).setup() + super(TestMetadata, self).setUp() class Person(self.Base): __tablename__ = 'person' diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 4eb83c3f..5a204d35 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -69,8 +69,8 @@ class DecoratedInterval(TypeDecorator): class TestFetchCollection(ManagerTestBase): """Tests for serializing when fetching from a collection endpoint.""" - def setup(self): - super(TestFetchCollection, self).setup() + def setUp(self): + super(TestFetchCollection, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -99,8 +99,8 @@ def test_exception_single(self): class TestFetchResource(ManagerTestBase): """Tests for serializing when fetching from a resource endpoint.""" - def setup(self): - super(TestFetchResource, self).setup() + def setUp(self): + super(TestFetchResource, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -431,8 +431,8 @@ def raise_with_msg(instance, *args, **kw): class TestFetchRelation(ManagerTestBase): - def setup(self): - super(TestFetchRelation, self).setup() + def setUp(self): + super(TestFetchRelation, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -511,8 +511,8 @@ def test_exception_on_included(self): class TestFetchRelatedResource(ManagerTestBase): """Tests for serializing when fetching from a related resource endpoint.""" - def setup(self): - super(TestFetchRelatedResource, self).setup() + def setUp(self): + super(TestFetchRelatedResource, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_updating.py b/tests/test_updating.py index 454e500e..613ea3c4 100644 --- a/tests/test_updating.py +++ b/tests/test_updating.py @@ -21,13 +21,14 @@ from __future__ import division from datetime import datetime +from unittest import skip + try: from flask.ext.sqlalchemy import SQLAlchemy except ImportError: has_flask_sqlalchemy = False else: has_flask_sqlalchemy = True - from sqlalchemy import Column from sqlalchemy import Date from sqlalchemy import DateTime @@ -52,20 +53,19 @@ from .helpers import MSIE8_UA from .helpers import MSIE9_UA from .helpers import ManagerTestBase -from .helpers import skip class TestUpdating(ManagerTestBase): """Tests for updating resources.""" - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask_restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the :class:`TestSupport.Person` and :class:`TestSupport.Article` models. """ - super(TestUpdating, self).setup() + super(TestUpdating, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -856,8 +856,8 @@ def test_relationship_missing_object(self): class TestProcessors(ManagerTestBase): """Tests for pre- and postprocessors.""" - def setup(self): - super(TestProcessors, self).setup() + def setUp(self): + super(TestProcessors, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -1000,14 +1000,14 @@ class TestAssociationProxy(ManagerTestBase): """ - def setup(self): + def setUp(self): """Creates the database, the :class:`~flask.Flask` object, the :class:`~flask.ext.restless.manager.APIManager` for that application, and creates the ReSTful API endpoints for the models used in the test methods. """ - super(TestAssociationProxy, self).setup() + super(TestAssociationProxy, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -1204,9 +1204,9 @@ class TestFlaskSQLAlchemy(FlaskSQLAlchemyTestBase): """ - def setup(self): + def setUp(self): """Creates the Flask-SQLAlchemy database and models.""" - super(TestFlaskSQLAlchemy, self).setup() + super(TestFlaskSQLAlchemy, self).setUp() # HACK During testing, we don't want the session to expire, so that we # can access attributes of model instances *after* a request has been # made (that is, after Flask-Restless does its work and commits the diff --git a/tests/test_updatingrelationship.py b/tests/test_updatingrelationship.py index ab480aba..0d319488 100644 --- a/tests/test_updatingrelationship.py +++ b/tests/test_updatingrelationship.py @@ -34,8 +34,8 @@ class TestAdding(ManagerTestBase): """ - def setup(self): - super(TestAdding, self).setup() + def setUp(self): + super(TestAdding, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -279,8 +279,8 @@ class TestDeleting(ManagerTestBase): """ - def setup(self): - super(TestDeleting, self).setup() + def setUp(self): + super(TestDeleting, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -528,8 +528,8 @@ class TestUpdatingToMany(ManagerTestBase): """ - def setup(self): - super(TestUpdatingToMany, self).setup() + def setUp(self): + super(TestUpdatingToMany, self).setUp() class Article(self.Base): __tablename__ = 'article' @@ -796,8 +796,8 @@ class TestUpdatingToOne(ManagerTestBase): """ - def setup(self): - super(TestUpdatingToOne, self).setup() + def setUp(self): + super(TestUpdatingToOne, self).setUp() class Article(self.Base): __tablename__ = 'article' diff --git a/tests/test_validation.py b/tests/test_validation.py index 0694d8e2..d699389f 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -18,6 +18,7 @@ client. """ +from unittest import skipUnless as skip_unless import sys from sqlalchemy import Column @@ -42,7 +43,6 @@ from .helpers import dumps from .helpers import loads from .helpers import ManagerTestBase -from .helpers import skip_unless class CoolValidationError(Exception): @@ -63,9 +63,9 @@ class TestSimpleValidation(ManagerTestBase): """ - def setup(self): + def setUp(self): """Create APIs for the validated models.""" - super(TestSimpleValidation, self).setup() + super(TestSimpleValidation, self).setUp() class Person(self.Base): __tablename__ = 'person' @@ -264,9 +264,9 @@ class TestSAValidation(ManagerTestBase): """ - def setup(self): + def setUp(self): """Create APIs for the validated models.""" - super(TestSAValidation, self).setup() + super(TestSAValidation, self).setUp() class Person(self.Base, _sav.ValidationMixin): __tablename__ = 'person'