示例#1
0
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()
示例#2
0
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
示例#3
0
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()
示例#4
0
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)
示例#5
0
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)
示例#6
0
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)
示例#7
0
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
示例#8
0
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
示例#9
0
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
    )
示例#10
0
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
示例#11
0
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)
示例#12
0
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)
示例#13
0
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)
示例#14
0
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)
示例#15
0
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
示例#16
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()
示例#17
0
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()
示例#18
0
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)
示例#19
0
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
示例#20
0
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
示例#21
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)
示例#22
0
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
示例#23
0
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
示例#24
0
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
示例#25
0
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
示例#26
0
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
示例#27
0
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)
示例#28
0
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
示例#29
0
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
示例#30
0
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)
示例#31
0
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
示例#32
0
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
示例#33
0
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)
示例#34
0
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)
示例#35
0
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
示例#36
0
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
示例#37
0
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)