This file contains hidden or 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
| class GrillChefPactHelper(PactHelper): | |
| test_port = 8080 | |
| process = None | |
| def setup(self): | |
| cmd = 'gunicorn start:app -w 3 -b :8080 --log-level error' | |
| self.process = subprocess.Popen(cmd, shell=True) | |
| def tear_down(self): | |
| self.process.kill() |
This file contains hidden or 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
| @honours_pact_with('Sous Chef') | |
| @pact_uri('http://localhost:9292/pacts/provider/Grill%20Chef/consumer/Sous%20Chef/latest.json') | |
| class SousChef(ServiceConsumerTest): | |
| @state('steaks are available') | |
| def test_steak(self): | |
| DB.save(Steak(cooked=False)) |
This file contains hidden or 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
| @given('steaks are available') | |
| @upon_receiving('a request for a well-done steak') | |
| @with_request({'method': 'POST', 'path': '/steaks/', 'body': {'cooking': 'well-done'}}) | |
| @will_respond_with({'status': 422, 'body': {'reason': 'we do not serve well-done steaks'}}) | |
| def test_steak(self): | |
| response = steak('well-done') | |
| assert response.status_code == 422 |
This file contains hidden or 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
| @service_consumer('Sous Chef') | |
| @has_pact_with('Grill Chef') | |
| class GrillChefTest(ServiceProviderTest): | |
| pass |
This file contains hidden or 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
| @service_consumer('Sous Chef') | |
| @has_pact_with('Grill Chef') | |
| class GrillChefTest(ServiceProviderTest): | |
| @given('steaks are available') | |
| @upon_receiving('a request for a steak') | |
| @with_request({'method': 'POST', 'path': '/steaks/', 'body': {'cooking': 'medium-rare'}}) | |
| @will_respond_with({'status': 201, 'body': {'waitingTime': 10}}) | |
| def test_steak(self): | |
| response = GrillChefRepository.steak('medium-rare') |
This file contains hidden or 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
| { | |
| "provider": { "name": "Grill Chef" }, | |
| "consumer": { "name": "Sous Chef" }, | |
| "interactions": [ | |
| { | |
| "status": "PASSED", | |
| "providerState": "steaks are available", | |
| "description": "a request for a steak", | |
| "request": { | |
| "body": { "cooking": "medium-rare" }, |
This file contains hidden or 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
| headers = [{'Content-Type': 'application/json'}, {'Accept', '*/*'}] | |
| for key, value in sum(list(map(list, map(dict.items, headers))), []): | |
| print(str(key) + ': ' + str(value)) |
This file contains hidden or 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 time | |
| from threading import Thread | |
| try: | |
| import socketserver as SocketServer | |
| import http.server as SimpleHTTPServer | |
| except ImportError: | |
| import SocketServer | |
| import SimpleHTTPServer | |
This file contains hidden or 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
| print('\033[95m' + '[ ] - ' + s.state + '\033[0m') | |
| print('\033[92m' + '[✓] - ' + s.state + '\033[0m') | |
| print('\033[93m' + '[!] - ' + s.state + '\033[0m') | |
| print('\033[91m' + '=======================\033[0m') | |
| print('\033[91m' + '[x] - ' + s.state + '\033[0m') | |
| print('\033[91m' + '-----------------------\033[0m') | |
| print('\033[91m' + 'Expected:\n\n ' + str({'spam': 'eggs'}) + '\n\nActual:\n\n ' + str({'eggs': 'bacon'}) + '\033[0m') | |
| print('\033[91m' + '=======================\033[0m') |
This file contains hidden or 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
| def state(state_value): | |
| def decorate(function): | |
| function.state = state_value | |
| return function | |
| return decorate | |
| class ConsumerTest(object): | |
| @property | |
| def states(self): |