# Path: falconswagger/models/orm/sqlalchemy_redis.py
# class ModelSQLAlchemyRedisFactory(object):
# 
#     @staticmethod
#     def make(name='ModelSQLAlchemyRedisBase', bind=None, metadata=None,
#              mapper=None, class_registry=None, authorizer=None, keys_separator=b'|'):
#         base = declarative_base(
#             name=name, metaclass=ModelSQLAlchemyRedisMeta,
#             cls=_ModelSQLAlchemyRedisBase, bind=bind, metadata=metadata,
#             mapper=mapper, constructor=_ModelSQLAlchemyRedisBase.__init__)
#         base.__authorizer__ = authorizer
#         base.__keys_separator__ = \
#             keys_separator.decode() if isinstance(keys_separator, str) else keys_separator
#         return base
# 
# class ModelSQLAlchemyRedisMeta(
#         ModelSQLAlchemyRedisInitMetaMixin,
#         ModelSQLAlchemyRedisOperationsMetaMixin):
#     pass
# 
# Path: falconswagger/models/orm/session.py
# class _SessionBase(SessionSA):
#     def __init__(
#             self, bind=None, autoflush=True,
#             expire_on_commit=True, _enable_transaction_accounting=True,
#             autocommit=False, twophase=False, weak_identity_map=True,
#             binds=None, extension=None, info=None, query_cls=Query, redis_bind=None):
#     def _clean_redis_sets(self):
#     def commit(self):
#     def delete(self, instance):
#     def _update_objects_on_redis(self):
#     def _exec_hdel(self, insts):
#     def _get_filters_names_set(self, inst):
#     def _exec_hmset(self, insts):
#     def mark_for_hdel(self, inst):
#     def mark_for_hmset(self, inst):
# def deleted_from_database(session, instance):
# def added_to_database(session, instance):
# 
# Path: falconswagger/exceptions.py
# class ModelBaseError(FalconSwaggerError):
#     def __init__(self, message, input_=None):
#         FalconSwaggerError.__init__(self, message, HTTP_BAD_REQUEST)
#         self.input_ = input_


from falconswagger.models.orm.sqlalchemy_redis import ModelSQLAlchemyRedisFactory, ModelSQLAlchemyRedisMeta
from falconswagger.models.orm.session import Session
from falconswagger.exceptions import ModelBaseError
from unittest import mock
import pytest
import sqlalchemy as sa
        }

    def test_todict_with_nested_relationship_with_schema(self, model1, model2, model3):
        m2 = {'id': 1, 'model1': {'id': 1, '_operation': 'insert'}, '_operation': 'insert'}
        m3 = model3(mock.MagicMock(), id=1, model2=m2)
        schema = {
            'model2': {
                'model1': {
                    'id': False
                }
            }
        }
        assert m3.todict(schema) == {
            'id': 1,
            'model1_id': None,
            'model2_id': None,
            'model1': None,
            'model2': {
                'id': 1,
                'model1_id': None,
                'model1': {}
            }
        }


class TestModelBaseNestedOperations(object):

    def test_raises_model_error_with_invalid_nested_id(self, model1, model2_mtm):
        session = mock.MagicMock()
        session.query().filter().all().__getitem__.return_value = model1(mock.MagicMock(), id=1)

# Path: falconswagger/models/orm/sqlalchemy_redis.py
# class ModelSQLAlchemyRedisFactory(object):
# 
#     @staticmethod
#     def make(name='ModelSQLAlchemyRedisBase', bind=None, metadata=None,
#              mapper=None, class_registry=None, authorizer=None, keys_separator=b'|'):
#         base = declarative_base(
#             name=name, metaclass=ModelSQLAlchemyRedisMeta,
#             cls=_ModelSQLAlchemyRedisBase, bind=bind, metadata=metadata,
#             mapper=mapper, constructor=_ModelSQLAlchemyRedisBase.__init__)
#         base.__authorizer__ = authorizer
#         base.__keys_separator__ = \
#             keys_separator.decode() if isinstance(keys_separator, str) else keys_separator
#         return base
# 
# class ModelSQLAlchemyRedisMeta(
#         ModelSQLAlchemyRedisInitMetaMixin,
#         ModelSQLAlchemyRedisOperationsMetaMixin):
#     pass
# 
# Path: falconswagger/models/orm/session.py
# class _SessionBase(SessionSA):
#     def __init__(
#             self, bind=None, autoflush=True,
#             expire_on_commit=True, _enable_transaction_accounting=True,
#             autocommit=False, twophase=False, weak_identity_map=True,
#             binds=None, extension=None, info=None, query_cls=Query, redis_bind=None):
#     def _clean_redis_sets(self):
#     def commit(self):
#     def delete(self, instance):
#     def _update_objects_on_redis(self):
#     def _exec_hdel(self, insts):
#     def _get_filters_names_set(self, inst):
#     def _exec_hmset(self, insts):
#     def mark_for_hdel(self, inst):
#     def mark_for_hmset(self, inst):
# def deleted_from_database(session, instance):
# def added_to_database(session, instance):
# 
# Path: falconswagger/exceptions.py
# class ModelBaseError(FalconSwaggerError):
#     def __init__(self, message, input_=None):
#         FalconSwaggerError.__init__(self, message, HTTP_BAD_REQUEST)
#         self.input_ = input_


# Path: tests/unit/base/models/test_sqlalchemy_redis.py
from falconswagger.models.orm.sqlalchemy_redis import ModelSQLAlchemyRedisFactory, ModelSQLAlchemyRedisMeta
from falconswagger.models.orm.session import Session
from falconswagger.exceptions import ModelBaseError
from unittest import mock
import pytest
import sqlalchemy as sa

        }

    def test_todict_with_nested_relationship_with_schema(self, model1, model2, model3):
        m2 = {'id': 1, 'model1': {'id': 1, '_operation': 'insert'}, '_operation': 'insert'}
        m3 = model3(mock.MagicMock(), id=1, model2=m2)
        schema = {
            'model2': {
                'model1': {
                    'id': False
                }
            }
        }
        assert m3.todict(schema) == {
            'id': 1,
            'model1_id': None,
            'model2_id': None,
            'model1': None,
            'model2': {
                'id': 1,
                'model1_id': None,
                'model1': {}
            }
        }


class TestModelBaseNestedOperations(object):

    def test_raises_model_error_with_invalid_nested_id(self, model1, model2_mtm):
        session = mock.MagicMock()
        session.query().filter().all().__getitem__.return_value = model1(mock.MagicMock(), id=1)

        with pytest.raises(ModelBaseError) as exc_info: