Created
May 22, 2021 23:28
-
-
Save mertyildiran/4e52945508965acbcb388d470426fa33 to your computer and use it in GitHub Desktop.
Mockintosh: mocks for microservice environments - Part 4: Multiple Responses and Datasets
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
services: | |
- port: 8081 | |
endpoints: | |
- path: "/example" | |
response: | |
- "response 1" | |
- "response 2" | |
- "response 3" |
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
import httpx | |
def do_request() -> int: | |
resp = httpx.get('http://localhost:8081/example') | |
return resp.status_code | |
def test_example(): | |
assert do_request() == 202 | |
assert do_request() == 202 | |
assert do_request() == 202 | |
assert do_request() == 503 |
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
services: | |
- port: 8081 | |
endpoints: | |
- path: "/example" | |
multiResponsesLooped: false | |
response: | |
- status: 202 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 200, "message": "Accepted"}' | |
- status: 202 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 200, "message": "Accepted"}' | |
- status: 202 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 200, "message": "Accepted"}' | |
- status: 503 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 503, "message": "Server is busy"}' |
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
management: | |
port: 8080 | |
services: | |
- port: 8081 | |
endpoints: | |
- path: "/example" | |
multiResponsesLooped: false | |
response: | |
- tag: accepted | |
status: 202 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 200, "message": "Accepted"}' | |
- tag: accepted | |
status: 202 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 200, "message": "Accepted"}' | |
- tag: accepted | |
status: 202 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 200, "message": "Accepted"}' | |
- tag: busy | |
status: 503 | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"status": 503, "message": "Server is busy"}' |
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
services: | |
- port: 8081 | |
endpoints: | |
- path: "/example" | |
dataset: | |
- var: "value 1" | |
- var: "value 2" | |
- var: "value 3" | |
response: "var: {{var}}" |
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
import httpx | |
def do_request() -> str: | |
resp = httpx.get('http://localhost:8081/example') | |
data = resp.json() | |
var = data['var'] | |
if isinstance(var, int): | |
return 'integer' | |
elif isinstance(var, float): | |
return 'float' | |
elif isinstance(var, str): | |
return 'string' | |
else: | |
raise Exception() | |
def test_example(): | |
assert do_request() == 'integer' | |
assert do_request() == 'float' | |
assert do_request() == 'string' |
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
services: | |
- port: 8081 | |
endpoints: | |
- path: "/example" | |
dataset: | |
- var: 5 | |
- var: 3.14 | |
- var: "\"hello world\"" | |
response: | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"var": {{var}}}' |
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
management: | |
port: 8080 | |
services: | |
- port: 8081 | |
endpoints: | |
- path: "/example" | |
dataset: | |
- tag: "integer" | |
var: 5 | |
- tag: "float" | |
var: 3.14 | |
- tag: "string" | |
var: "\"hello world\"" | |
response: | |
headers: | |
Content-Type: "application/json; charset=UTF-8" | |
body: '{"var": {{var}}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment