# Path: boardinghouse/schema.py
# LOGGER = logging.getLogger(__name__)
# REQUIRED_SHARED_MODELS = [
#     'auth.user',
#     'auth.permission',
#     'auth.group',
#     'boardinghouse.schema',
#     'sites.site',
#     'sessions.session',
#     'contenttypes.contenttype',
#     'admin.logentry',
#     'migrations.migration',
#     # In the case these are not the default values.
#     lazy(lambda: settings.BOARDINGHOUSE_SCHEMA_MODEL.lower())(),
#     lazy(lambda: settings.AUTH_USER_MODEL.lower())(),
# ]
# REQUIRED_SHARED_TABLES = [
#     'django_migrations',
# ]
# def get_schema_model():
# def _get_search_path():
# def _set_search_path(search_path):
# def _schema_exists(schema_name, cursor=None):
# def get_active_schema_name():
# def get_active_schema():
# def get_active_schemata():
# def _get_schema(schema_name):
# def activate_schema(schema_name):
# def activate_template_schema():
# def get_template_schema():
# def deactivate_schema(schema=None):
# def _is_join_model(model):
# def is_shared_model(model):
# def _get_models(apps, stack):
# def _get_join_model(table, table_map):
# def is_shared_table(table, apps=apps):
# def _table_exists(table_name, schema=None):
# def _schema_table_exists():


from django.test import TestCase
from django.db import connection
from django import forms
from django.utils import six
from boardinghouse.schema import (
    activate_schema, deactivate_schema,
    TemplateSchemaActivation,
    is_shared_model,
    get_active_schema_name,
    get_schema_model,
    activate_template_schema,
    _get_search_path,
)
    def test_manual_set_search_path(self):
        Schema.objects.create(name='a', schema='a')
        connection.cursor().execute('SET search_path TO a,public')
        self.assertEqual('a', get_active_schema_name())

    def test_activate_schema_sets_search_path(self):
        schema = Schema.objects.create(name='a', schema='a')
        schema.activate()
        self.assertEqual(schema.schema, get_active_schema_name())

        activate_template_schema()
        self.assertEqual('__template__', _get_search_path())

    def test_deactivate_schema_resets_search_path(self):
        schema = Schema.objects.create(name='a', schema='a')
        schema.activate()
        schema.deactivate()
        self.assertEqual(None, get_active_schema_name())

    def test_get_schema_or_template_helper(self):
        schema = Schema.objects.create(name='a', schema='a')
        self.assertEqual(None, get_active_schema_name())

        schema.activate()
        self.assertEqual('a', get_active_schema_name())

        schema.deactivate()
        self.assertEqual(None, get_active_schema_name())

    def test_activate_schema_function(self):

# Path: boardinghouse/schema.py
# LOGGER = logging.getLogger(__name__)
# REQUIRED_SHARED_MODELS = [
#     'auth.user',
#     'auth.permission',
#     'auth.group',
#     'boardinghouse.schema',
#     'sites.site',
#     'sessions.session',
#     'contenttypes.contenttype',
#     'admin.logentry',
#     'migrations.migration',
#     # In the case these are not the default values.
#     lazy(lambda: settings.BOARDINGHOUSE_SCHEMA_MODEL.lower())(),
#     lazy(lambda: settings.AUTH_USER_MODEL.lower())(),
# ]
# REQUIRED_SHARED_TABLES = [
#     'django_migrations',
# ]
# def get_schema_model():
# def _get_search_path():
# def _set_search_path(search_path):
# def _schema_exists(schema_name, cursor=None):
# def get_active_schema_name():
# def get_active_schema():
# def get_active_schemata():
# def _get_schema(schema_name):
# def activate_schema(schema_name):
# def activate_template_schema():
# def get_template_schema():
# def deactivate_schema(schema=None):
# def _is_join_model(model):
# def is_shared_model(model):
# def _get_models(apps, stack):
# def _get_join_model(table, table_map):
# def is_shared_table(table, apps=apps):
# def _table_exists(table_name, schema=None):
# def _schema_table_exists():


# Path: tests/tests/test_schema_creation.py
from django.test import TestCase
from django.db import connection
from django import forms
from django.utils import six
from boardinghouse.schema import (
    activate_schema, deactivate_schema,
    TemplateSchemaActivation,
    is_shared_model,
    get_active_schema_name,
    get_schema_model,
    activate_template_schema,
    _get_search_path,
)

    def test_manual_set_search_path(self):
        Schema.objects.create(name='a', schema='a')
        connection.cursor().execute('SET search_path TO a,public')
        self.assertEqual('a', get_active_schema_name())

    def test_activate_schema_sets_search_path(self):
        schema = Schema.objects.create(name='a', schema='a')
        schema.activate()
        self.assertEqual(schema.schema, get_active_schema_name())

        activate_template_schema()
        self.assertEqual('__template__', _get_search_path())

    def test_deactivate_schema_resets_search_path(self):
        schema = Schema.objects.create(name='a', schema='a')
        schema.activate()
        schema.deactivate()
        self.assertEqual(None, get_active_schema_name())

    def test_get_schema_or_template_helper(self):
        schema = Schema.objects.create(name='a', schema='a')
        self.assertEqual(None, get_active_schema_name())

        schema.activate()
        self.assertEqual('a', get_active_schema_name())

        schema.deactivate()
        self.assertEqual(None, get_active_schema_name())

    def test_activate_schema_function(self):

        self.assertRaises(TemplateSchemaActivation, activate_schema, '__template__')