def test_users(self): user = User("keith") self.assertEqual("keith", user.userid) user.roles.append("admin1") self.assertTrue(user.has_role("admin1")) self.assertFalse(user.has_role("adminx")) group = Group("sysadmin") self.assertFalse(group.has_user("keith")) self.assertEqual([], user.groups) user.add_to_group(group) self.assertTrue(group.has_user("keith")) self.assertEqual([group], user.groups) user.add_to_group(group) self.assertTrue(group.has_user("keith")) self.assertEqual([group], user.groups)
def test_groups(self): group = Group("sysadmin") self.assertEqual("sysadmin", group.groupid) self.assertFalse(group.has_role("admin2")) group.roles.append("admin2") self.assertTrue(group.has_role("admin2")) self.assertEqual([], group.users) self.assertFalse(group.has_user("keith")) self.assertFalse(group.has_user("fred")) user = User("keith") group.add_user(user) self.assertEqual([user], group.users) self.assertTrue(group.has_user("keith")) self.assertFalse(group.has_user("fred")) group.add_user(user) self.assertEqual([user], group.users)