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
def test_passing_arguments_object(self, app): req = Request.from_values('/bubble?foo=bar') parser = RequestParser() parser.add_argument(Argument('foo')) args = parser.parse_args(req) assert args['foo'] == 'bar'
def test_request_parser_copy(self, app): req = Request.from_values('/bubble?foo=101&bar=baz') parser = RequestParser() foo_arg = Argument('foo', type=int) parser.args.append(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 # Args added to new parser should not be added to the original bar_arg = Argument('bar') parser_copy.args.append(bar_arg) assert bar_arg not in parser.args args = parser_copy.parse_args(req) assert args['foo'] == 101 assert args['bar'] == 'baz'
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 arg.source(req) == MultiDict(req.args) arg = Argument('foo', location=['headers']) assert arg.source(req) == MultiDict(req.headers)
def test_default_operators(self): arg = Argument('foo') assert arg.operators[0] == '=' assert len(arg.operators) == 1
def test_location_url(self): arg = Argument('foo', location='url') assert arg.location == 'url'
def test_source_default_location(self, mocker): req = mocker.Mock(['values']) req._get_child_mock = lambda **kwargs: MultiDict() arg = Argument('foo') assert 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_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_help(self): arg = Argument('foo') assert arg.help is None
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_type(self, mocker): mock_six = mocker.patch('flask_restplus.reqparse.six') arg = Argument('foo') sentinel = object() arg.type(sentinel) mock_six.text_type.assert_called_with(sentinel)
def test_default_default(self): arg = Argument('foo') assert arg.default is None
def test_required(self): arg = Argument('foo', required=True) assert arg.required is True
def test_ignore_default(self): arg = Argument('foo') assert arg.ignore is False
def test_ignore(self): arg = Argument('foo', ignore=True) assert arg.ignore is True
def test_choices_default(self): arg = Argument('foo') assert len(arg.choices) == 0
def test_operator(self): arg = Argument('foo', operators=['>=', '<=', '=']) assert arg.operators == ['>=', '<=', '=']
def test_convert_default_type_with_null_input(self): arg = Argument('foo') assert arg.convert(None, None) is None
def test_action_filter(self): arg = Argument('foo', action='filter') assert arg.action == 'filter'
def test_source_bad_location(self, mocker): req = mocker.Mock(['values']) arg = Argument('foo', location=['foo']) assert len(arg.source(req)) == 0 # yes, basically you don't find it
def test_choices(self): arg = Argument('foo', choices=[1, 2]) assert arg.choices == [1, 2]
def test_action(self): arg = Argument('foo', action='append') assert arg.action == 'append'
def test_dest(self): arg = Argument('foo', dest='foobar') assert arg.dest == 'foobar'