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
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'
def test_schema_if_json_body(self): arg = Arg(int, location='json') res = arg2parameter(arg) assert 'schema' in res
def test_arg_with_name(self): arg = Arg(int, location='form', name='foo') res = arg2parameter(arg) assert res['name'] == 'foo'
def test_arg_name_is_body_if_location_is_json(self): arg = Arg(int, location='json') result = arg2parameter(arg) assert result['name'] == 'body'
def test_arg_with_default(self): arg = Arg(int, location='form', default=42) result = arg2parameter(arg) assert result['default'] == 42
def test_arg_with_format(self): arg = Arg(int, location='form', format='int32') result = arg2parameter(arg) assert result['format'] == 'int32'
def test_arg_with_description(self): arg = Arg(int, location='form', description='a webargs arg') result = arg2parameter(arg) assert result['description'] == arg.metadata['description']
def test_items_multiple_querystring(self): arg = Arg(int, multiple=True, location='querystring') result = arg2parameter(arg) assert result['items'] == {'type': 'integer', 'format': 'int32'}
def test_collection_translation_single(self): arg = Arg(int, location='querystring') result = arg2parameter(arg) assert 'collectionFormat' not in result
def test_collection_translation_multiple(self): arg = Arg(int, multiple=True, location='querystring') result = arg2parameter(arg) assert result['type'] == 'array' assert result['collectionFormat'] == 'multi'
def test_location_defaults_to_json_body(self): # No location specified arg = Arg(int) result = arg2parameter(arg) assert result['in'] == 'body'
def test_location_translation(self, webargs_location, swagger_location): arg = Arg(int, location=webargs_location) result = arg2parameter(arg) assert result['in'] == swagger_location
def test_type_translation(self, pytype, jsontype): arg = Arg(pytype, location='form') result = arg2parameter(arg) assert result['type'] == jsontype
def test_no_schema_if_form_body(self): arg = Arg(int, location='form') res = arg2parameter(arg) assert 'schema' not in res
'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))