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'}
def test_mock_resolver_no_examples(): resolver = MockResolver(mock_all=True) responses = { '418': {} } operation = Operation(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_example_nested_in_object(): resolver = MockResolver(mock_all=True) responses = { 'default': { 'schema': { 'type': 'object', 'properties': { 'foo': { 'type': 'string', 'example': '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'}
def test_mock_resolver(): resolver = MockResolver(mock_all=True) responses = { 'default': { 'examples': { 'application/json': { 'foo': 'bar' } } } } operation = Operation(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'}
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'}
def test_mock_resolver_no_example_nested_in_list_openapi(): resolver = MockResolver(mock_all=True) responses = { '202': { 'content': { 'application/json': { 'schema': { 'type': 'array', 'items': { 'type': 'string', } } } } } } 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 == 202 assert response == 'No example response was defined.'
def test_mock_resolver_no_examples(): resolver = MockResolver(mock_all=True) responses = { '418': {} } operation = Operation(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_numeric(): resolver = MockResolver(mock_all=True) responses = { '200': { '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'}
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'}
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.'
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'}
def test_mock_resolver_ref_schema_example(): resolver = MockResolver(mock_all=True) responses = { 'default': { 'schema': { '$ref': '#/definitions/Schema' } } } operation = Operation(api=None, method='GET', path='endpoint', path_parameters=[], operation={ 'responses': responses }, app_produces=['application/json'], app_consumes=['application/json'], app_security=[], security_definitions={}, definitions={ 'Schema': { 'example': { 'foo': 'bar' } } }, 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'}