def test_deactivate_activate_user(self):
        user_id2 = self.create_user_test2()
        self.assertIsNotNone(user_id2)

        user2 = UserManagementInterface.read_user_by_id(user_id2)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test2")
        self.assertEqual(user2["display_name"], "Test 2")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], True)

        # Positive tests ---------------------------------------------------------------------------
        # Deactivate user
        self.assertTrue(UserManagementInterface.deactivate_user(user_id2))

        user2 = UserManagementInterface.read_user_by_id(user_id2)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test2")
        self.assertEqual(user2["display_name"], "Test 2")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], False)

        # Activate user
        self.assertTrue(UserManagementInterface.activate_user(user_id2))

        user2 = UserManagementInterface.read_user_by_id(user_id2)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test2")
        self.assertEqual(user2["display_name"], "Test 2")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], True)
    def test_read_all_user_ids(self):
        # Create users
        user_id1 = self.create_user_test1()
        self.assertIsNotNone(user_id1)

        user_id2 = self.create_user_test2()
        self.assertIsNotNone(user_id2)

        # Check active users
        user_ids = UserManagementInterface.read_all_user_ids(UserSelection.Active)

        self.assertEqual(len(user_ids), 3)
        self.assertListEqual(user_ids, [self.__admin_user_id, user_id1, user_id2])

        # Deactivate user
        self.assertTrue(UserManagementInterface.deactivate_user(user_id1))

        # Recheck active users
        user_ids = UserManagementInterface.read_all_user_ids(UserSelection.Active)

        self.assertEqual(len(user_ids), 2)
        self.assertListEqual(user_ids, [self.__admin_user_id, user_id2])

        # Check inactive users
        user_ids = UserManagementInterface.read_all_user_ids(UserSelection.Inactive)

        self.assertEqual(len(user_ids), 1)
        self.assertListEqual(user_ids, [user_id1])

        # Check all users
        user_ids = UserManagementInterface.read_all_user_ids(UserSelection.All)

        self.assertEqual(len(user_ids), 3)
        self.assertListEqual(user_ids, [self.__admin_user_id, user_id1, user_id2])
    def test_deactivate_activate_user(self):
        user_id2 = self.create_user_test2()
        self.assertIsNotNone(user_id2)

        user2 = UserManagementInterface.read_user_by_id(user_id2)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test2")
        self.assertEqual(user2["display_name"], "Test 2")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], True)

        # Positive tests ---------------------------------------------------------------------------
        # Deactivate user
        self.assertTrue(UserManagementInterface.deactivate_user(user_id2))

        user2 = UserManagementInterface.read_user_by_id(user_id2)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test2")
        self.assertEqual(user2["display_name"], "Test 2")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], False)

        # Activate user
        self.assertTrue(UserManagementInterface.activate_user(user_id2))

        user2 = UserManagementInterface.read_user_by_id(user_id2)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test2")
        self.assertEqual(user2["display_name"], "Test 2")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], True)
    def test_read_all_user_ids(self):
        # Create users
        user_id1 = self.create_user_test1()
        self.assertIsNotNone(user_id1)

        user_id2 = self.create_user_test2()
        self.assertIsNotNone(user_id2)

        # Check active users
        user_ids = UserManagementInterface.read_all_user_ids(
            UserSelection.Active)

        self.assertEqual(len(user_ids), 3)
        self.assertListEqual(user_ids,
                             [self.__admin_user_id, user_id1, user_id2])

        # Deactivate user
        self.assertTrue(UserManagementInterface.deactivate_user(user_id1))

        # Recheck active users
        user_ids = UserManagementInterface.read_all_user_ids(
            UserSelection.Active)

        self.assertEqual(len(user_ids), 2)
        self.assertListEqual(user_ids, [self.__admin_user_id, user_id2])

        # Check inactive users
        user_ids = UserManagementInterface.read_all_user_ids(
            UserSelection.Inactive)

        self.assertEqual(len(user_ids), 1)
        self.assertListEqual(user_ids, [user_id1])

        # Check all users
        user_ids = UserManagementInterface.read_all_user_ids(UserSelection.All)

        self.assertEqual(len(user_ids), 3)
        self.assertListEqual(user_ids,
                             [self.__admin_user_id, user_id1, user_id2])
    def test_reads_user_by_user_name(self):
        # Create a user and then deactivate it and create a user with the same user name
        user_id1 = self.create_user_test1()
        self.assertIsNotNone(user_id1)

        user1 = UserManagementInterface.read_user_by_id(user_id1)
        self.assertIsNotNone(user1)

        self.assertTrue(UserManagementInterface.deactivate_user(user_id1))

        user_id2 = self.create_user_test1()
        self.assertIsNotNone(user_id2)

        # Positive tests ---------------------------------------------------------------------------
        users = UserManagementInterface.read_users_by_user_name("test1")
        self.assertEqual(len(users), 2)

        user1 = users[0]
        user2 = users[1]

        self.assertEqual(user1["id"], user_id1)
        self.assertEqual(user1["user_name"], "test1")
        self.assertEqual(user1["display_name"], "Test 1")
        self.assertEqual(user1["email"], "*****@*****.**")
        self.assertEqual(user1["active"], False)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test1")
        self.assertEqual(user2["display_name"], "Test 1")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], True)

        # Negative tests ---------------------------------------------------------------------------
        users = UserManagementInterface.read_users_by_user_name("")
        self.assertEqual(len(users), 0)

        users = UserManagementInterface.read_users_by_user_name("test999")
        self.assertEqual(len(users), 0)
    def test_reads_user_by_user_name(self):
        # Create a user and then deactivate it and create a user with the same user name
        user_id1 = self.create_user_test1()
        self.assertIsNotNone(user_id1)

        user1 = UserManagementInterface.read_user_by_id(user_id1)
        self.assertIsNotNone(user1)

        self.assertTrue(UserManagementInterface.deactivate_user(user_id1))

        user_id2 = self.create_user_test1()
        self.assertIsNotNone(user_id2)

        # Positive tests ---------------------------------------------------------------------------
        users = UserManagementInterface.read_users_by_user_name("test1")
        self.assertEqual(len(users), 2)

        user1 = users[0]
        user2 = users[1]

        self.assertEqual(user1["id"], user_id1)
        self.assertEqual(user1["user_name"], "test1")
        self.assertEqual(user1["display_name"], "Test 1")
        self.assertEqual(user1["email"], "*****@*****.**")
        self.assertEqual(user1["active"], False)

        self.assertEqual(user2["id"], user_id2)
        self.assertEqual(user2["user_name"], "test1")
        self.assertEqual(user2["display_name"], "Test 1")
        self.assertEqual(user2["email"], "*****@*****.**")
        self.assertEqual(user2["active"], True)

        # Negative tests ---------------------------------------------------------------------------
        users = UserManagementInterface.read_users_by_user_name("")
        self.assertEqual(len(users), 0)

        users = UserManagementInterface.read_users_by_user_name("test999")
        self.assertEqual(len(users), 0)