# Path: tests/helpers.py
# MSIE8_UA = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)'
# MSIE9_UA = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
# IS_PYTHON2 = (sys.version_info[0] == 2)
# CLASS_TYPES = (types.TypeType, types.ClassType) if IS_PYTHON2 else (type, )
# GLOBAL_FUNCS = [model_for, url_for, collection_name, serializer_for,
#                 primary_key_for]
# class raise_s_exception(DefaultSerializer):
# class raise_d_exception(DefaultDeserializer):
# class GUID(TypeDecorator):
# class BetterJSONEncoder(json.JSONEncoder):
# class FlaskTestBase(TestCase):
# class DatabaseMixin(object):
# class FlaskSQLAlchemyTestBase(FlaskTestBase, DatabaseMixin):
# class SQLAlchemyTestBase(FlaskTestBase, DatabaseMixin):
# class ManagerTestBase(SQLAlchemyTestBase):
#     def serialize(self, instance, *args, **kw):
#     def serialize_many(self, instances, *args, **kw):
#     def deserialize(self, *args, **kw):
#     def deserialize_many(self, *args, **kw):
# def isclass(obj):
# def parse_version(version_string):
# def unregister_fsa_session_signals():
# def check_sole_error(response, status, strings):
# def force_content_type_jsonapi(test_client):
#     def set_content_type(func):
#         def new_func(*args, **kw):
#     def load_dialect_impl(self, dialect):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def default(self, obj):
#     def setUp(self):
#     def database_uri(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
# 
# Path: tests/helpers.py
# class ManagerTestBase(SQLAlchemyTestBase):
#     """Base class for tests that use a SQLAlchemy database and an
#     :class:`~flask_restless.APIManager`.
# 
#     Nearly all test classes should subclass this class. Since we strive
#     to make Flask-Restless compliant with plain old SQLAlchemy first,
#     the default database abstraction layer used by tests in this class
#     will be SQLAlchemy. Test classes requiring Flask-SQLAlchemy must
#     instantiate their own :class:`~flask_restless.APIManager`.
# 
#     The :class:`~flask_restless.APIManager` instance for use in
#     tests is accessible at ``self.manager``.
# 
#     """
# 
#     def setUp(self):
#         """Initializes an instance of
#         :class:`~flask_restless.APIManager` with a SQLAlchemy
#         session.
# 
#         """
#         super(ManagerTestBase, self).setUp()
#         self.manager = APIManager(self.flaskapp, session=self.session)
# 
#     # 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):
#         """Clear the :class:`~flask_restless.APIManager` objects
#         known by the global helper functions :data:`model_for`,
#         :data:`url_for`, etc.
# 
#         """
#         super(ManagerTestBase, self).tearDown()
#         for func in GLOBAL_FUNCS:
#             func.created_managers.clear()


