# 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_schemata():
#     """
#     Get a (cached) list of all currently active schemata.
#     """
#     schemata = cache.get('active-schemata')
#     if schemata is None:
#         schemata = get_schema_model().objects.active()
#         cache.set('active-schemata', schemata)
#     return schemata


from django.test import TestCase
from django.contrib.auth.models import User
from django.core.cache import cache
from boardinghouse.models import Schema
from boardinghouse.schema import get_active_schemata
        user = User.objects.get(username='a')
        user.schemata.add(*Schema.objects.all())

        self.assertEqual(3, len(user.visible_schemata))

        user.schemata.remove(Schema.objects.get(schema='a'))
        self.assertEqual(None, cache.get('visible-schemata-{0!s}'.format(user.pk)))

    def test_adding_users_to_schema_clears_cache(self):
        User.objects.create_user(username='a', email='a@example.com', password='a')
        Schema.objects.mass_create('a', 'b', 'c')

        user = User.objects.get(username='a')

        self.assertEqual(0, len(user.visible_schemata))
        self.assertEqual([], list(cache.get('visible-schemata-{0!s}'.format(user.pk))))

        schema = Schema.objects.get(schema='a')
        schema.users.add(user)

        self.assertEqual(None, cache.get('visible-schemata-{0!s}'.format(user.pk)))

    def test_removing_users_from_schema_clears_cache(self):
        User.objects.create_user(username='a', email='a@example.com', password='a')
        Schema.objects.mass_create('a', 'b', 'c')

        user = User.objects.get(username='a')
        user.schemata.add(*Schema.objects.all())
        self.assertEqual(3, len(user.visible_schemata))


# 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_schemata():
#     """
#     Get a (cached) list of all currently active schemata.
#     """
#     schemata = cache.get('active-schemata')
#     if schemata is None:
#         schemata = get_schema_model().objects.active()
#         cache.set('active-schemata', schemata)
#     return schemata


# Path: tests/tests/test_user_schemata.py
from django.test import TestCase
from django.contrib.auth.models import User
from django.core.cache import cache
from boardinghouse.models import Schema
from boardinghouse.schema import get_active_schemata

        user = User.objects.get(username='a')
        user.schemata.add(*Schema.objects.all())

        self.assertEqual(3, len(user.visible_schemata))

        user.schemata.remove(Schema.objects.get(schema='a'))
        self.assertEqual(None, cache.get('visible-schemata-{0!s}'.format(user.pk)))

    def test_adding_users_to_schema_clears_cache(self):
        User.objects.create_user(username='a', email='a@example.com', password='a')
        Schema.objects.mass_create('a', 'b', 'c')

        user = User.objects.get(username='a')

        self.assertEqual(0, len(user.visible_schemata))
        self.assertEqual([], list(cache.get('visible-schemata-{0!s}'.format(user.pk))))

        schema = Schema.objects.get(schema='a')
        schema.users.add(user)

        self.assertEqual(None, cache.get('visible-schemata-{0!s}'.format(user.pk)))

    def test_removing_users_from_schema_clears_cache(self):
        User.objects.create_user(username='a', email='a@example.com', password='a')
        Schema.objects.mass_create('a', 'b', 'c')

        user = User.objects.get(username='a')
        user.schemata.add(*Schema.objects.all())
        self.assertEqual(3, len(user.visible_schemata))


        schema = Schema.objects.get(schema='a')