Exemple #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()
Exemple #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
Exemple #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()
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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
Exemple #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
    )
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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()
Exemple #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()
Exemple #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)
Exemple #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
Exemple #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
Exemple #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)
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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)
Exemple #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
Exemple #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
Exemple #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)
Exemple #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
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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
Exemple #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)