async def test_source(self, mocker): req = mocker.Mock(['args', 'headers', 'values']) req.args = {'foo': 'bar'} req.headers = {'baz': 'bat'} arg = Argument('foo', location=['args']) assert (await arg.source(req)) == MultiDict(req.args) arg = Argument('foo', location=['headers']) assert (await arg.source(req)) == MultiDict(req.headers)
def test_option_case_sensitive(self): arg = Argument('foo', choices=['bar', 'baz'], case_sensitive=True) assert arg.case_sensitive is True # Insensitive arg = Argument('foo', choices=['bar', 'baz'], case_sensitive=False) assert arg.case_sensitive is False # Default arg = Argument('foo', choices=['bar', 'baz']) assert arg.case_sensitive is True
async def test_passing_arguments_object(self, app): async with app.test_request_context('/bubble?foo=bar') as ctx: req = ctx.request parser = RequestParser() parser.add_argument(Argument('foo')) args = await parser.parse_args(req) assert args['foo'] == 'bar'
async def test_request_parser_copy(self, app): async with app.test_request_context('/bubble?foo=101&bar=baz') as ctx: req = ctx.request parser = RequestParser() foo_arg = Argument('foo', type=int) parser.args[foo_arg.name] = foo_arg parser_copy = parser.copy() # Deepcopy should create a clone of the argument object instead of # copying a reference to the new args list assert foo_arg not in parser_copy.args.values() # Args added to new parser should not be added to the original bar_arg = Argument('bar') parser_copy.args[bar_arg.name] = bar_arg assert bar_arg not in parser.args.values() args = await parser_copy.parse_args(req) assert args['foo'] == 101 assert args['bar'] == 'baz'
def test_choices(self): arg = Argument('foo', choices=[1, 2]) assert arg.choices == [1, 2]
def test_location_url(self): arg = Argument('foo', location='url') assert arg.location == 'url'
async def test_source_default_location(self, mocker): req = mocker.Mock(['values']) req._get_child_mock = lambda **kwargs: MultiDict() arg = Argument('foo') assert (await arg.source(req)) == req.values
def test_convert_with_null_input_when_not_nullable(self): arg = Argument('foo', nullable=False) pytest.raises(ValueError, lambda: arg.convert(None, None))
def test_name(self): arg = Argument('foo') assert arg.name == 'foo'
def test_action_default(self): arg = Argument('foo') assert arg.action == 'store'
def test_required_default(self): arg = Argument('foo') assert arg.required is False
def test_default(self): arg = Argument('foo', default=True) assert arg.default is True
def test_type(self): arg = Argument('foo', type=int) assert arg.type == int
def test_location_header_list(self): arg = Argument('foo', location=['headers']) assert arg.location == ['headers']
def test_location_get_json(self): arg = Argument('foo', location='get_json') assert arg.location == 'get_json'
def test_location_header(self): arg = Argument('foo', location='headers') assert arg.location == 'headers'
def test_location_url_list(self): arg = Argument('foo', location=['url']) assert arg.location == ['url']
def test_default_operators(self): arg = Argument('foo') assert arg.operators[0] == '=' assert len(arg.operators) == 1
def test_default_default(self): arg = Argument('foo') assert arg.default is None
def test_default_help(self): arg = Argument('foo') assert arg.help is None
def test_ignore_default(self): arg = Argument('foo') assert arg.ignore is False
def test_required(self): arg = Argument('foo', required=True) assert arg.required is True
def test_choices_default(self): arg = Argument('foo') assert len(arg.choices) == 0
def test_ignore(self): arg = Argument('foo', ignore=True) assert arg.ignore is True
def test_convert_default_type_with_null_input(self): arg = Argument('foo') assert arg.convert(None, None) is None
def test_operator(self): arg = Argument('foo', operators=['>=', '<=', '=']) assert arg.operators == ['>=', '<=', '=']
async def test_source_bad_location(self, mocker): req = mocker.Mock(['values']) arg = Argument('foo', location=['foo']) assert len(await arg.source(req)) == 0 # yes, basically you don't find it
def test_action(self): arg = Argument('foo', action='append') assert arg.action == 'append'
def test_action_filter(self): arg = Argument('foo', action='filter') assert arg.action == 'filter'
def test_dest(self): arg = Argument('foo', dest='foobar') assert arg.dest == 'foobar'