made participant-test run again
This commit is contained in:
parent
1719aa588d
commit
f22362df9d
@ -51,11 +51,13 @@ class OpenSlidesUser(models.Model, PersonMixin):
|
|||||||
firstpassword = models.CharField(max_length=100, null=True, blank=True,
|
firstpassword = models.CharField(max_length=100, null=True, blank=True,
|
||||||
verbose_name = _("First Password"))
|
verbose_name = _("First Password"))
|
||||||
|
|
||||||
def reset_password(self):
|
def reset_password(self, password=None):
|
||||||
"""
|
"""
|
||||||
Reset the password for the user to his default-password.
|
Reset the password for the user to his default-password.
|
||||||
"""
|
"""
|
||||||
self.user.set_password(self.firstpassword)
|
if password is None:
|
||||||
|
password = self.firstpassword
|
||||||
|
self.user.set_password(password)
|
||||||
self.user.save()
|
self.user.save()
|
||||||
|
|
||||||
def has_perm(self, perm):
|
def has_perm(self, perm):
|
||||||
@ -114,7 +116,7 @@ class OpenSlidesUsersConnecter(object):
|
|||||||
|
|
||||||
if not self.person_prefix or self.person_prefix == OpenSlidesGroup.person_prefix:
|
if not self.person_prefix or self.person_prefix == OpenSlidesGroup.person_prefix:
|
||||||
if self.id:
|
if self.id:
|
||||||
yield OpenSlidesObject.objects.get(pk=self.id)
|
yield OpenSlidesGroup.objects.get(pk=self.id)
|
||||||
else:
|
else:
|
||||||
for group in OpenSlidesGroup.objects.all():
|
for group in OpenSlidesGroup.objects.all():
|
||||||
yield group
|
yield group
|
||||||
|
@ -16,72 +16,57 @@ from django.contrib.auth.models import User, Group
|
|||||||
from django.db.models.query import EmptyQuerySet
|
from django.db.models.query import EmptyQuerySet
|
||||||
from django.contrib.auth.hashers import check_password
|
from django.contrib.auth.hashers import check_password
|
||||||
|
|
||||||
from openslides.utils.user import get_user, Users
|
from openslides.utils.person import get_person, Persons
|
||||||
from openslides.participant.api import gen_username, gen_password, user2djangouser
|
from openslides.participant.api import gen_username, gen_password
|
||||||
from openslides.participant.models import Profile, DjangoGroup, DjangoUser
|
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
|
||||||
|
|
||||||
|
|
||||||
class ParticipantTest(TestCase):
|
class OpenSlidesUserTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user1 = User(first_name=u'Max', last_name=u'Mustermann')
|
self.user1 = User(first_name=u'Max', last_name=u'Mustermann')
|
||||||
self.user1.username = gen_username(self.user1.first_name, self.user1.last_name)
|
self.user1.username = gen_username(self.user1.first_name, self.user1.last_name)
|
||||||
self.user1.save()
|
self.user1.save()
|
||||||
self.participant1 = Profile.objects.create(user=self.user1, firstpassword=gen_password())
|
self.openslidesuser1 = self.user1.openslidesuser
|
||||||
|
self.openslidesuser1.firstpassword = gen_password()
|
||||||
|
self.openslidesuser1.save()
|
||||||
|
self.user1 = self.openslidesuser1.user
|
||||||
|
|
||||||
def test_participant_user(self):
|
def test_participant_user(self):
|
||||||
self.assertEqual(self.user1.profile, self.participant1)
|
self.assertEqual(self.user1.openslidesuser, self.openslidesuser1)
|
||||||
self.assertEqual(self.user1, self.participant1.user)
|
self.assertEqual(self.user1, self.openslidesuser1.user)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
self.assertEqual(unicode(self.participant1), u'Max Mustermann')
|
self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann')
|
||||||
|
|
||||||
def test_group(self):
|
def test_name_surfix(self):
|
||||||
self.participant1.group = u'München'
|
self.openslidesuser1.name_surfix = u'München'
|
||||||
self.participant1.save()
|
self.openslidesuser1.save()
|
||||||
self.assertEqual(unicode(self.participant1), u'Max Mustermann (München)')
|
self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann (München)')
|
||||||
|
|
||||||
def test_reset_password(self):
|
def test_reset_password(self):
|
||||||
self.assertIsInstance(self.participant1.firstpassword, basestring)
|
self.assertIsInstance(self.openslidesuser1.firstpassword, basestring)
|
||||||
self.assertEqual(len(self.participant1.firstpassword), 8)
|
self.assertEqual(len(self.openslidesuser1.firstpassword), 8)
|
||||||
self.user1.set_unusable_password()
|
self.user1.set_unusable_password()
|
||||||
self.assertFalse(self.user1.check_password(self.participant1.firstpassword))
|
self.assertFalse(self.user1.check_password(self.openslidesuser1.firstpassword))
|
||||||
self.participant1.reset_password()
|
self.openslidesuser1.reset_password()
|
||||||
self.assertTrue(self.user1.check_password(self.participant1.firstpassword))
|
self.assertTrue(self.user1.check_password(self.openslidesuser1.firstpassword))
|
||||||
|
|
||||||
def test_user_api(self):
|
def test_person_api(self):
|
||||||
self.assertTrue(hasattr(self.participant1, 'uid'))
|
self.assertTrue(hasattr(self.openslidesuser1, 'person_id'))
|
||||||
self.assertEqual(self.participant1.uid, 'participant:1')
|
self.assertEqual(self.openslidesuser1.person_id, 'openslides_user:1')
|
||||||
self.assertEqual(get_user('participant:1'), self.participant1)
|
self.assertEqual(get_person('openslides_user:1'), self.openslidesuser1)
|
||||||
self.assertEqual(len(Users()), 1)
|
self.assertEqual(len(Persons()), 1)
|
||||||
|
|
||||||
|
|
||||||
class DjangoGroupTest(TestCase):
|
class OpenSlidesGroupTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.group1 = Group.objects.create(name='Test Group')
|
self.group1 = Group.objects.create(name='Test Group')
|
||||||
self.djangogroup1 = DjangoGroup.objects.create(group=self.group1)
|
self.openslidesgroup1 = OpenSlidesGroup.objects.create(group=self.group1)
|
||||||
|
|
||||||
def test_group_djangogroup(self):
|
def test_group_openslidesgroup(self):
|
||||||
self.assertEqual(self.djangogroup1.group, self.group1)
|
self.assertEqual(self.openslidesgroup1.group, self.group1)
|
||||||
|
|
||||||
def test_user_api(self):
|
def test_person_api(self):
|
||||||
self.assertTrue(hasattr(self.djangogroup1, 'uid'))
|
self.assertTrue(hasattr(self.openslidesgroup1, 'person_id'))
|
||||||
self.assertEqual(self.djangogroup1.uid, 'djangogroup:1')
|
self.assertEqual(self.openslidesgroup1.person_id, 'openslides_group:1')
|
||||||
self.assertEqual(get_user('djangogroup:1'), self.djangogroup1)
|
self.assertEqual(get_person('openslides_group:1'), self.openslidesgroup1)
|
||||||
|
|
||||||
|
|
||||||
class DjangoUserTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.user1 = User.objects.create(username='admin')
|
|
||||||
self.djangouser1 = DjangoUser.objects.get(pk=1)
|
|
||||||
|
|
||||||
def test_djangouser_user(self):
|
|
||||||
self.assertEqual(self.user1.pk, self.djangouser1.pk)
|
|
||||||
|
|
||||||
def test_has_no_profile(self):
|
|
||||||
self.assertTrue(self.djangouser1.has_no_profile())
|
|
||||||
|
|
||||||
def test_user_api(self):
|
|
||||||
self.assertTrue(hasattr(self.djangouser1, 'uid'))
|
|
||||||
self.assertEqual(self.djangouser1.uid, 'djangouser:1')
|
|
||||||
self.assertEqual(get_user('djangouser:1'), self.djangouser1)
|
|
||||||
self.assertEqual(user2djangouser(self.user1), self.djangouser1)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user