add tests for osusers.models.User
- fix task name in Group.delete - remove duplicate task from User.delete - adapt osusers.tests.test_models.GroupTest.test_delete - add tests to UserTest - test_save - test_delete_only_user - test_delete_additional_groups
This commit is contained in:
parent
ceeffb6d1c
commit
b37e44ccfd
2 changed files with 40 additions and 7 deletions
|
@ -97,7 +97,7 @@ class Group(TimeStampedModel, models.Model):
|
||||||
DeleteTaskResult.objects.create_deletetaskresult(
|
DeleteTaskResult.objects.create_deletetaskresult(
|
||||||
'group', self.groupname,
|
'group', self.groupname,
|
||||||
delete_ldap_group_if_empty.delay(self.groupname),
|
delete_ldap_group_if_empty.delay(self.groupname),
|
||||||
'delete_ldap_group'
|
'delete_ldap_group_if_empty'
|
||||||
)
|
)
|
||||||
super(Group, self).delete(*args, **kwargs)
|
super(Group, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -258,11 +258,6 @@ class User(TimeStampedModel, models.Model):
|
||||||
delete_ldap_user.delay(self.username),
|
delete_ldap_user.delay(self.username),
|
||||||
'delete_ldap_user'
|
'delete_ldap_user'
|
||||||
)
|
)
|
||||||
DeleteTaskResult.objects.create_deletetaskresult(
|
|
||||||
'group', self.group.groupname,
|
|
||||||
delete_ldap_group_if_empty.delay(self.group.groupname),
|
|
||||||
'delete_ldap_group_if_empty'
|
|
||||||
)
|
|
||||||
self.group.delete()
|
self.group.delete()
|
||||||
super(User, self).delete(*args, **kwargs)
|
super(User, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,8 @@ class GroupTest(TestCaseWithCeleryTasks):
|
||||||
self.assertEqual(len(GroupTaskResult.objects.all()), 0)
|
self.assertEqual(len(GroupTaskResult.objects.all()), 0)
|
||||||
taskres = DeleteTaskResult.objects.all()
|
taskres = DeleteTaskResult.objects.all()
|
||||||
self.assertEqual(len(taskres), 1)
|
self.assertEqual(len(taskres), 1)
|
||||||
self.assertEqual(taskres[0].task_name, 'delete_ldap_group')
|
self.assertEqual(taskres[0].task_name,
|
||||||
|
'delete_ldap_group_if_empty')
|
||||||
self.assertEqual(taskres[0].modeltype, 'group')
|
self.assertEqual(taskres[0].modeltype, 'group')
|
||||||
self.assertEqual(taskres[0].modelname, 'test')
|
self.assertEqual(taskres[0].modelname, 'test')
|
||||||
|
|
||||||
|
@ -282,3 +283,40 @@ class UserTest(TestCaseWithCeleryTasks):
|
||||||
self.assertEqual(len(taskres), 1)
|
self.assertEqual(len(taskres), 1)
|
||||||
self.assertEqual(taskres[0].user, user)
|
self.assertEqual(taskres[0].user, user)
|
||||||
self.assertEqual(taskres[0].task_name, 'create_ldap_user')
|
self.assertEqual(taskres[0].task_name, 'create_ldap_user')
|
||||||
|
|
||||||
|
def test_save(self):
|
||||||
|
user = User.objects.create_user()
|
||||||
|
UserTaskResult.objects.all().delete()
|
||||||
|
user.save()
|
||||||
|
taskres = UserTaskResult.objects.all()
|
||||||
|
self.assertEqual(len(taskres), 1)
|
||||||
|
self.assertEqual(taskres[0].user, user)
|
||||||
|
self.assertEqual(taskres[0].task_name, 'create_ldap_user')
|
||||||
|
|
||||||
|
def test_delete_only_user(self):
|
||||||
|
user = User.objects.create_user()
|
||||||
|
user.delete()
|
||||||
|
taskres = DeleteTaskResult.objects.all()
|
||||||
|
self.assertEqual(len(taskres), 2)
|
||||||
|
self.assertIn('delete_ldap_user',
|
||||||
|
[r.task_name for r in taskres])
|
||||||
|
self.assertIn('delete_ldap_group_if_empty',
|
||||||
|
[r.task_name for r in taskres])
|
||||||
|
self.assertEqual(len(User.objects.all()), 0)
|
||||||
|
|
||||||
|
def test_delete_additional_groups(self):
|
||||||
|
group1 = Group.objects.create(gid=2000, groupname='group1')
|
||||||
|
group2 = Group.objects.create(gid=2001, groupname='group2')
|
||||||
|
user = User.objects.create_user()
|
||||||
|
for group in [group1, group2]:
|
||||||
|
user.additionalgroup_set.add(
|
||||||
|
AdditionalGroup.objects.create(user=user, group=group))
|
||||||
|
user.delete()
|
||||||
|
taskres = DeleteTaskResult.objects.all()
|
||||||
|
self.assertEqual(len(taskres), 4)
|
||||||
|
tasknames = [t.task_name for t in taskres]
|
||||||
|
self.assertEqual(tasknames.count('remove_ldap_user_from_group'), 2)
|
||||||
|
self.assertEqual(tasknames.count('delete_ldap_user'), 1)
|
||||||
|
self.assertEqual(tasknames.count('delete_ldap_group_if_empty'), 1)
|
||||||
|
self.assertEqual(len(User.objects.all()), 0)
|
||||||
|
self.assertEqual(len(AdditionalGroup.objects.all()), 0)
|
||||||
|
|
Loading…
Reference in a new issue