assert get_value({'foo': 42}, 'bar', False) is missing assert get_value({'foos': ['a', 'b']}, 'foos', True) == ['a', 'b'] # https://github.com/sloria/webargs/pull/30 assert get_value({'foos': ['a', 'b']}, 'bar', True) is missing def create_bottle_multi_dict(): d = BotMultiDict() d['foos'] = 'a' d['foos'] = 'b' return d multidicts = [ WerkMultiDict([('foos', 'a'), ('foos', 'b')]), create_bottle_multi_dict(), DjMultiDict({'foos': ['a', 'b']}), ] @pytest.mark.parametrize('input_dict', multidicts) def test_get_value_multidict(input_dict): field = fields.List(fields.Str()) assert get_value(input_dict, 'foos', field) == ['a', 'b'] def test_parse_with_load_from(web_request): web_request.json = {'Content-Type': 'application/json'} parser = MockRequestParser() args = {'content_type': fields.Field(load_from='Content-Type')} parsed = parser.parse(args, web_request, locations=('json',)) assert parsed == {'content_type': 'application/json'} # https://github.com/sloria/webargs/issues/118
with pytest.raises(ValueError) as excinfo: parser.parse({}, web_request, validate="notcallable") assert "not a callable or list of callables." in excinfo.value.args[0] def create_bottle_multi_dict(): d = BotMultiDict() d["foos"] = "a" d["foos"] = "b" return d multidicts = [ WerkMultiDict([("foos", "a"), ("foos", "b")]), create_bottle_multi_dict(), DjMultiDict({"foos": ["a", "b"]}), ] @pytest.mark.parametrize("input_dict", multidicts) def test_multidict_proxy(input_dict): class ListSchema(Schema): foos = fields.List(fields.Str()) class StrSchema(Schema): foos = fields.Str() # this MultiDictProxy is aware that "foos" is a list field and will # therefore produce a list with __getitem__ list_wrapped_multidict = MultiDictProxy(input_dict, ListSchema())
assert get_value({'foos': ['a', 'b']}, 'bar', True) is missing def create_bottle_multi_dict(): d = BotMultiDict() d['foos'] = 'a' d['foos'] = 'b' return d multidicts = [ WerkMultiDict([('foos', 'a'), ('foos', 'b')]), create_bottle_multi_dict(), ] if not PY26: multidicts.append(DjMultiDict({'foos': ['a', 'b']})) @pytest.mark.parametrize('input_dict', multidicts) def test_get_value_multidict(input_dict): field = fields.List(fields.Str()) assert get_value(input_dict, 'foos', field) == ['a', 'b'] def test_parse_with_load_from(web_request): web_request.json = {'Content-Type': 'application/json'} parser = MockRequestParser() args = {'content_type': fields.Field(load_from='Content-Type')} parsed = parser.parse(args, web_request, locations=('json', )) assert parsed == {'content_type': 'application/json'}