def test_bitwise_and_failure(self): """ Test the bitwise and method with an invalid permission.. Expected result: The method raises an error. """ with self.assertRaises(ValueError) as exception_cm: # noinspection PyTypeChecker Permission.bitwise_and(Permission.EditGlobalSettings, None, Permission.EditRole) self.assertEqual('None is not a valid permission', str(exception_cm.exception))
def test_bitwise_and_success(self): """ Test the bitwise and method. Expected result: The method returns the same result as performing the operation manually. """ expectation = Permission.EditRole result = Permission.bitwise_and(Permission.EditRole) self.assertEqual(expectation, result) combination = Permission.EditRole | Permission.EditGlobalSettings expectation = combination & Permission.EditUser result = Permission.bitwise_and(combination, Permission.EditUser) self.assertEqual(expectation, result) combination_1 = Permission.EditGlobalSettings | Permission.EditRole | Permission.EditUser combination_2 = Permission.EditGlobalSettings | Permission.EditRole combination_3 = Permission.EditGlobalSettings | Permission.EditUser expectation = combination_1 & combination_2 & combination_3 result = Permission.bitwise_and(combination_1, combination_2, combination_3) self.assertEqual(expectation, result)