gva/gnuviechadmin/osusers/tests/test_models.py

61 lines
1.8 KiB
Python

from django.core.exceptions import ValidationError
from django.test import TestCase
from django.test.utils import override_settings
from osusers.models import (
CANNOT_USE_PRIMARY_GROUP_AS_ADDITIONAL,
AdditionalGroup,
Group,
Shadow,
User,
)
@override_settings(
CELERY_ALWAYS_EAGER=True,
CELERY_CACHE_BACKEND='memory',
BROKER_BACKEND='memory'
)
class TestCaseWithCeleryTasks(TestCase):
pass
class AdditionalGroupTest(TestCaseWithCeleryTasks):
def test_clean_primary_group(self):
group1 = Group.objects.create(groupname='test1', gid=1000)
user = User.objects.create(
username='test', uid=1000, group=group1,
homedir='/home/test', shell='/bin/bash')
testsubj = AdditionalGroup(user=user, group=group1)
with self.assertRaises(ValidationError) as cm:
testsubj.clean()
self.assertEqual(
cm.exception.message, CANNOT_USE_PRIMARY_GROUP_AS_ADDITIONAL)
def test_clean_other_group(self):
group1 = Group(groupname='test1', gid=1000)
group2 = Group(groupname='test2', gid=1001)
user = User(username='test', uid=1000, group=group1,
homedir='/home/test', shell='/bin/bash')
testsubj = AdditionalGroup(user=user, group=group2)
testsubj.clean()
class GroupTest(TestCaseWithCeleryTasks):
pass
class ShadowTest(TestCaseWithCeleryTasks):
def test___str__(self):
group = Group.objects.create(
groupname='test', gid=1000)
user = User.objects.create(
username='test', uid=1000, group=group, homedir='/home/test',
shell='/bin/bash')
shadow = Shadow(user=user)
self.assertEqual(str(shadow), 'for user test (1000)')
class UserTest(TestCaseWithCeleryTasks):
pass