Esempio n. 1
0
    async def test_parse_required(self, app):
        async with app.test_request_context('/bubble'):
            parser = RequestParser()
            parser.add_argument('foo', required=True, location='values')

            expected = {
                'foo':
                'Missing required parameter in the post body or the query string'
            }
            with pytest.raises(BadRequest) as cm:
                await parser.parse_args()

            assert cm.value.data[
                'message'] == 'Input payload validation failed'
            assert cm.value.data['errors'] == expected

            parser = RequestParser()
            parser.add_argument('bar',
                                required=True,
                                location=['values', 'cookies'])

            expected = {
                'bar':
                ("Missing required parameter in the post body or the query "
                 "string or the request's cookies")
            }

            with pytest.raises(BadRequest) as cm:
                await parser.parse_args()
            assert cm.value.data[
                'message'] == 'Input payload validation failed'
            assert cm.value.data['errors'] == expected
Esempio n. 2
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
Esempio n. 3
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'
Esempio n. 4
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'
Esempio n. 5
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
Esempio n. 6
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']
Esempio n. 7
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]
Esempio n. 8
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
Esempio n. 9
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']
Esempio n. 10
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ß'
Esempio 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'
Esempio n. 12
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
Esempio n. 13
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',
     }]
Esempio n. 14
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',
     }]
Esempio n. 15
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',
     }]
Esempio n. 16
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',
     }]
Esempio n. 17
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
Esempio n. 18
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)
Esempio n. 19
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'
Esempio n. 20
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
Esempio n. 21
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'
Esempio n. 22
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,
     }]
Esempio n. 23
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,
     }]
Esempio n. 24
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,
     }]
Esempio n. 25
0
    def test_form_and_body_location(self):
        parser = RequestParser()
        parser.add_argument('default', type=int)
        parser.add_argument('in_form', type=int, location='form')
        parser.add_argument('in_json', type=str, location='json')
        with pytest.raises(SpecsError) as cm:
            _ = parser.__schema__

        assert cm.value.msg == "Can't use formData and body at the same time"
Esempio n. 26
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'
Esempio n. 27
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
Esempio n. 28
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)
Esempio n. 29
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', '<=')
Esempio n. 30
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',
     }]