diff --git a/separate_users/models.py b/separate_users/models.py index 50dd3a9..8198c41 100644 --- a/separate_users/models.py +++ b/separate_users/models.py @@ -57,6 +57,7 @@ def save(self, *args, **kwargs): self.is_staff = False super(FrontendUser, self).save(*args, **kwargs) + class Editor(SeparateUserBase, UserModel): objects = EditorManager() diff --git a/separate_users/tests/settings.py b/separate_users/tests/settings.py index 5bf189f..e22e8f2 100644 --- a/separate_users/tests/settings.py +++ b/separate_users/tests/settings.py @@ -46,17 +46,6 @@ 'migrations', 'fixtures', 'admin$', 'django_extensions', ] -EXTERNAL_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.messages', - 'django.contrib.sessions', - 'django.contrib.staticfiles', - 'django.contrib.sitemaps', - 'django.contrib.sites', -) - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -79,11 +68,21 @@ }, ] +EXTERNAL_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.messages', + 'django.contrib.sessions', + 'django.contrib.staticfiles', + 'django.contrib.sitemaps', + 'django.contrib.sites', +] -INTERNAL_APPS = ( +INTERNAL_APPS = [ 'separate_users', 'separate_users.tests.test_app', -) +] MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', diff --git a/separate_users/tests/settings_custom_user.py b/separate_users/tests/settings_custom_user.py new file mode 100644 index 0000000..7fefa00 --- /dev/null +++ b/separate_users/tests/settings_custom_user.py @@ -0,0 +1,10 @@ +from .settings import * +# TODO: it doesnt work! + +AUTH_USER_MODEL = 'test_app_custom_user.CustomUser' + +del(INSTALLED_APPS[INSTALLED_APPS.index('separate_users.tests.test_app')]) + +print INSTALLED_APPS + +INSTALLED_APPS.insert(0, 'separate_users.tests.test_app_custom_user') diff --git a/separate_users/tests/test_admin.py b/separate_users/tests/test_admin.py index 7324c97..a54e7e7 100644 --- a/separate_users/tests/test_admin.py +++ b/separate_users/tests/test_admin.py @@ -13,6 +13,7 @@ class AdminTestCase(TestCase): TODO: check with custom User Model! """ def setUp(self): + self.auth_custom_user = 'test_app_custom_user.CustomUser' self.superuser = create_superuser() self.client.login(username='admin', password='secret') self.frontenduser = FrontendUser.objects.create(username='frontend') @@ -33,16 +34,22 @@ def test_editor_changelist(self): self.changelist('editor') # @override_settings( - # AUTH_USER_MODEL = 'test_app.CustomUser' + # AUTH_USER_MODEL = 'test_app_custom_user.CustomUser' # ) # def test_frontend_user_changelist_custom_user(self): # self.changelist('frontenduser') # # @override_settings( - # AUTH_USER_MODEL = 'test_app.CustomUser' + # AUTH_USER_MODEL = 'test_app_custom_user.CustomUser' # ) # def test_editor_changelist_custom_user(self): - # self.changelist('editor') + # with self.modify_settings(INSTALLED_APPS={ + # 'append': 'test_app_custom_user', + # 'remove': [ + # 'test_app', + # ], + # }): + # self.changelist('editor') def change(self, user_version, id): url = reverse( diff --git a/separate_users/tests/test_app/views.py b/separate_users/tests/test_app/views.py deleted file mode 100644 index e69de29..0000000 diff --git a/separate_users/tests/test_app/admin.py b/separate_users/tests/test_app_custom_user/__init__.py similarity index 100% rename from separate_users/tests/test_app/admin.py rename to separate_users/tests/test_app_custom_user/__init__.py diff --git a/separate_users/tests/test_app_custom_user/admin.py b/separate_users/tests/test_app_custom_user/admin.py new file mode 100644 index 0000000..5ef0f20 --- /dev/null +++ b/separate_users/tests/test_app_custom_user/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin +from .models import CustomUser + +admin.site.register(CustomUser, UserAdmin) diff --git a/separate_users/tests/test_app/models.py b/separate_users/tests/test_app_custom_user/migrations/__init__.py similarity index 100% rename from separate_users/tests/test_app/models.py rename to separate_users/tests/test_app_custom_user/migrations/__init__.py diff --git a/separate_users/tests/test_app_custom_user/models.py b/separate_users/tests/test_app_custom_user/models.py new file mode 100644 index 0000000..34d487b --- /dev/null +++ b/separate_users/tests/test_app_custom_user/models.py @@ -0,0 +1,6 @@ +from django.conf import settings +from django.contrib.auth.models import AbstractUser + + +class CustomUser(AbstractUser): + pass diff --git a/separate_users/tests/test_compatibility.py b/separate_users/tests/test_compatibility.py index 4787279..c8c75a3 100644 --- a/separate_users/tests/test_compatibility.py +++ b/separate_users/tests/test_compatibility.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from time import sleep - -from django.contrib.auth.models import User +from django.test import override_settings from django.test.testcases import TestCase @@ -10,9 +8,6 @@ class AdminTestCase(TestCase): TODO: check for pre 1.11 ImproperlyConfigured etc. TODO: check that MIGRATION_MODULES is configured (migration are written into this app!) """ - username = 'admin' - password = 'admin' - def setUp(self): pass @@ -20,13 +15,16 @@ def tearDown(self): pass def test_improperly_pre_1_11_with_custom_user_model(self): - exit() + pass + @override_settings( + MIGRATION_MODULES = {} + ) def test_improperly_no_migration_modules(self): - exit() - - def test_frontend_user_changeview(self): - exit() + """ + TOOD: trigger improperly configured!!? but how? + :return: + """ + from separate_users.models import FrontendUser + FrontendUser.objects.all() - def test_staff_user_changeview(self): - exit() diff --git a/separate_users/tests/test_permissions.py b/separate_users/tests/test_permissions.py index 134a52e..5930b15 100644 --- a/separate_users/tests/test_permissions.py +++ b/separate_users/tests/test_permissions.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from django.contrib.auth.models import Permission from django.core.urlresolvers import reverse from django.test import Client from django.test import TestCase @@ -7,7 +8,6 @@ class PermissionsTestCase(TestCase): """ check if permissions are there, after management command was run. - check if not there initially - this will fail if django fixes the bug! nice to know. """ def setUp(self): pass @@ -15,8 +15,22 @@ def setUp(self): def tearDown(self): pass - def no_permissions_initially(self): - exit() + def test_no_permissions_initially(self): + """ + check if not there initially - this will fail if django fixes the bug! nice to know. + """ + self.assertEqual(self.permission_count('separate_users', 'add_frontenduser'), 0) + self.assertEqual(self.permission_count('separate_users', 'add_editor'), 0) def test_permission_management_command(self): - exit() + from django.core.management import call_command + call_command('fix_proxy_permissions', ) + self.assertEqual(self.permission_count('separate_users', 'add_frontenduser'), 1) + self.assertEqual(self.permission_count('separate_users', 'add_editor'), 1) + + def permission_count(self, app_label, codename): + count = Permission.objects.filter( + content_type__app_label=app_label, + codename=codename, + ).count() + return count \ No newline at end of file