OpenSlides/tests/users/test_models.py

65 lines
2.5 KiB
Python
Raw Normal View History

from openslides.users.api import gen_password, gen_username
from openslides.users.models import Group, User
from openslides.utils.test import TestCase
2013-06-16 12:00:57 +02:00
class UserTest(TestCase):
def setUp(self):
self.user1 = User()
self.user1.first_name = 'Max'
self.user1.last_name = 'Mustermann'
2013-06-16 12:00:57 +02:00
self.user1.username = gen_username(
self.user1.first_name, self.user1.last_name)
self.user1.default_password = gen_password()
self.user1.save()
def test_str(self):
self.assertEqual(str(self.user1), 'Max Mustermann')
2013-06-16 12:00:57 +02:00
def test_name_suffix(self):
self.user1.structure_level = 'München'
2013-06-16 12:00:57 +02:00
self.user1.save()
self.assertEqual(str(self.user1), 'Max Mustermann (München)')
2013-06-16 12:00:57 +02:00
def test_reset_password(self):
self.assertIsInstance(self.user1.default_password, str)
2013-06-16 12:00:57 +02:00
self.assertEqual(len(self.user1.default_password), 8)
self.user1.set_unusable_password()
self.assertFalse(self.user1.check_password(self.user1.default_password))
self.user1.reset_password()
self.assertTrue(self.user1.check_password(self.user1.default_password))
2013-11-06 17:08:54 +01:00
def test_get_absolute_url(self):
urls = (('detail', '/user/2/'),
('update', '/user/2/edit/'),
('delete', '/user/2/del/'))
2013-11-06 17:08:54 +01:00
for link, url in urls:
self.assertEqual(self.user1.get_absolute_url(link), url)
2013-06-16 12:00:57 +02:00
2013-04-02 15:50:40 +02:00
class DefaultGroups(TestCase):
def test_pks_of_default_groups(self):
default_groups = ((1, 'Anonymous'),
(2, 'Registered'),
(3, 'Delegates'),
(4, 'Staff'))
for pk, name in default_groups:
self.assertEqual(Group.objects.get(pk=pk).name, name)
2013-04-02 15:50:40 +02:00
def test_default_perms_anonymous(self):
anonymous = Group.objects.get(pk=1)
default_perms = ('core.can_see_projector',
'core.can_see_dashboard',
2013-04-02 15:50:40 +02:00
'agenda.can_see_agenda',
'agenda.can_see_orga_items',
'motion.can_see_motion',
'assignment.can_see_assignment',
'users.can_see',
2013-04-02 15:50:40 +02:00
'mediafile.can_see')
for perm_string in default_perms:
perm_string_list = []
for perm in anonymous.permissions.all():
perm_string_list.append('%s.%s' % (perm.content_type.app_label, perm.codename))
self.assertTrue(perm_string in perm_string_list)