Skip to content

Instantly share code, notes, and snippets.

View Kalimaha's full-sized avatar
🌒
not because they are easy, but because they are hard

Guido Barbaglia Kalimaha

🌒
not because they are easy, but because they are hard
View GitHub Profile
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()
@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))
@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
@service_consumer('Sous Chef')
@has_pact_with('Grill Chef')
class GrillChefTest(ServiceProviderTest):
pass
@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')
{
"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" },
@Kalimaha
Kalimaha / oneliner.py
Last active October 14, 2017 00:25
iterate key, value for each dict in a list
headers = [{'Content-Type': 'application/json'}, {'Accept', '*/*'}]
for key, value in sum(list(map(list, map(dict.items, headers))), []):
print(str(key) + ': ' + str(value))
@Kalimaha
Kalimaha / proxy.py
Last active August 2, 2024 05:15
Simple Proxy server in Python
import time
from threading import Thread
try:
import socketserver as SocketServer
import http.server as SimpleHTTPServer
except ImportError:
import SocketServer
import SimpleHTTPServer
@Kalimaha
Kalimaha / colours.py
Created June 17, 2017 00:13
Print to terminal in colours w/ Python
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')
@Kalimaha
Kalimaha / experiment.py
Created May 22, 2017 09:17
Decorators Experiment
def state(state_value):
def decorate(function):
function.state = state_value
return function
return decorate
class ConsumerTest(object):
@property
def states(self):