Ejemplo n.º 1
0
def test_mock_resolver_notimplemented():
    resolver = MockResolver(mock_all=False)

    responses = {'418': {}}

    # do not mock the existent functions
    operation = OpenAPIOperation(
        api=None,
        method='GET',
        path='endpoint',
        path_parameters=[],
        operation={'operationId': 'fakeapi.hello.get'},
        app_security=[],
        resolver=resolver)
    assert operation.operation_id == 'fakeapi.hello.get'

    # mock only the nonexistent ones
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={
                                     'operationId':
                                     'fakeapi.hello.nonexistent_function',
                                     'responses': responses
                                 },
                                 app_security=[],
                                 resolver=resolver)
    # check if it is using the mock function
    assert operation._resolution.function() == (
        'No example response was defined.', 418)
Ejemplo n.º 2
0
def test_mock_resolver():
    resolver = MockResolver(mock_all=True)

    responses = {
        'default': {
            'content': {
                'application/json': {
                    'examples': {
                        "super_cool_example": {
                            'foo': 'bar'
                        }
                    }
                }
            }
        }
    }

    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={'responses': responses},
                                 app_security=[],
                                 resolver=resolver)
    assert operation.operation_id == 'mock-1'

    response, status_code = resolver.mock_operation(operation)
    assert status_code == 200
    assert response == {'foo': 'bar'}
Ejemplo n.º 3
0
def test_resty_resolve_with_default_module_name_lowercase_verb():
    operation = OpenAPIOperation(api=None,
                                 method='get',
                                 path='/hello/{id}',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=RestyResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.hello.get'
Ejemplo n.º 4
0
def test_methodview_resolve_with_default_module_name_lowercase_verb():
    operation = OpenAPIOperation(api=None,
                                 method='get',
                                 path='/example_method/{id}',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.Example_methodView.get'
Ejemplo n.º 5
0
def test_resty_resolve_with_default_module_name_can_resolve_api_root():
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='/',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=RestyResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.get'
Ejemplo n.º 6
0
def test_methodview_resolve_with_default_module_name_will_translate_dashes_in_resource_name(
):
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='/example-method',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.Example_methodView.search'
Ejemplo n.º 7
0
def test_methodview_resolve_x_router_controller_without_operation_id():
    operation = OpenAPIOperation(
        api=None,
        method='GET',
        path='/hello/{id}',
        path_parameters=[],
        operation={'x-openapi-router-controller': 'fakeapi.Example_method'},
        app_security=[],
        components=COMPONENTS,
        resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.Example_methodView.get'
Ejemplo n.º 8
0
def test_methodview_resolve_with_default_module_name_will_resolve_resource_root_post_as_post(
):
    operation = OpenAPIOperation(api=None,
                                 method='POST',
                                 path='/example_method',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.Example_methodView.post'
Ejemplo n.º 9
0
def test_resty_resolve_with_default_module_name_will_translate_dashes_in_resource_name(
):
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='/foo-bar',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=RestyResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.foo_bar.search'
Ejemplo n.º 10
0
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_as_configured(
):
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='/hello',
                                 path_parameters=[],
                                 operation={},
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=RestyResolver('fakeapi', 'api_list'))
    assert operation.operation_id == 'fakeapi.hello.api_list'
Ejemplo n.º 11
0
def test_methodview_resolve_operation_id():
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={
                                     'operationId':
                                     'fakeapi.hello.post_greeting',
                                 },
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.hello.post_greeting'
Ejemplo n.º 12
0
def test_methodview_resolve_x_router_controller_with_operation_id():
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={
                                     'x-openapi-router-controller':
                                     'fakeapi.Example_methodView',
                                     'operationId': 'post_greeting',
                                 },
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.Example_methodView.post_greeting'
Ejemplo n.º 13
0
def test_standard_resolve_x_router_controller():
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={
                                     'x-openapi-router-controller':
                                     'fakeapi.hello',
                                     'operationId': 'post_greeting',
                                 },
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=Resolver())
    assert operation.operation_id == 'fakeapi.hello.post_greeting'
Ejemplo n.º 14
0
def test_methodview_resolve_with_default_module_name_and_x_router_controller_will_resolve_resource_root_get_as_search(
):
    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='/hello',
                                 path_parameters=[],
                                 operation={
                                     'x-openapi-router-controller':
                                     'fakeapi.example_method',
                                 },
                                 app_security=[],
                                 components=COMPONENTS,
                                 resolver=MethodViewResolver('fakeapi'))
    assert operation.operation_id == 'fakeapi.Example_methodView.search'
Ejemplo n.º 15
0
def test_mock_resolver_no_examples():
    resolver = MockResolver(mock_all=True)

    responses = {'418': {}}

    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={'responses': responses},
                                 app_security=[],
                                 resolver=resolver)
    assert operation.operation_id == 'mock-1'

    response, status_code = resolver.mock_operation(operation)
    assert status_code == 418
    assert response == 'No example response was defined.'
Ejemplo n.º 16
0
def test_mock_resolver_inline_schema_example():
    resolver = MockResolver(mock_all=True)

    responses = {
        'default': {
            'content': {
                'application/json': {
                    'schema': {
                        'type': 'object',
                        'properties': {
                            'foo': {
                                'schema': {
                                    'type': 'string'
                                }
                            }
                        }
                    },
                    'example': {
                        'foo': 'bar'
                    }
                }
            }
        }
    }

    operation = OpenAPIOperation(api=None,
                                 method='GET',
                                 path='endpoint',
                                 path_parameters=[],
                                 operation={'responses': responses},
                                 app_security=[],
                                 resolver=resolver)
    assert operation.operation_id == 'mock-1'

    response, status_code = resolver.mock_operation(operation)
    assert status_code == 200
    assert response == {'foo': 'bar'}