# Path: boardinghouse/models.py
# class Schema(AbstractSchema):
#     """
#     The default schema model.
# 
#     Unless you set `settings.BOARDINGHOUSE_SCHEMA_MODEL`, this model will
#     be used for storing the schema objects.
#     """
#     users = models.ManyToManyField(
#         settings.AUTH_USER_MODEL,
#         blank=True, related_name='schemata',
#         help_text=_(u'Which users may access data from this schema.')
#     )
# 
#     class Meta:
#         app_label = 'boardinghouse'
#         verbose_name_plural = 'schemata'
#         swappable = 'BOARDINGHOUSE_SCHEMA_MODEL'
# 
# Path: boardinghouse/schema.py
# def get_active_schema_name():
#     """
#     Get the currently active schema.
# 
#     This requires a database query to ask it what the current `search_path` is.
#     """
#     active_schema = getattr(_thread_locals, 'schema', None)
# 
#     if not active_schema:
#         reported_schema = _get_search_path()[0]
# 
#         if _get_schema(reported_schema):
#             active_schema = reported_schema
#         else:
#             active_schema = None
# 
#         _thread_locals.schema = active_schema
# 
#     return active_schema


from django.test import TestCase
from boardinghouse.models import Schema
from boardinghouse.schema import get_active_schema_name



class TestSchemaQuerysetMethods(TestCase):
    def test_active(self):
        Schema.objects.mass_create('a', 'b', 'c')
        self.assertEqual(
            set(['a', 'b', 'c']),
            set(Schema.objects.active().values_list('schema', flat=True))
        )


# Path: boardinghouse/models.py
# class Schema(AbstractSchema):
#     """
#     The default schema model.
# 
#     Unless you set `settings.BOARDINGHOUSE_SCHEMA_MODEL`, this model will
#     be used for storing the schema objects.
#     """
#     users = models.ManyToManyField(
#         settings.AUTH_USER_MODEL,
#         blank=True, related_name='schemata',
#         help_text=_(u'Which users may access data from this schema.')
#     )
# 
#     class Meta:
#         app_label = 'boardinghouse'
#         verbose_name_plural = 'schemata'
#         swappable = 'BOARDINGHOUSE_SCHEMA_MODEL'
# 
# Path: boardinghouse/schema.py
# def get_active_schema_name():
#     """
#     Get the currently active schema.
# 
#     This requires a database query to ask it what the current `search_path` is.
#     """
#     active_schema = getattr(_thread_locals, 'schema', None)
# 
#     if not active_schema:
#         reported_schema = _get_search_path()[0]
# 
#         if _get_schema(reported_schema):
#             active_schema = reported_schema
#         else:
#             active_schema = None
# 
#         _thread_locals.schema = active_schema
# 
#     return active_schema


# Path: tests/tests/test_schema_model.py
from django.test import TestCase
from boardinghouse.models import Schema
from boardinghouse.schema import get_active_schema_name




class TestSchemaQuerysetMethods(TestCase):
    def test_active(self):
        Schema.objects.mass_create('a', 'b', 'c')
        self.assertEqual(
            set(['a', 'b', 'c']),
            set(Schema.objects.active().values_list('schema', flat=True))
        )


        Schema.objects.filter(schema='a').update(is_active=False)