Skip to content

Commit

Permalink
basic tests finished
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Oct 27, 2017
1 parent 9a003d8 commit 8520fbc
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 33 deletions.
1 change: 1 addition & 0 deletions separate_users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 12 additions & 13 deletions separate_users/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions separate_users/tests/settings_custom_user.py
Original file line number Diff line number Diff line change
@@ -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')
13 changes: 10 additions & 3 deletions separate_users/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(
Expand Down
Empty file.
File renamed without changes.
5 changes: 5 additions & 0 deletions separate_users/tests/test_app_custom_user/admin.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
6 changes: 6 additions & 0 deletions separate_users/tests/test_app_custom_user/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.conf import settings
from django.contrib.auth.models import AbstractUser


class CustomUser(AbstractUser):
pass
24 changes: 11 additions & 13 deletions separate_users/tests/test_compatibility.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -10,23 +8,23 @@ 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

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()
22 changes: 18 additions & 4 deletions separate_users/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,16 +8,29 @@
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

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

0 comments on commit 8520fbc

Please sign in to comment.