def test_raises_field_errors_on_match(invalid_event_id_field_error): errors = [invalid_event_id_field_error] with raises_field_errors({'event_id': 'INVALID'}) as exc_info: raise Client.CallActionError( actions=[ActionResponse(action='', errors=errors)]) assert exc_info.soa_errors == errors
def test_raises_field_errors_missing(code, field): errors = [ Error(code=code, message='test fail', field=field), ] with pytest.raises(pytest.raises.Exception): with raises_field_errors({'event_id': 'UNKNOWN'}): raise Client.CallActionError( actions=[ActionResponse(action='', errors=errors)])
def test_raises_field_errors_match_multiple(codes): errors = [Error(code=code, field=field, message='bam') for field, code in codes] with raises_field_errors({'event_id': 'UNKNOWN', 'organization_id': 'INVALID'}) as exc_info: raise Client.CallActionError( actions=[ActionResponse(action='', errors=errors)] ) assert exc_info.soa_errors == errors
def assertActionRunsWithFieldErrors(self, action, body, field_errors, only=False, **kwargs): with raises_field_errors(field_errors, only=only): self.call_action(action, body, **kwargs)
def test_raises_field_errors_unexpected_only(invalid_event_id_field_error, unknown_event_id_field_error): errors = [ invalid_event_id_field_error, unknown_event_id_field_error, ] with pytest.raises(pytest.raises.Exception): with raises_field_errors({'event_id': ['UNKNOWN']}, only=True): raise Client.CallActionError( actions=[ActionResponse(action='', errors=errors)])
def assertActionRunsWithFieldErrors( self, action, # type: six.text_type body, # type: Body field_errors, # type: Dict[six.text_type, Union[Iterable[six.text_type], six.text_type]] only=False, # type: bool **kwargs # type: Any ): # type: (...) -> None """ Calls `self.call_action` and asserts that it runs with the specified field errors. :param action: The name of the action to call :param body: The request body to send to the action :param field_errors: A dictionary of field name keys to error codes or iterables of error codes for the fields (all of the specified errors must be present in the response). :param only: If `True` additional errors cause a failure (defaults to `False`, so additional errors are ignored). :param kwargs: Additional keyword arguments to send to :meth:`pysoa.client.client.Client.call_action`. """ with raises_field_errors(field_errors, only=only): self.call_action(action, body, **kwargs)
def test_raises_field_errors_no_error(): with pytest.raises(pytest.raises.Exception): with raises_field_errors({'organization_id': 'UNKNOWN'}): pass