2014-10-11 14:34:49 +02:00
|
|
|
from openslides.users.api import gen_password, gen_username
|
|
|
|
from openslides.users.models import Group, User
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.utils.test import TestCase
|
2013-06-16 12:00:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UserTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.user1 = User()
|
2014-10-11 14:34:49 +02:00
|
|
|
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()
|
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def test_str(self):
|
|
|
|
self.assertEqual(str(self.user1), 'Max Mustermann')
|
2013-06-16 12:00:57 +02:00
|
|
|
|
|
|
|
def test_name_suffix(self):
|
2014-10-11 14:34:49 +02:00
|
|
|
self.user1.structure_level = 'München'
|
2013-06-16 12:00:57 +02:00
|
|
|
self.user1.save()
|
2014-10-11 14:34:49 +02:00
|
|
|
self.assertEqual(str(self.user1), 'Max Mustermann (München)')
|
2013-06-16 12:00:57 +02:00
|
|
|
|
|
|
|
def test_reset_password(self):
|
2014-08-16 09:25:18 +02:00
|
|
|
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):
|
2014-10-11 14:34:49 +02:00
|
|
|
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:
|
2014-08-16 09:25:18 +02:00
|
|
|
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)
|
2014-01-28 08:32:26 +01:00
|
|
|
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',
|
2014-10-11 14:34:49 +02:00
|
|
|
'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)
|