def test_conflict_error(self): base = BaseController() base.conflict = MagicMock('aaa') base.handle_business_errors(ConflictError('conflict')) base.conflict.assert_called_with()
def test_not_found_error(self): base = BaseController() base.not_found = MagicMock('aaa') base.handle_business_errors(ResourceNotFoundError()) base.not_found.assert_called_with()
def test_forbidden_error(self): base = BaseController() base.forbidden = MagicMock('aaa') base.handle_business_errors(PermissionDeniedError()) base.forbidden.assert_called_with()
def test_internal_error(self): base = BaseController() base.internal_server_error = MagicMock('aaa') exception = InternalError() base.handle_business_errors(exception) base.internal_server_error.assert_called_with(exception=exception)
def test_invalid_data(self): base = BaseController() base.bad_request = MagicMock('aaa') error = {'field': 'invalid'} base.handle_business_errors(ValidationError(error)) base.bad_request.assert_called_with({'field': 'invalid'})
def test_other_exceptions_error(self): base = BaseController() with pytest.raises(ValueError): base.handle_business_errors(ValueError())