summaryrefslogtreecommitdiff
path: root/yarns/900.yarn
diff options
context:
space:
mode:
Diffstat (limited to 'yarns/900.yarn')
-rw-r--r--yarns/900.yarn36
1 files changed, 36 insertions, 0 deletions
diff --git a/yarns/900.yarn b/yarns/900.yarn
new file mode 100644
index 0000000..c7e81a0
--- /dev/null
+++ b/yarns/900.yarn
@@ -0,0 +1,36 @@
+# Scenario step implementations
+
+ IMPLEMENTS GIVEN a running backend instance
+ backend = os.path.join(srcdir, 'distix-backend')
+ cliapp.runcmd(['/usr/sbin/daemonize', '-c.', backend, 'pid', 'port'])
+ vars['pid'] = cat('pid').strip()
+ vars['port'] = cat('port').strip()
+
+ IMPLEMENTS FINALLY stop backend instance
+ import signal
+ print 'killing process', repr(vars['pid'])
+ os.kill(int(vars['pid']), signal.SIGTERM)
+
+ IMPLEMENTS WHEN client makes request GET (\S+)
+ path = os.environ['MATCH_1']
+ url = 'http://localhost:{}{}'.format(vars['port'], path)
+ print 'url:', repr(url)
+ import requests
+ r = requests.get(url)
+ vars['http-status'] = r.status_code
+ vars['http-body'] = r.text
+
+ IMPLEMENTS THEN HTTP status code is (\d+)
+ wanted = int(os.environ['MATCH_1'])
+ print 'wanted:', repr(wanted)
+ print 'actual:', repr(vars['http-status'])
+ assert vars['http-status'] == wanted
+
+ IMPLEMENTS THEN result matches (.*)
+ import json
+ body = json.loads(vars['http-body'])
+ pattern = json.loads(os.environ['MATCH_1'])
+ assert type(body) == type(pattern)
+ for key in pattern.keys():
+ assert key in body
+ assert body[key] == pattern[key]