|
@@ -24,6 +24,8 @@ import nose.tools
|
|
|
|
|
|
|
|
from useradmin.models import User, Group, Organization
|
|
from useradmin.models import User, Group, Organization
|
|
|
|
|
|
|
|
|
|
+from desktop.conf import ENABLE_ORGANIZATIONS
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class Client(django.test.client.Client):
|
|
class Client(django.test.client.Client):
|
|
|
"""
|
|
"""
|
|
@@ -48,8 +50,8 @@ def make_logged_in_client(username="test", password="test", is_superuser=True, r
|
|
|
"""
|
|
"""
|
|
|
Create a client with a user already logged in.
|
|
Create a client with a user already logged in.
|
|
|
|
|
|
|
|
- Sometimes we recreate the user, because some tests like to
|
|
|
|
|
- mess with is_active and such.
|
|
|
|
|
|
|
+ Sometimes we recreate the user, because some tests like to mess with is_active and such.
|
|
|
|
|
+ Note: could be combined with backend.create_user and other standart utils.
|
|
|
"""
|
|
"""
|
|
|
try:
|
|
try:
|
|
|
user = User.objects.get(username=username)
|
|
user = User.objects.get(username=username)
|
|
@@ -66,8 +68,13 @@ def make_logged_in_client(username="test", password="test", is_superuser=True, r
|
|
|
user.save()
|
|
user.save()
|
|
|
|
|
|
|
|
if groupname is not None:
|
|
if groupname is not None:
|
|
|
- group, created = Group.objects.get_or_create(name=groupname)
|
|
|
|
|
- if not user.groups.filter(name=group.name).exists():
|
|
|
|
|
|
|
+ attributes = {'name': groupname}
|
|
|
|
|
+
|
|
|
|
|
+ if ENABLE_ORGANIZATIONS.get():
|
|
|
|
|
+ attributes['organization'] = user.organization
|
|
|
|
|
+
|
|
|
|
|
+ group, created = Group.objects.get_or_create(**attributes)
|
|
|
|
|
+ if not user.groups.filter(**attributes).exists():
|
|
|
user.groups.add(group)
|
|
user.groups.add(group)
|
|
|
user.save()
|
|
user.save()
|
|
|
|
|
|