summaryrefslogtreecommitdiff
path: root/yarns/900.yarn
blob: c7e81a068715ee6416acedefc108a2f480813769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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]