Exemplo n.º 1
0
    async def test_parse_none(self, app):
        async with app.test_request_context('/bubble'):
            parser = RequestParser()
            parser.add_argument('foo')

            args = await parser.parse_args()
            assert args['foo'] is None
Exemplo n.º 2
0
    async def test_parse_lte(self, app):
        async with app.test_request_context('/bubble?foo<=bar'):
            parser = RequestParser()
            parser.add_argument('foo', operators=['<='])

            args = await parser.parse_args()
            assert args['foo'] == 'bar'
Exemplo n.º 3
0
    async def test_parse_foo_operators_ignore(self, app):
        async with app.test_request_context('/bubble'):
            parser = RequestParser()
            parser.add_argument('foo', ignore=True, store_missing=True)

            args = await parser.parse_args()
            assert args['foo'] is None
Exemplo n.º 4
0
    async def test_parse_unicode_app(self, app):
        parser = RequestParser()
        parser.add_argument('foo')

        async with app.test_request_context('/bubble?foo=barß'):
            args = await parser.parse_args()
            assert args['foo'] == 'barß'
Exemplo n.º 5
0
    async def test_split_multiple_cast(self, app):
        async with app.test_request_context('/bubble?foo=1,2,3'):
            parser = RequestParser()
            parser.add_argument('foo', type=int, action='split')

            args = await parser.parse_args()
            assert args['foo'] == [1, 2, 3]
Exemplo n.º 6
0
    async def test_parse_dest(self, app):
        async with app.test_request_context('/bubble?foo=bar'):
            parser = RequestParser()
            parser.add_argument('foo', dest='bat')

            args = await parser.parse_args()
            assert args['bat'] == 'bar'
Exemplo n.º 7
0
    async def test_parse_append_single(self, app):
        async with app.test_request_context('/bubble?foo=bar'):
            parser = RequestParser()
            parser.add_argument('foo', action='append'),

            args = await parser.parse_args()
            assert args['foo'] == ['bar']
Exemplo n.º 8
0
    async def test_split_multiple(self, app):
        async with app.test_request_context('/bubble?foo=bar,bat'):
            parser = RequestParser()
            parser.add_argument('foo', action='split'),

            args = await parser.parse_args()
            assert args['foo'] == ['bar', 'bat']
Exemplo n.º 9
0
    async def test_parse_append_default(self, app):
        async with app.test_request_context('/bubble?'):
            parser = RequestParser()
            parser.add_argument('foo', action='append', store_missing=True),

            args = await parser.parse_args()
            assert args['foo'] is None
Exemplo n.º 10
0
    async def test_json_location(self, app):
        async with app.test_request_context('/bubble', method='POST'):
            parser = RequestParser()
            parser.add_argument('foo', location='json', store_missing=True)

            args = await parser.parse_args()
            assert args['foo'] is None
Exemplo n.º 11
0
    async def test_parse_default(self, app):
        async with app.test_request_context('/bubble'):
            parser = RequestParser()
            parser.add_argument('foo', default='bar', store_missing=True)

            args = await parser.parse_args()
            assert args['foo'] == 'bar'
Exemplo n.º 12
0
    async def test_parse_choices_correct(self, app):
        async with app.test_request_context('/bubble?foo=bat') as ctx:
            req = ctx.request
            parser = RequestParser()
            parser.add_argument('foo', choices=['bat']),

            args = await parser.parse_args(req)
            assert args['foo'] == 'bat'
Exemplo n.º 13
0
 def test_unknown_type(self):
     parser = RequestParser()
     parser.add_argument('unknown', type=lambda v: v)
     assert parser.__schema__ == [{
         'name': 'unknown',
         'type': 'string',
         'in': 'query',
     }]
Exemplo n.º 14
0
 def test_location_files(self):
     parser = RequestParser()
     parser.add_argument('in_files', type=FileStorage, location='files')
     assert parser.__schema__ == [{
         'name': 'in_files',
         'type': 'file',
         'in': 'formData',
     }]
Exemplo n.º 15
0
 def test_location_form(self):
     parser = RequestParser()
     parser.add_argument('in_form', type=int, location='form')
     assert parser.__schema__ == [{
         'name': 'in_form',
         'type': 'integer',
         'in': 'formData',
     }]
Exemplo n.º 16
0
 async def test_strict_parsing_on_partial_hit(self, app):
     async with app.test_request_context(
             '/bubble?foo=1&bar=bees&n=22') as ctx:
         req = ctx.request
         parser = RequestParser()
         parser.add_argument('foo', type=int)
         with pytest.raises(BadRequest):
             await parser.parse_args(req, strict=True)
