def test_duplicate_users(self):
        """Tests adding users with the same name, but duplicate in case."""
        auag = UsersAndGroups()

        auag.add_user(User("user1"))
        with self.assertRaises(Exception):
            auag.add_user(User("user1"))
        with self.assertRaises(Exception):
            auag.add_user(User("User1"))
        self.assertEqual(auag.number_users(), 1)

        self.assertTrue(auag.has_user("user1"))
        self.assertTrue(auag.has_user("User1"))

        auag.remove_user("user1")
        self.assertFalse(auag.has_user("user1"))
        self.assertEqual(auag.number_users(), 0)
示例#2
0
    def test_adding_and_removing_users(self):
        """Tests adding and removing users."""
        auag = UsersAndGroups()

        auag.add_user(User("user1"))
        auag.add_user(User("user2"))

        self.assertTrue(auag.has_user("user1"))
        self.assertFalse(auag.has_user("user6"))
        self.assertEqual(auag.number_users(), 2)

        auag.remove_user("user1")
        self.assertFalse(auag.has_user("user1"))
        self.assertEqual(auag.number_users(), 1)

        self.assertTrue(auag.has_user("user2"))
        u = auag.get_user("user2")
        self.assertTrue(u.name, "user2")

        self.assertIsNone(auag.get_user("noone"))