Skip to content

Commit

Permalink
Remove 'source' param
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Apr 5, 2015
1 parent 4615e5a commit 03a4c51
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Features:
* Store argument name on ``RequiredArgMissingError``. Thanks :user:`stas`.
* Allow error messages for required validation to be overriden. Thanks again :user:`stas`.

Removals:

* Remove ``source`` parameter from ``Arg``.


0.12.0 (2015-03-22)
*******************
Expand Down
34 changes: 0 additions & 34 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,6 @@ def test_parse_json_called_by_parse_arg(parse_json, web_request):
p.parse_arg('foo', arg, web_request)
parse_json.assert_called_with(web_request, 'foo', arg)

@mock.patch('webargs.core.Parser.parse_json')
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)

@mock.patch('webargs.core.Parser.parse_querystring')
def test_parse_querystring_called_by_parse_arg(parse_querystring, web_request):
arg = Arg()
Expand Down Expand Up @@ -501,27 +494,12 @@ def parse_data(req, name, arg):
result = parser.parse({'foo': Arg(int)}, web_request, locations=('data', ))
assert result['foo'] == 42

def test_custom_location_handler_with_source(web_request):
web_request.data = {'X-Foo': 42}
parser = Parser()

@parser.location_handler('data')
def parse_data(req, name, arg):
# The source name is passed
assert name == 'X-Foo'
return req.data.get(name)

result = parser.parse({'x_foo': Arg(int, source='X-Foo')},
web_request, locations=('data', ))
assert result['x_foo'] == 42

def test_custom_location_handler_with_dest(web_request):
web_request.data = {'X-Foo': 42}
parser = Parser()

@parser.location_handler('data')
def parse_data(req, name, arg):
# The source name is passed
assert name == 'X-Foo'
return req.data.get(name)

Expand Down Expand Up @@ -633,18 +611,6 @@ def create_bottle_multi_dict():
def test_get_value_multidict(input_dict):
assert get_value(input_dict, 'foos', multiple=True) == ['a', 'b']

def test_parse_with_source(web_request):
web_request.json = {'foo': 41, 'bar': 42}

parser = MockRequestParser()
args = {'foo': Arg(int), 'baz': Arg(int, source='bar')}
parsed = parser.parse(args, web_request, locations=('json',))
assert parsed == {'foo': 41, 'baz': 42}

def test_source_param_is_deprecated(recwarn):
Arg(source='foo')
pytest.deprecated_call(lambda: Arg(source='foo'))

def test_parse_with_dest(web_request):
web_request.json = {'Content-Type': 'application/json'}

Expand Down
11 changes: 2 additions & 9 deletions webargs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Arg(object):
"""
def __init__(self, type_=None, default=None, required=False,
validate=None, use=None, multiple=False, error=None,
allow_missing=False, location=None, dest=None, source=None, **metadata):
allow_missing=False, location=None, dest=None, **metadata):
if isinstance(type_, dict):
self.type = type(type_) # type will always be a dict
self._nested_args = type_
Expand All @@ -215,13 +215,6 @@ def __init__(self, type_=None, default=None, required=False,
self.allow_missing = allow_missing
self.location = location
self.dest = dest
if source:
warnings.warn(
"The 'source' parameter is deprecated. Use the 'dest' parameter "
"to specify the key to be added in the output dictionary.",
category=DeprecationWarning
)
self.source = source # TODO: Remove me.
self.metadata = metadata

def __repr__(self):
Expand Down Expand Up @@ -340,7 +333,7 @@ def _get_value(self, name, argobj, req, location):
function = func
else:
function = getattr(self, func)
value = function(req, argobj.source or name, argobj)
value = function(req, name, argobj)
else:
value = None
return value
Expand Down

0 comments on commit 03a4c51

Please sign in to comment.