2012-08-07 10:15:39 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.participant.tests
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Unit test for the participant app.
|
|
|
|
|
|
|
|
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.client import Client
|
|
|
|
from django.contrib.auth.hashers import check_password
|
|
|
|
|
2012-08-08 10:07:36 +02:00
|
|
|
from openslides.utils.person import get_person, Persons
|
|
|
|
from openslides.participant.api import gen_username, gen_password
|
2012-08-12 12:52:38 +02:00
|
|
|
from openslides.participant.models import User, Group
|
2012-08-07 10:15:39 +02:00
|
|
|
|
|
|
|
|
2012-08-12 12:52:38 +02:00
|
|
|
class UserTest(TestCase):
|
2012-08-07 10:15:39 +02:00
|
|
|
def setUp(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.user1 = User()
|
|
|
|
self.user1.first_name = u'Max'
|
|
|
|
self.user1.last_name = u'Mustermann'
|
|
|
|
self.user1.username = gen_username(
|
|
|
|
self.user1.first_name, self.user1.last_name)
|
|
|
|
self.user1.firstpassword = gen_password()
|
|
|
|
self.user1.save()
|
|
|
|
self.django_user1 = self.user1.django_user
|
2012-08-07 10:15:39 +02:00
|
|
|
|
|
|
|
def test_participant_user(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertEqual(self.django_user1.user, self.user1)
|
|
|
|
self.assertEqual(self.django_user1, self.user1.django_user)
|
2012-08-07 10:15:39 +02:00
|
|
|
|
|
|
|
def test_repr(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertEqual(unicode(self.user1), u'Max Mustermann')
|
2012-08-07 10:15:39 +02:00
|
|
|
|
2012-08-08 10:07:36 +02:00
|
|
|
def test_name_surfix(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.user1.category = u'München'
|
|
|
|
self.user1.save()
|
|
|
|
self.assertEqual(unicode(self.user1), u'Max Mustermann (München)')
|
2012-08-07 10:15:39 +02:00
|
|
|
|
|
|
|
def test_reset_password(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertIsInstance(self.user1.firstpassword, basestring)
|
|
|
|
self.assertEqual(len(self.user1.firstpassword), 8)
|
2012-08-07 10:15:39 +02:00
|
|
|
self.user1.set_unusable_password()
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertFalse(self.user1.check_password(self.user1.firstpassword))
|
|
|
|
self.user1.reset_password()
|
|
|
|
self.assertTrue(self.user1.check_password(self.user1.firstpassword))
|
2012-08-07 10:15:39 +02:00
|
|
|
|
2012-08-08 10:07:36 +02:00
|
|
|
def test_person_api(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertTrue(hasattr(self.user1, 'person_id'))
|
|
|
|
self.assertEqual(self.user1.person_id, 'user:1')
|
|
|
|
self.assertEqual(get_person('user:1'), self.user1)
|
|
|
|
self.assertEqual(len(Persons(person_prefix='user')), 1)
|
2012-08-07 10:15:39 +02:00
|
|
|
|
|
|
|
|
2012-08-12 12:52:38 +02:00
|
|
|
class GroupTest(TestCase):
|
2012-08-07 10:15:39 +02:00
|
|
|
def setUp(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.group1 = Group.objects.create(name='Test Group')
|
|
|
|
self.django_group1 = self.group1.django_group
|
2012-08-07 10:15:39 +02:00
|
|
|
|
2012-08-12 12:52:38 +02:00
|
|
|
def test_group_group(self):
|
|
|
|
self.assertEqual(self.group1.django_group, self.django_group1)
|
|
|
|
self.assertEqual(self.group1, self.django_group1.group)
|
2012-08-07 10:15:39 +02:00
|
|
|
|
2012-08-08 10:07:36 +02:00
|
|
|
def test_person_api(self):
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertTrue(hasattr(self.group1, 'person_id'))
|
|
|
|
person_id = "group:%d" % self.group1.id
|
|
|
|
self.assertEqual(self.group1.person_id, person_id)
|
2012-08-13 14:37:49 +02:00
|
|
|
self.assertRaises(Group.DoesNotExist)
|
|
|
|
self.group1.group_as_person = True
|
|
|
|
self.group1.save()
|
2012-08-12 12:52:38 +02:00
|
|
|
self.assertEqual(get_person(person_id), self.group1)
|