示例#1
0
    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)
示例#2
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
示例#3
0
    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'
示例#4
0
    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'
示例#5
0
 def test_choices(self):
     arg = Argument('foo', choices=[1, 2])
     assert arg.choices == [1, 2]
示例#6
0
 def test_location_url(self):
     arg = Argument('foo', location='url')
     assert arg.location == 'url'
示例#7
0
 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
示例#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_name(self):
     arg = Argument('foo')
     assert arg.name == 'foo'
示例#10
0
 def test_action_default(self):
     arg = Argument('foo')
     assert arg.action == 'store'
示例#11
0
 def test_required_default(self):
     arg = Argument('foo')
     assert arg.required is False
示例#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_operators(self):
     arg = Argument('foo')
     assert arg.operators[0] == '='
     assert len(arg.operators) == 1
示例#19
0
 def test_default_default(self):
     arg = Argument('foo')
     assert arg.default is None
示例#20
0
 def test_default_help(self):
     arg = Argument('foo')
     assert arg.help is None
示例#21
0
 def test_ignore_default(self):
     arg = Argument('foo')
     assert arg.ignore is False
示例#22
0
 def test_required(self):
     arg = Argument('foo', required=True)
     assert arg.required is True
示例#23
0
 def test_choices_default(self):
     arg = Argument('foo')
     assert len(arg.choices) == 0
示例#24
0
 def test_ignore(self):
     arg = Argument('foo', ignore=True)
     assert arg.ignore is True
示例#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_operator(self):
     arg = Argument('foo', operators=['>=', '<=', '='])
     assert arg.operators == ['>=', '<=', '=']
示例#27
0
 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
示例#28
0
 def test_action(self):
     arg = Argument('foo', action='append')
     assert arg.action == 'append'
示例#29
0
 def test_action_filter(self):
     arg = Argument('foo', action='filter')
     assert arg.action == 'filter'
示例#30
0
 def test_dest(self):
     arg = Argument('foo', dest='foobar')
     assert arg.dest == 'foobar'