Exemple #1
0
    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
Exemple #2
0
    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'
Exemple #3
0
    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'
Exemple #4
0
    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)
Exemple #5
0
 def test_default_operators(self):
     arg = Argument('foo')
     assert arg.operators[0] == '='
     assert len(arg.operators) == 1
Exemple #6
0
 def test_location_url(self):
     arg = Argument('foo', location='url')
     assert arg.location == 'url'
Exemple #7
0
 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
Exemple #8
0
 def test_convert_with_null_input_when_not_nullable(self):
     arg = Argument('foo', nullable=False)
     pytest.raises(ValueError, lambda: arg.convert(None, None))
Exemple #9
0
 def test_action_default(self):
     arg = Argument('foo')
     assert arg.action == 'store'
Exemple #10
0
 def test_required_default(self):
     arg = Argument('foo')
     assert arg.required is False
Exemple #11
0
 def test_default_help(self):
     arg = Argument('foo')
     assert arg.help is None
Exemple #12
0
 def test_default(self):
     arg = Argument('foo', default=True)
     assert arg.default is True
Exemple #13
0
 def test_type(self):
     arg = Argument('foo', type=int)
     assert arg.type == int
Exemple #14
0
 def test_location_header_list(self):
     arg = Argument('foo', location=['headers'])
     assert arg.location == ['headers']
Exemple #15
0
 def test_location_get_json(self):
     arg = Argument('foo', location='get_json')
     assert arg.location == 'get_json'
Exemple #16
0
 def test_location_header(self):
     arg = Argument('foo', location='headers')
     assert arg.location == 'headers'
Exemple #17
0
 def test_location_url_list(self):
     arg = Argument('foo', location=['url'])
     assert arg.location == ['url']
Exemple #18
0
 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)
Exemple #19
0
 def test_default_default(self):
     arg = Argument('foo')
     assert arg.default is None
Exemple #20
0
 def test_required(self):
     arg = Argument('foo', required=True)
     assert arg.required is True
Exemple #21
0
 def test_ignore_default(self):
     arg = Argument('foo')
     assert arg.ignore is False
Exemple #22
0
 def test_ignore(self):
     arg = Argument('foo', ignore=True)
     assert arg.ignore is True
Exemple #23
0
 def test_choices_default(self):
     arg = Argument('foo')
     assert len(arg.choices) == 0
Exemple #24
0
 def test_operator(self):
     arg = Argument('foo', operators=['>=', '<=', '='])
     assert arg.operators == ['>=', '<=', '=']
Exemple #25
0
 def test_convert_default_type_with_null_input(self):
     arg = Argument('foo')
     assert arg.convert(None, None) is None
Exemple #26
0
 def test_action_filter(self):
     arg = Argument('foo', action='filter')
     assert arg.action == 'filter'
Exemple #27
0
 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
Exemple #28
0
 def test_choices(self):
     arg = Argument('foo', choices=[1, 2])
     assert arg.choices == [1, 2]
Exemple #29
0
 def test_action(self):
     arg = Argument('foo', action='append')
     assert arg.action == 'append'
Exemple #30
0
 def test_dest(self):
     arg = Argument('foo', dest='foobar')
     assert arg.dest == 'foobar'