def test_0005_group_views(self):
module = import_module('boardinghouse.migrations.0005_group_views')
# Performing this migration operation when preconditions for table move are not met
# should be idempotent, and should not throw an exception.
module.move_existing_to_schemata(apps, connection.schema_editor())
# Test for coverage purposes
module.noop(apps, connection.schema_editor())
# Test that we get the expected values from the helper method, including when the contrib.groups
# app has been installed.
self.assertEqual([User.groups.through, User.user_permissions.through], module.private_auth_models(apps))
with modify_settings(PRIVATE_MODELS={'append': ['auth.groups']}):
self.assertEqual([
User.groups.through, User.user_permissions.through, Group
], module.private_auth_models(apps))
self.assertEqual([User.groups.through, User.user_permissions.through], module.private_auth_models(apps))
# We need to test that we will move an existing table in public.X_X to <all-schemata>.X-X
# Lets get rid of the views that normally get created:
module.drop_views(apps, connection.schema_editor())
# And move the template tables into public.
with connection.cursor() as cursor:
for model in module.private_auth_models(apps):
db_table = model._meta.db_table
cursor.execute('ALTER TABLE __template__.{0} SET SCHEMA public'.format(db_table))
module.move_existing_to_schemata(apps, connection.schema_editor())
# Now re-create the views.
module.create_views(apps, connection.schema_editor())
# Now test that user-group relationships are not stored unless a schema is active.
user = User.objects.create_user(username='username', password='password')
group = Group.objects.create(name='Group')
user.groups.add(group)
self.assertEqual(0, user.groups.count())
Schema.objects.create(schema='a', name='a').activate()
user.groups.add(group)
self.assertEqual(1, user.groups.count())
评论列表
文章目录