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