コード例 #1
0
 def test_required_translation(self):
     arg = Arg(int, required=True)
     arg.location = 'json'
     result = arg2parameter(arg)
     assert result['required'] is True
     arg2 = Arg(int, location='json')
     result2 = arg2parameter(arg2)
     assert result2['required'] is False
コード例 #2
0
    def test_arg2swagger_puts_json_arguments_in_schema(self):
        arg = Arg(int, location='json', description='a count', format='int32')
        res = arg2parameter(arg, 'username')
        assert res['name'] == 'body'
        assert 'description' not in res
        schema_props = res['schema']['properties']

        # property is defined on schema
        assert schema_props['username']['type'] == 'integer'
        assert schema_props['username']['description'] == arg.metadata[
            'description']
        assert schema_props['username']['format'] == 'int32'
コード例 #3
0
 def test_schema_if_json_body(self):
     arg = Arg(int, location='json')
     res = arg2parameter(arg)
     assert 'schema' in res
コード例 #4
0
 def test_arg_with_name(self):
     arg = Arg(int, location='form', name='foo')
     res = arg2parameter(arg)
     assert res['name'] == 'foo'
コード例 #5
0
 def test_arg_name_is_body_if_location_is_json(self):
     arg = Arg(int, location='json')
     result = arg2parameter(arg)
     assert result['name'] == 'body'
コード例 #6
0
 def test_arg_with_default(self):
     arg = Arg(int, location='form', default=42)
     result = arg2parameter(arg)
     assert result['default'] == 42
コード例 #7
0
 def test_arg_with_format(self):
     arg = Arg(int, location='form', format='int32')
     result = arg2parameter(arg)
     assert result['format'] == 'int32'
コード例 #8
0
 def test_arg_with_description(self):
     arg = Arg(int, location='form', description='a webargs arg')
     result = arg2parameter(arg)
     assert result['description'] == arg.metadata['description']
コード例 #9
0
 def test_items_multiple_querystring(self):
     arg = Arg(int, multiple=True, location='querystring')
     result = arg2parameter(arg)
     assert result['items'] == {'type': 'integer', 'format': 'int32'}
コード例 #10
0
 def test_collection_translation_single(self):
     arg = Arg(int, location='querystring')
     result = arg2parameter(arg)
     assert 'collectionFormat' not in result
コード例 #11
0
 def test_collection_translation_multiple(self):
     arg = Arg(int, multiple=True, location='querystring')
     result = arg2parameter(arg)
     assert result['type'] == 'array'
     assert result['collectionFormat'] == 'multi'
コード例 #12
0
 def test_location_defaults_to_json_body(self):
     # No location specified
     arg = Arg(int)
     result = arg2parameter(arg)
     assert result['in'] == 'body'
コード例 #13
0
 def test_location_translation(self, webargs_location, swagger_location):
     arg = Arg(int, location=webargs_location)
     result = arg2parameter(arg)
     assert result['in'] == swagger_location
コード例 #14
0
 def test_type_translation(self, pytype, jsontype):
     arg = Arg(pytype, location='form')
     result = arg2parameter(arg)
     assert result['type'] == jsontype
コード例 #15
0
 def test_no_schema_if_form_body(self):
     arg = Arg(int, location='form')
     res = arg2parameter(arg)
     assert 'schema' not in res
コード例 #16
0
        'get': {
            'responses': {
                200: {
                    'schema': swagger.schema2jsonschema(PetSchema),
                    'description': 'A pet',
                },
            },
            'parameters': [
                {
                    'name': 'q',
                    'in': 'query',
                    'type': 'string'
                },
                {
                    'name': 'category_id',
                    'in': 'path',
                    'type': 'string'
                },
                arg2parameter(Arg(str, multiple=True, location='querystring')),
            ],
        },
    },
)


def test_swagger_tools_validate():
    try:
        utils.validate_swagger(spec)
    except exceptions.SwaggerError as error:
        pytest.fail(str(error))