# 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):


from falconswagger.models.orm.session import Session
from unittest import mock
from sqlalchemy import create_engine
import pytest
import pymysql
def redis():
    return mock.MagicMock()


@pytest.fixture
def session(model_base, request, variables, redis):
    conn = pymysql.connect(
        user=variables['database']['user'], password=variables['database']['password'])

    with conn.cursor() as cursor:
        try:
            cursor.execute('drop database {};'.format(variables['database']['database']))
        except:
            pass

        cursor.execute('create database {};'.format(variables['database']['database']))
    conn.commit()
    conn.close()

    if variables['database']['password']:
        url = 'mysql+pymysql://{user}:{password}'\
            '@{host}:{port}/{database}'.format(**variables['database'])
    else:
        variables['database'].pop('password')
        url = 'mysql+pymysql://{user}'\
            '@{host}:{port}/{database}'.format(**variables['database'])
        variables['database']['password'] = None

    engine = create_engine(url)
    model_base.metadata.bind = engine

# 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: tests/integration/conftest.py
from falconswagger.models.orm.session import Session
from unittest import mock
from sqlalchemy import create_engine
import pytest
import pymysql

def redis():
    return mock.MagicMock()


@pytest.fixture
def session(model_base, request, variables, redis):
    conn = pymysql.connect(
        user=variables['database']['user'], password=variables['database']['password'])

    with conn.cursor() as cursor:
        try:
            cursor.execute('drop database {};'.format(variables['database']['database']))
        except:
            pass

        cursor.execute('create database {};'.format(variables['database']['database']))
    conn.commit()
    conn.close()

    if variables['database']['password']:
        url = 'mysql+pymysql://{user}:{password}'\
            '@{host}:{port}/{database}'.format(**variables['database'])
    else:
        variables['database'].pop('password')
        url = 'mysql+pymysql://{user}'\
            '@{host}:{port}/{database}'.format(**variables['database'])
        variables['database']['password'] = None

    engine = create_engine(url)
    model_base.metadata.bind = engine

    model_base.metadata.create_all()