def test_parse_headers_called_when_headers_is_a_location(parse_headers, web_request): field = fields.Field() p = Parser() p.parse_arg("foo", field, web_request) assert parse_headers.call_count == 0 p.parse_arg("foo", field, web_request, locations=("headers",)) parse_headers.assert_called()
def test_parse_cookies_called_when_cookies_is_a_location(parse_cookies, web_request): arg = Arg() p = Parser() p.parse_arg('foo', arg, web_request) assert parse_cookies.call_count == 0 p.parse_arg('foo', arg, web_request, locations=('cookies',)) parse_cookies.assert_called
def test_parse_cookies_called_when_cookies_is_a_location(parse_cookies, web_request): field = fields.Field() p = Parser() p.parse_arg('foo', field, web_request) assert parse_cookies.call_count == 0 p.parse_arg('foo', field, web_request, locations=('cookies',)) parse_cookies.assert_called()
def test_value_error_raised_if_invalid_target(request): arg = Arg() p = Parser() with pytest.raises(ValueError) as excinfo: p.parse_arg('foo', arg, request, targets=('invalidtarget', 'headers')) assert 'Invalid targets arguments: {0}'.format(['invalidtarget' ]) in str(excinfo)
def test_parse_required_arg_raises_validation_error(parse_json, request): arg = Arg(required=True) p = Parser() parse_json.return_value = Missing with pytest.raises(ValidationError) as excinfo: p.parse_arg('foo', arg, request) assert 'Required parameter ' + repr('foo') + ' not found.' in str(excinfo)
def test_parse_required_arg_raises_validation_error(parse_json, web_request): arg = Arg(required=True) p = Parser() parse_json.return_value = Missing with pytest.raises(ValidationError) as excinfo: p.parse_arg('foo', arg, web_request) assert 'Required parameter "foo" not found.' in str(excinfo)
def test_parse_cookies_called_when_cookies_is_a_target(parse_cookies, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) assert parse_cookies.call_count == 0 p.parse_arg('foo', arg, request, targets=('cookies',)) assert parse_cookies.called
def test_parse_cookies_called_when_cookies_is_a_target(parse_cookies, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) assert parse_cookies.call_count == 0 p.parse_arg('foo', arg, request, targets=('cookies', )) assert parse_cookies.called
def test_value_error_raised_if_parse_arg_called_with_invalid_location(web_request): field = fields.Field() p = Parser() with pytest.raises(ValueError) as excinfo: p.parse_arg("foo", field, web_request, locations=("invalidlocation", "headers")) assert "Invalid locations arguments: {0}".format(["invalidlocation"]) in str( excinfo )
def test_parse_headers_called_when_headers_is_a_target(parse_headers, web_request): arg = Arg() p = Parser() p.parse_arg('foo', arg, web_request) assert parse_headers.call_count == 0 p.parse_arg('foo', arg, web_request, targets=('headers', )) parse_headers.assert_called
def test_parse_required_multiple_arg(parse_form, web_request): parse_form.return_value = [] arg = Arg(multiple=True, required=True) p = Parser() with pytest.raises(RequiredArgMissingError): p.parse_arg('foo', arg, web_request) parse_form.return_value = None with pytest.raises(RequiredArgMissingError): p.parse_arg('foo', arg, web_request)
def test_value_error_raised_if_invalid_location(web_request): arg = Arg() p = Parser() with pytest.raises(ValueError) as excinfo: p.parse_arg('foo', arg, web_request, locations=('invalidlocation', 'headers')) assert 'Invalid locations arguments: {0}'.format(['invalidlocation' ]) in str(excinfo)
def test_parse_required_multiple_arg(parse_form, request): parse_form.return_value = [] arg = Arg(multiple=True, required=True) p = Parser() with pytest.raises(ValidationError): p.parse_arg('foo', arg, request) parse_form.return_value = None with pytest.raises(ValidationError): p.parse_arg('foo', arg, request)
def test_parse_json_not_called_when_json_not_a_location(parse_json, web_request): field = fields.Field() p = Parser() p.parse_arg('foo', field, web_request, locations=('form', 'querystring')) assert parse_json.call_count == 0
def test_parse_form_called_by_parse_arg(parse_form, web_request): field = fields.Field() p = Parser() p.parse_arg('foo', field, web_request) assert parse_form.called_once()
def test_parse_querystring_called_by_parse_arg(parse_querystring, web_request): field = fields.Field() p = Parser() p.parse_arg('foo', field, web_request) assert parse_querystring.called_once()
def test_parse_required_arg_raises_validation_error(request): arg = Arg(required=True) p = Parser() with pytest.raises(ValidationError) as excinfo: p.parse_arg('foo', arg, request) assert 'Required parameter ' + repr('foo') + ' not found.' in str(excinfo)
def test_fallback_used_if_all_other_functions_return_none(fallback, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) assert fallback.called
def test_parse_json_not_called_when_json_not_a_target(parse_json, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request, targets=('form', 'querystring')) assert parse_json.call_count == 0
def test_parse_json_called_by_parse_arg(parse_json, web_request): arg = Arg() p = Parser() p.parse_arg('foo', arg, web_request) parse_json.assert_called_with(web_request, 'foo', arg)
def test_parse_json_called_by_parse_arg(parse_json, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) assert parse_json.called
def test_parse_form_called_by_parse_arg(parse_form, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) assert parse_form.called
def test_parse_required_arg(parse_json, request): arg = Arg(required=True) parse_json.return_value = 42 p = Parser() result = p.parse_arg('foo', arg, request, targets=('json', )) assert result == 42
def test_parse_json_called_with_source(parse_json, request): arg = Arg(source='bar') p = Parser() p.parse_arg('foo', arg, request) parse_json.assert_called_with(request, 'bar', arg)
def test_parse_querystring_called_by_parse_arg(parse_querystring, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) assert parse_querystring.called
def test_parse_json_called_with_source(parse_json, web_request): arg = Arg(source='bar') p = Parser() p.parse_arg('foo', arg, web_request) parse_json.assert_called_with(web_request, 'bar', arg)
def test_parse_required_arg(parse_json, web_request): arg = fields.Field(required=True) parse_json.return_value = 42 p = Parser() result = p.parse_arg('foo', arg, web_request, locations=('json', )) assert result == 42
def test_parse_json_called_by_parse_arg(parse_json, web_request): field = fields.Field() p = Parser() p.parse_arg('foo', field, web_request) parse_json.assert_called_with(web_request, 'foo', field)
def test_value_error_raised_if_invalid_target(request): arg = Arg() p = Parser() with pytest.raises(ValueError) as excinfo: p.parse_arg('foo', arg, request, targets=('invalidtarget', 'headers')) assert 'Invalid targets arguments: {0}'.format(['invalidtarget']) in str(excinfo)
def test_parse_json_called_by_parse_arg(parse_json, request): arg = Arg() p = Parser() p.parse_arg('foo', arg, request) parse_json.assert_called_with(request, 'foo', arg)