|
31 | 31 | 'USER': 'postgres', |
32 | 32 | } |
33 | 33 |
|
34 | | -settings.configure(**{ |
35 | | - 'DEBUG': True, |
36 | | - 'SECRET_KEY': 'testy mctestface', |
37 | | - 'ALLOWED_HOSTS': ['*'], |
38 | | - 'DATABASES': { |
39 | | - 'default': db_settings, |
40 | | - }, |
41 | | - 'MIDDLEWARE': [ |
42 | | - # TODO: Try to reduce the set of absolutely required middlewares |
43 | | - 'request_id.middleware.RequestIdMiddleware', |
44 | | - 'django.contrib.sessions.middleware.SessionMiddleware', |
45 | | - 'django.middleware.csrf.CsrfViewMiddleware', |
46 | | - 'django.contrib.auth.middleware.AuthenticationMiddleware', |
47 | | - 'binder.plugins.token_auth.middleware.TokenAuthMiddleware', |
48 | | - ], |
49 | | - 'INSTALLED_APPS': [ |
50 | | - # TODO: Try to reduce the set of absolutely required applications |
51 | | - 'django.contrib.auth', |
52 | | - 'django.contrib.contenttypes', |
53 | | - 'django.contrib.sessions', |
54 | | - 'binder', |
55 | | - 'binder.plugins.token_auth', |
56 | | - 'tests', |
57 | | - 'tests.testapp', |
58 | | - ], |
59 | | - 'MIGRATION_MODULES': { |
60 | | - 'testapp': None, |
61 | | - 'auth': None, |
62 | | - 'sessions': None, |
63 | | - 'contenttypes': None, |
64 | | - 'binder': None, |
65 | | - 'token_auth': None, |
66 | | - }, |
67 | | - 'USE_TZ': True, |
68 | | - 'TIME_ZONE': 'UTC', |
69 | | - 'ROOT_URLCONF': 'tests.testapp.urls', |
70 | | - 'LOGGING': { |
71 | | - 'version': 1, |
72 | | - 'handlers': { |
73 | | - 'console': { |
74 | | - 'level': 'DEBUG', |
75 | | - 'class': 'logging.StreamHandler', |
76 | | - }, |
| 34 | +if not settings.configured: |
| 35 | + settings.configure(**{ |
| 36 | + 'DEBUG': True, |
| 37 | + 'SECRET_KEY': 'testy mctestface', |
| 38 | + 'ALLOWED_HOSTS': ['*'], |
| 39 | + 'DATABASES': { |
| 40 | + 'default': db_settings, |
77 | 41 | }, |
78 | | - 'loggers': { |
79 | | - # We override only this one to avoid logspam |
80 | | - # while running tests. Django warnings are |
81 | | - # stil shown. |
82 | | - 'binder': { |
83 | | - 'handlers': ['console'], |
84 | | - 'level': 'ERROR', |
85 | | - }, |
86 | | - } |
87 | | - }, |
88 | | - 'BINDER_PERMISSION': { |
89 | | - 'default': [ |
90 | | - ('auth.reset_password_user', None), |
91 | | - ('auth.view_user', 'own'), |
92 | | - ('auth.activate_user', None), |
93 | | - ('auth.unmasquerade_user', None), # If you are masquarade, the user must be able to unmasquarade |
94 | | - ('auth.login_user', None), |
95 | | - ('auth.signup_user', None), |
96 | | - ('auth.logout_user', None), |
97 | | - ('auth.change_own_password_user', None), |
| 42 | + 'MIDDLEWARE': [ |
| 43 | + # TODO: Try to reduce the set of absolutely required middlewares |
| 44 | + 'request_id.middleware.RequestIdMiddleware', |
| 45 | + 'django.contrib.sessions.middleware.SessionMiddleware', |
| 46 | + 'django.middleware.csrf.CsrfViewMiddleware', |
| 47 | + 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 48 | + 'binder.plugins.token_auth.middleware.TokenAuthMiddleware', |
98 | 49 | ], |
99 | | - # Basic permissions which can be used to override stuff |
100 | | - 'testapp.view_country': [ |
101 | | - |
102 | | - ] |
103 | | - }, |
104 | | - 'GROUP_PERMISSIONS': { |
105 | | - 'admin': [ |
106 | | - 'testapp.view_country' |
107 | | - ] |
108 | | - }, |
109 | | - 'GROUP_CONTAINS': { |
110 | | - 'admin': [] |
111 | | - }, |
112 | | - 'INTERNAL_MEDIA_HEADER': 'X-Accel-Redirect', |
113 | | - 'INTERNAL_MEDIA_LOCATION': '/internal/media/', |
114 | | -}) |
| 50 | + 'INSTALLED_APPS': [ |
| 51 | + # TODO: Try to reduce the set of absolutely required applications |
| 52 | + 'django.contrib.auth', |
| 53 | + 'django.contrib.contenttypes', |
| 54 | + 'django.contrib.sessions', |
| 55 | + 'binder', |
| 56 | + 'binder.plugins.token_auth', |
| 57 | + 'tests', |
| 58 | + 'tests.testapp', |
| 59 | + ], |
| 60 | + 'MIGRATION_MODULES': { |
| 61 | + 'testapp': None, |
| 62 | + 'auth': None, |
| 63 | + 'sessions': None, |
| 64 | + 'contenttypes': None, |
| 65 | + 'binder': None, |
| 66 | + 'token_auth': None, |
| 67 | + }, |
| 68 | + 'USE_TZ': True, |
| 69 | + 'TIME_ZONE': 'UTC', |
| 70 | + 'ROOT_URLCONF': 'tests.testapp.urls', |
| 71 | + 'LOGGING': { |
| 72 | + 'version': 1, |
| 73 | + 'handlers': { |
| 74 | + 'console': { |
| 75 | + 'level': 'DEBUG', |
| 76 | + 'class': 'logging.StreamHandler', |
| 77 | + }, |
| 78 | + }, |
| 79 | + 'loggers': { |
| 80 | + # We override only this one to avoid logspam |
| 81 | + # while running tests. Django warnings are |
| 82 | + # stil shown. |
| 83 | + 'binder': { |
| 84 | + 'handlers': ['console'], |
| 85 | + 'level': 'ERROR', |
| 86 | + }, |
| 87 | + } |
| 88 | + }, |
| 89 | + 'BINDER_PERMISSION': { |
| 90 | + 'default': [ |
| 91 | + ('auth.reset_password_user', None), |
| 92 | + ('auth.view_user', 'own'), |
| 93 | + ('auth.activate_user', None), |
| 94 | + ('auth.unmasquerade_user', None), # If you are masquarade, the user must be able to unmasquarade |
| 95 | + ('auth.login_user', None), |
| 96 | + ('auth.signup_user', None), |
| 97 | + ('auth.logout_user', None), |
| 98 | + ('auth.change_own_password_user', None), |
| 99 | + ], |
| 100 | + # Basic permissions which can be used to override stuff |
| 101 | + 'testapp.view_country': [ |
115 | 102 |
|
116 | | -setup() |
| 103 | + ] |
| 104 | + }, |
| 105 | + 'GROUP_PERMISSIONS': { |
| 106 | + 'admin': [ |
| 107 | + 'testapp.view_country' |
| 108 | + ] |
| 109 | + }, |
| 110 | + 'GROUP_CONTAINS': { |
| 111 | + 'admin': [] |
| 112 | + }, |
| 113 | + 'INTERNAL_MEDIA_HEADER': 'X-Accel-Redirect', |
| 114 | + 'INTERNAL_MEDIA_LOCATION': '/internal/media/', |
| 115 | + }) |
| 116 | + setup() |
117 | 117 |
|
118 | | -# Do the dance to ensure the models are synched to the DB. |
119 | | -# This saves us from having to include migrations |
120 | | -from django.core.management.commands.migrate import Command as MigrationCommand # noqa |
121 | | -from django.db import connections # noqa |
122 | | -from django.db.migrations.executor import MigrationExecutor # noqa |
| 118 | + # Do the dance to ensure the models are synched to the DB. |
| 119 | + # This saves us from having to include migrations |
| 120 | + from django.core.management.commands.migrate import Command as MigrationCommand # noqa |
| 121 | + from django.db import connections # noqa |
| 122 | + from django.db.migrations.executor import MigrationExecutor # noqa |
123 | 123 |
|
124 | | -# This is oh so hacky.... |
125 | | -cmd = MigrationCommand() |
126 | | -cmd.verbosity = 0 |
127 | | -connection = connections['default'] |
128 | | -executor = MigrationExecutor(connection) |
129 | | -cmd.sync_apps(connection, executor.loader.unmigrated_apps) |
| 124 | + # This is oh so hacky.... |
| 125 | + cmd = MigrationCommand() |
| 126 | + cmd.verbosity = 0 |
| 127 | + connection = connections['default'] |
| 128 | + executor = MigrationExecutor(connection) |
| 129 | + cmd.sync_apps(connection, executor.loader.unmigrated_apps) |
130 | 130 |
|
131 | | -# Hack to make the view_country permission, which doesn't work with the MigrationCommand somehow |
132 | | -from django.contrib.auth.models import Group, Permission, ContentType |
133 | | -content_type = ContentType.objects.get_or_create(app_label='testapp', model='country')[0] |
134 | | -Permission.objects.get_or_create(content_type=content_type, codename='view_country') |
135 | | -call_command('define_groups') |
| 131 | + # Hack to make the view_country permission, which doesn't work with the MigrationCommand somehow |
| 132 | + from django.contrib.auth.models import Group, Permission, ContentType |
| 133 | + content_type = ContentType.objects.get_or_create(app_label='testapp', model='country')[0] |
| 134 | + Permission.objects.get_or_create(content_type=content_type, codename='view_country') |
| 135 | + call_command('define_groups') |
0 commit comments