I'm trying to test an app that creates some custom permissions during intialization. These are created right after database creation:
custom_permissions = getattr(settings,'SOMEAPP_PERMISSIONS',() )
def create_custom_permissions(sender, **kwargs):
ct, created = ContentType.objects.get_or_create(model = '',
app_label = 'some_app',
defaults = {'name':'some_app'})
for codename, name in custom_permissions:
perm = Permission.objects.get_or_create(codename = codename,
content_type__pk = ct.id,
name = name)
post_save.connect(create_custom_permissions, Permission)
All the discussions i can find for overriding settings are somewhat related to override_settings
,with self.settings
and so on. But when i override the settings during a TestCase, my function has already been run, and the change of the settings has, of course, no effect:
@override_settings(SOMEAPP_PERMISSIONS = (('some_custom_permission','No Name'))
class TestCustomPermissions(TestCase):
fixtures = ['some_app_user_fixture.json']
urls = 'some_app.tests.test_urls'
def test_create_point_privileges(self):
""" check if all necessary privileges have been created """
Permission.objects.get(codename = 'some_custom_permission')
And therefore all my tests fail. Now how can i use a settings file just for testing this special function and it's tie to the creation of the Database?