def test_duplicate_groups(self): """Tests creating duplicate groups with different flags.""" auag = UsersAndGroups() # create a duplicate with default flag to raise an error. auag.add_group(Group(name="group1")) with self.assertRaises(Exception): auag.add_group(Group(name="group1")) # create with overwrite. auag.add_group( Group(name="group2", group_names=["group2"]), duplicate=UsersAndGroups.OVERWRITE_ON_DUPLICATE, ) u = auag.get_group("group2") self.assertEqual(u.name, "group2") self.assertEqual(u.groupNames, ["group2"]) auag.add_group( Group(name="group2", group_names=["group3"]), duplicate=UsersAndGroups.OVERWRITE_ON_DUPLICATE, ) u = auag.get_group("group2") self.assertEqual(u.name, "group2") self.assertEqual(u.groupNames, ["group3"]) # create with update. auag.add_group( Group(name="group3", group_names=["group2"]), duplicate=UsersAndGroups.OVERWRITE_ON_DUPLICATE, ) u = auag.get_group("group3") self.assertEqual(u.name, "group3") self.assertEqual(u.groupNames, ["group2"]) auag.add_group( Group(name="group3", group_names=["group3"]), duplicate=UsersAndGroups.UPDATE_ON_DUPLICATE, ) u = auag.get_group("group3") self.assertEqual(u.groupNames, ["group2", "group3"])
def test_adding_and_removing_groups(self): """Tests adding and removing groups.""" auag = UsersAndGroups() auag.add_group(Group("Group1")) auag.add_group(Group("Group2")) auag.add_group(Group("Group3")) self.assertTrue(auag.has_group("Group1")) self.assertTrue(auag.has_group("Group2")) self.assertTrue(auag.has_group("Group3")) self.assertEqual(auag.number_groups(), 3) auag.remove_group("Group1") self.assertFalse(auag.has_group("Group1")) self.assertEqual(auag.number_groups(), 2) self.assertTrue(auag.has_group("Group2")) u = auag.get_group("Group2") self.assertTrue(u.name, "Group2") self.assertIsNone(auag.get_group("noone"))