-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#292 add some first test for MockResolver
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
from connexion.operation import Operation | ||
from connexion.mock import MockResolver | ||
|
||
|
||
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_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_notimplemented(): | ||
resolver = MockResolver(mock_all=False) | ||
|
||
operation = Operation(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' |