def test_mock_resolver_notimplemented(): resolver = MockResolver(mock_all=False) responses = {'418': {}} # do not mock the existent functions operation = Swagger2Operation( api=None, method='GET', path='endpoint', path_parameters=[], operation={'operationId': 'fakeapi.hello.get'}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions={}, resolver=resolver) assert operation.operation_id == 'fakeapi.hello.get' # mock only the nonexistent ones operation = Swagger2Operation(api=None, method='GET', path='endpoint', path_parameters=[], operation={ 'operationId': 'fakeapi.hello.nonexistent_function', 'responses': responses }, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions={}, resolver=resolver) # check if it is using the mock function assert operation._resolution.function() == ( 'No example response was defined.', 418)
def test_resty_resolve_with_default_module_name_can_resolve_api_root(): operation = Swagger2Operation(api=None, method='GET', path='/', path_parameters=[], operation={}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions=PARAMETER_DEFINITIONS, resolver=RestyResolver('fakeapi')) assert operation.operation_id == 'fakeapi.get'
def test_resty_resolve_x_router_controller_without_operation_id(): operation = Swagger2Operation( api=None, method='GET', path='/hello/{id}', path_parameters=[], operation={'x-swagger-router-controller': 'fakeapi.hello'}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions=PARAMETER_DEFINITIONS, resolver=RestyResolver('fakeapi')) assert operation.operation_id == 'fakeapi.hello.get'
def test_resty_resolve_with_default_module_name_will_translate_dashes_in_resource_name( ): operation = Swagger2Operation(api=None, method='GET', path='/foo-bar', path_parameters=[], operation={}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions=PARAMETER_DEFINITIONS, resolver=RestyResolver('fakeapi')) assert operation.operation_id == 'fakeapi.foo_bar.search'
def test_resty_resolve_with_default_module_name_will_resolve_resource_root_as_configured( ): operation = Swagger2Operation(api=None, method='GET', path='/hello', path_parameters=[], operation={}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions=PARAMETER_DEFINITIONS, resolver=RestyResolver( 'fakeapi', 'api_list')) assert operation.operation_id == 'fakeapi.hello.api_list'
def test_resty_resolve_operation_id(): operation = Swagger2Operation(api=None, method='GET', path='endpoint', path_parameters=[], operation={ 'operationId': 'fakeapi.hello.post_greeting', }, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions=PARAMETER_DEFINITIONS, resolver=RestyResolver('fakeapi')) assert operation.operation_id == 'fakeapi.hello.post_greeting'
def test_resty_resolve_with_default_module_name_and_x_router_controller_will_resolve_resource_root_get_as_search( ): operation = Swagger2Operation(api=None, method='GET', path='/hello', path_parameters=[], operation={ 'x-swagger-router-controller': 'fakeapi.hello', }, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions=PARAMETER_DEFINITIONS, resolver=RestyResolver('fakeapi')) assert operation.operation_id == 'fakeapi.hello.search'
def test_mock_resolver_no_examples(): resolver = MockResolver(mock_all=True) responses = {'418': {}} operation = Swagger2Operation(api=None, method='GET', path='endpoint', path_parameters=[], operation={'responses': responses}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions={}, 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.'
def test_mock_resolver(): resolver = MockResolver(mock_all=True) responses = {'default': {'examples': {'application/json': {'foo': 'bar'}}}} operation = Swagger2Operation(api=None, method='GET', path='endpoint', path_parameters=[], operation={'responses': responses}, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={}, parameter_definitions={}, resolver=resolver) assert operation.operation_id == 'mock-1' response, status_code = resolver.mock_operation(operation) assert status_code == 200 assert response == {'foo': 'bar'}