Exemple #1
0
def test_spec_get_operation_parameters(petstore_dict, media_type):
    operation_dict = petstore_dict['paths']['/v1/pets/{pet_id}']['get']
    operation_dict['parameters'] = [
        {
            'name': 'page',
            'in': 'query'
        },
        {
            'name': 'limit',
            'in': 'query'
        },
        {
            'name': 'pet_id',
            'in': 'query'
        },
        {
            'name': 'pet_id',
            'in': 'path'
        },
    ]
    spec = create_spec_from_dict(petstore_dict)

    operation = spec.get_operation('/api/v1/pets/{pet_id}', 'get', media_type)
    assert operation['parameters'] == operation_dict['parameters']
    assert 'requestBody' not in operation
Exemple #2
0
def test_spec_get_operation_request_body_and_security(petstore_dict,
                                                      media_type):
    spec = create_spec_from_dict(petstore_dict)
    schemas = spec['components']['schemas']

    operation = spec.get_operation('/api/v1/pets', 'post', media_type)
    assert operation['parameters'] == []
    assert operation['requestBody'] == {
        'content': {
            media_type: {
                'schema': schemas['PetNew']
            }
        },
        'required': True,
    }
    assert operation['security'] == [{'api_key': []}, {'session': []}]
Exemple #3
0
def test_spec_get_security_schemes_none():
    spec = create_spec_from_dict({})

    assert spec.get_security_schemes() is None
Exemple #4
0
def test_spec_get_security_schemes(petstore_dict):
    spec = create_spec_from_dict(petstore_dict)
    components = spec['components']

    assert spec.get_security_schemes() == components['securitySchemes']
Exemple #5
0
def test_spec_get_operation_undocumented_operation():
    spec = create_spec_from_dict({})
    assert spec.get_operation('/path', 'get', None) is None
Exemple #6
0
def test_spec_get_operation_unknown_base_path():
    spec = create_spec_from_dict({'servers': [{'url': '/api'}], 'paths': {}})
    assert spec.get_operation('/path', 'get', None) is None
Exemple #7
0
def test_spec_get_operation_request_body_undocumented_media_type(
    petstore_dict, ):
    spec = create_spec_from_dict(petstore_dict)

    with pytest.raises(UndocumentedMediaType):
        spec.get_operation('/api/v1/pets', 'post', 'text/plain')
Exemple #8
0
def test_create_spec_from_dict(petstore_dict):
    spec = create_spec_from_dict(petstore_dict)

    schemas = spec['components']['schemas']
    assert schemas['PetNew']['allOf'][0] == schemas['PetUpdate']