from operator import attrgetter
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy.orm import relationship
from ..helpers import dumps
from ..helpers import ManagerTestBase
        person = self.Person(id=1)
        article = self.Article(id=1)
        self.session.add_all([person, article])
        self.session.commit()
        self.manager.create_api(self.Person, methods=['PATCH'],
                                url_prefix='/api2',
                                allow_to_many_replacement=True)
        data = {'data': [{'type': 'article', 'id': '1'},
                         {'type': 'article', 'id': '2'}]}
        response = self.app.patch('/api2/person/1/relationships/articles',
                                  data=dumps(data))
        assert response.status_code == 404
        # TODO test error messages

    def test_to_many_forbidden(self):
        """Tests that full replacement of a to-many relationship is forbidden
        by the server configuration, then the response is :http:status:`403`.

        For more information, see the `Updating To-Many Relationships`_ section
        of the JSON API specification.

        .. _Updating To-Many Relationships:
           http://jsonapi.org/format/#crud-updating-to-many-relationships

        """
        person = self.Person(id=1)
        self.session.add(person)
        self.session.commit()
        data = {'data': []}
        response = self.app.patch('/api/person/1/relationships/articles',

# Path: tests/helpers.py
# MSIE8_UA = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)'
# MSIE9_UA = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
# IS_PYTHON2 = (sys.version_info[0] == 2)
# CLASS_TYPES = (types.TypeType, types.ClassType) if IS_PYTHON2 else (type, )
# GLOBAL_FUNCS = [model_for, url_for, collection_name, serializer_for,
#                 primary_key_for]
# class raise_s_exception(DefaultSerializer):
# class raise_d_exception(DefaultDeserializer):
# class GUID(TypeDecorator):
# class BetterJSONEncoder(json.JSONEncoder):
# class FlaskTestBase(TestCase):
# class DatabaseMixin(object):
# class FlaskSQLAlchemyTestBase(FlaskTestBase, DatabaseMixin):
# class SQLAlchemyTestBase(FlaskTestBase, DatabaseMixin):
# class ManagerTestBase(SQLAlchemyTestBase):
#     def serialize(self, instance, *args, **kw):
#     def serialize_many(self, instances, *args, **kw):
#     def deserialize(self, *args, **kw):
#     def deserialize_many(self, *args, **kw):
# def isclass(obj):
# def parse_version(version_string):
# def unregister_fsa_session_signals():
# def check_sole_error(response, status, strings):
# def force_content_type_jsonapi(test_client):
#     def set_content_type(func):
#         def new_func(*args, **kw):
#     def load_dialect_impl(self, dialect):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def default(self, obj):
#     def setUp(self):
#     def database_uri(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
#     def setUp(self):
#     def tearDown(self):
# 
# Path: tests/helpers.py
# class ManagerTestBase(SQLAlchemyTestBase):
#     """Base class for tests that use a SQLAlchemy database and an
#     :class:`~flask_restless.APIManager`.
# 
#     Nearly all test classes should subclass this class. Since we strive
#     to make Flask-Restless compliant with plain old SQLAlchemy first,
#     the default database abstraction layer used by tests in this class
#     will be SQLAlchemy. Test classes requiring Flask-SQLAlchemy must
#     instantiate their own :class:`~flask_restless.APIManager`.
# 
#     The :class:`~flask_restless.APIManager` instance for use in
#     tests is accessible at ``self.manager``.
# 
#     """
# 
#     def setUp(self):
#         """Initializes an instance of
#         :class:`~flask_restless.APIManager` with a SQLAlchemy
#         session.
# 
#         """
#         super(ManagerTestBase, self).setUp()
#         self.manager = APIManager(self.flaskapp, session=self.session)
# 
#     # 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):
#         """Clear the :class:`~flask_restless.APIManager` objects
#         known by the global helper functions :data:`model_for`,
#         :data:`url_for`, etc.
# 
#         """
#         super(ManagerTestBase, self).tearDown()
#         for func in GLOBAL_FUNCS:
#             func.created_managers.clear()


# Path: tests/test_jsonapi/test_updating_relationships.py
from operator import attrgetter
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy.orm import relationship
from ..helpers import dumps
from ..helpers import ManagerTestBase

        person = self.Person(id=1)
        article = self.Article(id=1)
        self.session.add_all([person, article])
        self.session.commit()
        self.manager.create_api(self.Person, methods=['PATCH'],
                                url_prefix='/api2',
                                allow_to_many_replacement=True)
        data = {'data': [{'type': 'article', 'id': '1'},
                         {'type': 'article', 'id': '2'}]}
        response = self.app.patch('/api2/person/1/relationships/articles',
                                  data=dumps(data))
        assert response.status_code == 404
        # TODO test error messages

    def test_to_many_forbidden(self):
        """Tests that full replacement of a to-many relationship is forbidden
        by the server configuration, then the response is :http:status:`403`.

        For more information, see the `Updating To-Many Relationships`_ section
        of the JSON API specification.

        .. _Updating To-Many Relationships:
           http://jsonapi.org/format/#crud-updating-to-many-relationships

        """
        person = self.Person(id=1)
        self.session.add(person)
        self.session.commit()
        data = {'data': []}
        response = self.app.patch('/api/person/1/relationships/articles',

                                  data=dumps(data))