Skip to content

Commit

Permalink
yes
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Oct 27, 2017
1 parent e3faf8e commit 9a003d8
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 41 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
==== 0.0.1 ===

- initial release


16 changes: 14 additions & 2 deletions separate_users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@

# admin.site.unregister(get_user_model())

class SeparateUserAdminBase(UserAdmin):

class FrontendUserAdmin(UserAdmin):
def get_urls(self):
model_name_lower = self.model.__name__.lower()
return [
url(
r'^(.+)/password/$',
self.admin_site.admin_view(self.user_change_password),
name='separate_users_{}_password_change'.format(model_name_lower),
),
] + super(SeparateUserAdminBase, self).get_urls()


class FrontendUserAdmin(SeparateUserAdminBase):
readonly_fields = ['date_joined', 'last_login', 'is_staff', 'is_superuser', 'groups', 'user_permissions', ]
list_filter = ['is_active', 'groups', ]
list_display = ['username', 'is_active', 'get_groups', ]
Expand All @@ -21,7 +33,7 @@ class FrontendUserAdmin(UserAdmin):
admin.site.register(FrontendUser, FrontendUserAdmin)


class EditorAdmin(UserAdmin):
class EditorAdmin(SeparateUserAdminBase):
exclude = []
readonly_fields = ['date_joined', 'last_login', 'is_staff', 'is_superuser', 'user_permissions', ]
list_filter = ['is_active', 'groups', ]
Expand Down
1 change: 0 additions & 1 deletion separate_users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Meta:
proxy = True

def get_groups(self):
print self.groups.all()
return ', '.join([str(item) for item in self.groups.all()])

get_groups.short_description = ("Groups")
Expand Down
76 changes: 55 additions & 21 deletions separate_users/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,73 @@
# -*- coding: utf-8 -*-
from time import sleep

from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import override_settings
from django.test.testcases import TestCase
from django.urls import reverse

from separate_users.models import Editor, FrontendUser
from separate_users.tests.utils.django_utils import create_superuser


class AdminTestCase(TestCase):
"""
test some basic admin views
make test generic,
check some basic admin views
TODO: check with custom User Model!
"""
username = 'admin'
password = 'admin'

def setUp(self):
pass
self.superuser = create_superuser()
self.client.login(username='admin', password='secret')
self.frontenduser = FrontendUser.objects.create(username='frontend')
self.editor = Editor.objects.create(username='editor')

def tearDown(self):
pass

def changelist(self, user_version):
url = reverse('admin:separate_users_{}_changelist'.format(user_version))
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)

def test_frontend_user_changelist(self):
exit()
self.changelist('frontenduser')

def test_editor_changelist(self):
self.changelist('editor')

# @override_settings(
# AUTH_USER_MODEL = 'test_app.CustomUser'
# )
# def test_frontend_user_changelist_custom_user(self):
# self.changelist('frontenduser')
#
# @override_settings(
# AUTH_USER_MODEL = 'test_app.CustomUser'
# )
# def test_editor_changelist_custom_user(self):
# self.changelist('editor')

def change(self, user_version, id):
url = reverse(
'admin:separate_users_{}_change'.format(user_version),
args=[id]
)
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)

def test_staff_user_changelist(self):
exit()
def test_change_frontenduser(self):
self.change('frontenduser', self.frontenduser.id)

def test_frontend_user_changeview(self):
exit()
def test_change_editor(self):
self.change('editor', self.editor.id)

def test_staff_user_changeview(self):
exit()
def password_change(self, user_version, id):
url = reverse(
'admin:separate_users_{}_password_change'.format(user_version),
args=[id]
)
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)

def test_staff_user_passwordchange(self):
exit()
def test_frontenduser_password_change(self):
self.password_change('frontenduser', self.frontenduser.id)

def test_frontend_user_passwordchange(self):
exit()
def test_editor_password_change(self):
self.password_change('editor', self.editor.id)
4 changes: 2 additions & 2 deletions separate_users/tests/test_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def setUp(self):
def tearDown(self):
pass

def test_frontend_user_changelist(self):
def test_improperly_pre_1_11_with_custom_user_model(self):
exit()

def test_staff_user_changelist(self):
def test_improperly_no_migration_modules(self):
exit()

def test_frontend_user_changeview(self):
Expand Down
17 changes: 4 additions & 13 deletions separate_users/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@

class PermissionsTestCase(TestCase):
"""
TODO: check for pre 1.11 ImproperlyConfigured etc.
TODO: check that MIGRATION_MODULES is configured (migration are written into this app!)
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.
"""
username = 'admin'
password = 'admin'

def setUp(self):
pass

def tearDown(self):
pass

def test_frontend_user_changelist(self):
exit()

def test_staff_user_changelist(self):
exit()

def test_frontend_user_changeview(self):
def no_permissions_initially(self):
exit()

def test_staff_user_changeview(self):
def test_permission_management_command(self):
exit()
5 changes: 5 additions & 0 deletions separate_users/tests/utils/django_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


def create_superuser():
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User # NOQA
superuser = User.objects.create_superuser('admin',
'[email protected]',
'secret')
Expand Down

0 comments on commit 9a003d8

Please sign in to comment.