Exemplo n.º 17
0
 def test_location_json(self):
     parser = RequestParser()
     parser.add_argument('in_json', type=str, location='json')
     assert parser.__schema__ == [{
         'name': 'in_json',
         'type': 'string',
         'in': 'body',
     }]
Exemplo n.º 18
0
    async def test_not_json_location_and_content_type_json(self, app):
        parser = RequestParser()
        parser.add_argument('foo', location='args')

        async with app.test_request_context('/bubble',
                                            method='get',
                                            headers=JSON_HEADERS):
            await parser.parse_args()  # Should not raise a 400: BadRequest
Exemplo n.º 19
0
 async def test_strict_parsing_off_partial_hit(self, app):
     async with app.test_request_context(
             '/bubble?foo=1&bar=bees&n=22') as ctx:
         req = ctx.request
         parser = RequestParser()
         parser.add_argument('foo', type=int)
         args = await parser.parse_args(req)
         assert args['foo'] == 1
Exemplo n.º 20
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'
Exemplo n.º 21
0
    async def test_parse_lte_gte_mock(self, app, mocker):
        async with app.test_request_context('/bubble?foo<=bar'):
            mock_type = mocker.Mock()

            parser = RequestParser()
            parser.add_argument('foo', type=mock_type, operators=['<='])

            await parser.parse_args()
            mock_type.assert_called_with('bar', 'foo', '<=')
Exemplo n.º 22
0
    async def test_request_parse_copy_including_settings(self):
        parser = RequestParser(trim=True,
                               store_missing=False,
                               bundle_errors=True)
        parser_copy = parser.copy()

        assert parser.trim == parser_copy.trim
        assert parser.store_missing == parser_copy.store_missing
        assert parser.bundle_errors == parser_copy.bundle_errors
Exemplo n.º 23
0
    async def test_type_callable(self, app):
        async with app.test_request_context('/bubble?foo=1') as ctx:
            req = ctx.request

            parser = RequestParser()
            parser.add_argument('foo', type=lambda x: x, required=False),

            args = await parser.parse_args(req)
            assert args['foo'] == '1'
Exemplo n.º 24
0
 async def test_none_argument(self, app):
     parser = RequestParser()
     parser.add_argument('foo', location='json')
     async with app.test_request_context('/bubble',
                                         method='post',
                                         data={'foo': None},
                                         headers=JSON_HEADERS):
         args = await parser.parse_args()
     assert args['foo'] is None
Exemplo n.º 25
0
    async def test_parse_choices_sensitive(self, app):
        async with app.test_request_context('/bubble?foo=BAT') as ctx:
            req = ctx.request

            parser = RequestParser()
            parser.add_argument('foo', choices=['bat'], case_sensitive=True),

            with pytest.raises(BadRequest):
                await parser.parse_args(req)
Exemplo n.º 26
0
 def test_default_as_false(self):
     parser = RequestParser()
     parser.add_argument('bool', type=inputs.boolean, default=False)
     assert parser.__schema__ == [{
         'name': 'bool',
         'type': 'boolean',
         'in': 'query',
         'default': False,
     }]
Exemplo n.º 27
0
 def test_required(self):
     parser = RequestParser()
     parser.add_argument('int', type=int, required=True)
     assert parser.__schema__ == [{
         'name': 'int',
         'type': 'integer',
         'in': 'query',
         'required': True,
     }]
Exemplo n.º 28
0
 def test_default(self):
     parser = RequestParser()
     parser.add_argument('int', type=int, default=5)
     assert parser.__schema__ == [{
         'name': 'int',
         'type': 'integer',
         'in': 'query',
         'default': 5,
     }]
Exemplo n.º 29
0
 def test_choices(self):
     parser = RequestParser()
     parser.add_argument('string', type=str, choices=['a', 'b'])
     assert parser.__schema__ == [{
         'name': 'string',
         'type': 'string',
         'in': 'query',
         'enum': ['a', 'b'],
         'collectionFormat': 'multi',
     }]
Exemplo n.º 30
0
    async def test_request_parser_remove_argument(self, app):
        async with app.test_request_context('/bubble?foo=baz') as ctx:
            req = ctx.request
            parser = RequestParser()
            parser.add_argument('foo', type=int)
            parser_copy = parser.copy()
            parser_copy.remove_argument('foo')

            args = await parser_copy.parse_args(req)
            assert args == {}