# 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/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


from sqlalchemy.ext.declarative import declarative_base
from unittest import mock
from falconswagger.models.orm.session import Session
from falconswagger.models.orm.sqlalchemy_redis import ModelSQLAlchemyRedisFactory
import msgpack
import pytest
import sqlalchemy as sa


class TestSessionCommitRedisDeleteWithoutUseRedisFlag(object):
    def test_if_instance_is_deleted_from_redis(self, session, model1_no_redis, redis):
        inst1 = model1_no_redis(session, id=1)
        session.add(inst1)
        session.commit()

        session.delete(inst1)
        session.commit()

        assert redis.hdel.call_args_list == []


@pytest.fixture
def model1_related(request, model_base, redis, session):
    class model_(model_base):
        __tablename__ = 'test1'
        __table_args__ = {'mysql_engine':'innodb'}
        id = sa.Column(sa.Integer, primary_key=True)
        test = sa.Column(sa.String(255))

    model_base.metadata.create_all()
    return model_


@pytest.fixture
def model2_related(request, model_base, redis, session, model1_related):
    mtm_table = sa.Table(
        'model1_model2', model_base.metadata,

# 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/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


# Path: tests/integration/base/test_session_integration.py
from sqlalchemy.ext.declarative import declarative_base
from unittest import mock
from falconswagger.models.orm.session import Session
from falconswagger.models.orm.sqlalchemy_redis import ModelSQLAlchemyRedisFactory
import msgpack
import pytest
import sqlalchemy as sa



class TestSessionCommitRedisDeleteWithoutUseRedisFlag(object):
    def test_if_instance_is_deleted_from_redis(self, session, model1_no_redis, redis):
        inst1 = model1_no_redis(session, id=1)
        session.add(inst1)
        session.commit()

        session.delete(inst1)
        session.commit()

        assert redis.hdel.call_args_list == []


@pytest.fixture
def model1_related(request, model_base, redis, session):
    class model_(model_base):
        __tablename__ = 'test1'
        __table_args__ = {'mysql_engine':'innodb'}
        id = sa.Column(sa.Integer, primary_key=True)
        test = sa.Column(sa.String(255))

    model_base.metadata.create_all()
    return model_


@pytest.fixture
def model2_related(request, model_base, redis, session, model1_related):
    mtm_table = sa.Table(
        'model1_model2', model_base.metadata,

        sa.Column('model1_id', sa.Integer, sa.ForeignKey('test1.id', ondelete='CASCADE')),