Пример #1
0
 def test_exceptions_without_error_codes_are_equal_only_if_messages_are_equal(
         self):
     exc1 = exceptions.LogicException('Test')
     exc2 = exceptions.LogicException('Test')
     exc3 = exceptions.LogicException('Not Test')
     self.assertEqual(exc1, exc2)
     self.assertNotEqual(exc1, exc3)
Пример #2
0
 def test_validator_raises_exception(self):
     self.mock_validator.side_effect = exceptions.LogicException()
     self.assertRaises(exceptions.LogicException,
                       lambda: self.decorated_validator())
     self.assertRaises(
         exceptions.LogicException,
         lambda: self.decorated_validator(raise_exception=True))
Пример #3
0
 def test_permission_result_delegates_errors_and_error_code(self):
     exception = exceptions.LogicException("test",
                                           error_code="CODE",
                                           errors=object())
     result = core.ValidationResult(success=False, error=exception)
     self.assertEqual(result.error_code, exception.error_code)
     self.assertEqual(result.errors, exception.errors)
Пример #4
0
class TestErrors(errors.LogicErrors):
    INVALID_ACTION = exceptions.InvalidOperationException(
        "This action is permitted by business logic")
    NO_PERMISSION = exceptions.NotPermittedException(
        "This action is permitted because not sufficient permissions")
    generic_error = exceptions.LogicException(
        "This action is permitted just because :)")
Пример #5
0
 def test_returned_failure_contains_exception(self):
     self.mock_validator.side_effect = exceptions.LogicException()
     result = self.decorated_validator(raise_exception=False)
     self.assertFalse(result)
     self.assertFalse(result.success)
     self.assertIsInstance(result.error, exceptions.LogicException)
     # it should be none because exception is not created using ServiceErrors
     self.assertIsNone(result.errors)
     self.assertIsNone(result.error_code)
Пример #6
0
 def test_formatting_returns_copy_with_formatted_message(self):
     parametrizable = exceptions.LogicException(
         message='{user} has been {behaviour}!',
         error_code='BEHAVIOUR',
         errors={'BEHAVIOUR': 'test'})
     formatted = parametrizable.format(user='******', behaviour='naughty')
     self.assertEqual(str(formatted), 'Marian has been naughty!')
     self.assertIs(type(parametrizable), type(formatted))
     self.assertEqual(parametrizable.errors, formatted.errors)
     self.assertEqual(parametrizable.error_code, formatted.error_code)
     self.assertEqual(parametrizable, formatted)
     self.assertIsNot(parametrizable, formatted)
Пример #7
0
 def test_validator_returns_false_permission_when_exception_raised_and_caught(self):
     self.mock_validator.side_effect = exceptions.LogicException()
     failure1 = self.decorated_validator(raise_exception=False)
     self.assertIsInstance(failure1, core.ValidationResult)
     self.assertFalse(failure1)
Пример #8
0
 def test_unicode_is_handled_properly(self):
     unicode_text = u'Zażółć gęślą jaźń'
     result = core.ValidationResult(success=False, error=exceptions.LogicException(unicode_text))
     self.assertEqual(u'{}'.format(result), unicode_text)
Пример #9
0
 def test_exception_from_validator_is_raised(self):
     self.mock_validator.side_effect = exceptions.LogicException("Fail!")
     self.assertRaises(exceptions.LogicException, self.mock_validator)
Пример #10
0
 def test_parametrizable_exceptions_should_be_parametrized(self):
     self.mock_validator.side_effect = exceptions.LogicException(
         "I'm {parametrizable}!")
     with self.assertRaises(AssertionError) as cm:
         self.decorated_validator()
     self.assertIn('parametrizable', str(cm.exception))
Пример #11
0
 def test_formatting_message_with_invalid_parameters_raises_error(self):
     exc = exceptions.LogicException('Test {person}?')
     with self.assertRaises(KeyError):
         exc.format(pearson='me')
Пример #12
0
 def test_exceptions_with_same_error_codes_are_equal(self):
     exc1 = exceptions.LogicException('Test', error_code='TEST')
     exc2 = exceptions.LogicException('Test', error_code='TEST')
     self.assertEqual(exc1, exc2)
Пример #13
0
 def test_exception_is_hashable(self):
     exc = exceptions.LogicException('Test')
     self.assertIsInstance(hash(exc), int)
Пример #14
0
 def test_exception_repr_is_working_correctly(self):
     exc = exceptions.LogicException('Test', error_code='TEST')
     self.assertEqual(repr(exc),
                      "LogicException('Test', error_code='TEST')")