def test_models_sync_inconsistencies(self): from groups_manager import settings settings.GROUPS_MANAGER = deepcopy(GROUPS_MANAGER_MOCK) # change sync between group creation and deletion settings.GROUPS_MANAGER['AUTH_MODELS_SYNC'] = False w = testproject_models.WorkGroup(name='New workgroup') w.save() self.assertIsNone(w.django_group) settings.GROUPS_MANAGER['AUTH_MODELS_SYNC'] = True w.delete() # change sync between member creation and deletion settings.GROUPS_MANAGER['AUTH_MODELS_SYNC'] = False m = testproject_models.OrganizationMember(first_name='Name', last_name='Surname') m.save() self.assertIsNone(m.django_user) settings.GROUPS_MANAGER['AUTH_MODELS_SYNC'] = True m.delete() settings.GROUPS_MANAGER['AUTH_MODELS_SYNC'] = True w = testproject_models.WorkGroup(name='New workgroup') w.save() m = testproject_models.OrganizationMember(first_name='Name', last_name='Surname') m.save() # add to group outside membership m.django_user.groups.add(w.django_group) w.add_member(m) self.assertTrue(w.django_group in m.django_user.groups.all()) w.remove_member(m) # delete django group w.django_group = None w.add_member(m)
def test_models_sync_inconsistencies_group_member(self): from groups_manager import settings settings.GROUPS_MANAGER = deepcopy(GROUPS_MANAGER_MOCK) # change sync between group creation and deletion w = testproject_models.WorkGroup(name='New workgroup') w.save() m = testproject_models.OrganizationMember(first_name='Name', last_name='Surname') m.save() # remove django group from django user manually w.add_member(m) m.django_user.groups.remove(w.django_group) w.remove_member(m) # manually remove django group w.add_member(m) g = w.django_group w.django_group = None w.remove_member(m) w.django_group = g # manually delete django group w.add_member(m) g = w.django_group g.delete() w.remove_member(m)
def test_signals_kwargs(self): from groups_manager import settings settings.GROUPS_MANAGER = deepcopy(GROUPS_MANAGER_MOCK) settings.GROUPS_MANAGER['AUTH_MODELS_SYNC'] = False # TEST 'get_auth_models_sync_func' # default signal w = testproject_models.WorkGroup(name='New workgroup') w.save() self.assertIsNone(w.django_group) # test signal wrapping pg = testproject_models.ProjectGroup(name='Project group') pg.save() self.assertIsNotNone(pg.django_group) self.assertTrue(pg.django_group.name.startswith('PGS_')) self.assertTrue(pg.django_group.name.endswith('_Project')) pm = testproject_models.ProjectMember(first_name='Mike', last_name='Miky') pm.save() self.assertTrue(pm.django_user.username.startswith('PGS_')) self.assertTrue(pm.django_user.username.endswith('_Project')) self.assertIsNotNone(pm.django_user) pg.add_member(pm) self.assertTrue(pg.django_group in pm.django_user.groups.all()) pg.remove_member(pm) # Test catch exception with self.assertRaises(exceptions_gm.GetGroupMemberError): pg.remove_member(pm) self.assertFalse(pg.django_group in pm.django_user.groups.all()) self.assertFalse(pm in pg.members) pm_django_user_id = pm.django_user.id pm.delete() django_user = auth_models.User.objects.filter(id=pm_django_user_id) self.assertEqual(len(django_user), 0) pg_django_group_id = pg.django_group.id pg.delete() django_group = auth_models.Group.objects.filter(id=pg_django_group_id) self.assertEqual(len(django_group), 0)