# Implementation of scenario steps ## Server aliases IMPLEMENTS GIVEN server is also known as (\S+) import yarnhelper h = yarnhelper.YarnHelper() h.set_variable('SERVER', h.get_next_match()) ## HTTP requests IMPLEMENTS WHEN user fetches (\S+) import yarnhelper h = yarnhelper.YarnHelper() server = h.get_variable('SERVER') url = h.get_next_match() status, body = h.http_get(server, url) h.set_variable('http_status', status) h.set_variable('http_body', body) IMPLEMENTS THEN HTTP status is (\d+) import yarnhelper h = yarnhelper.YarnHelper() expected = h.get_variable('http_status') actual = int(h.get_next_match()) h.assertEqual(expected, actual) IMPLEMENTS THEN HTTP body matches "(.*)" import re, yarnhelper h = yarnhelper.YarnHelper() body = h.get_variable('http_body') pattern = h.get_next_match() m = re.search(pattern, body) h.assertNotEqual(m, None) ## Running commands and checking results IMPLEMENTS WHEN user runs Gitano (.*) import os, re, cliapp, yarnhelper h = yarnhelper.YarnHelper() server = os.environ['SERVER'] cmd = h.get_next_match() argv = ['ssh', 'git@' + server] + cmd.split() exit, out, err = cliapp.runcmd_unchecked(argv) h.set_variable('argv', argv) h.set_variable('exit', int(exit)) h.set_variable('stdout', out) h.set_variable('stderr', err) IMPLEMENTS WHEN user clones the (\S+) repository over git:// import os, re, cliapp, yarnhelper h = yarnhelper.YarnHelper() server = os.environ['SERVER'] repo = h.get_next_match() url = 'git://{}/{}'.format(server, repo) argv = ['git', 'clone', url] exit, out, err = cliapp.runcmd_unchecked(argv, cwd=os.environ['DATADIR']) h.set_variable('argv', argv) h.set_variable('exit', int(exit)) h.set_variable('stdout', out) h.set_variable('stderr', err) IMPLEMENTS THEN exit code is (\d+) import yarnhelper h = yarnhelper.YarnHelper() code = h.get_next_match() h.assertEqual(h.get_variable('exit'), int(code)) IMPLEMENTS THEN standard output matches "(.+)" import re, cliapp, yarnhelper h = yarnhelper.YarnHelper() pattern = h.get_next_match() stdout = h.get_variable('stdout') m = re.search(pattern, stdout) print 'pattern:', repr(pattern) print 'argv:', repr(h.get_variable('argv')) print 'stdout:', repr(stdout) h.assertNotEqual(m, None) IMPLEMENTS THEN standard error matches "(.+)" import re, cliapp, yarnhelper h = yarnhelper.YarnHelper() pattern = h.get_next_match() stderr = h.get_variable('stderr') m = re.search(pattern, stderr) print 'pattern:', repr(pattern) print 'argv:', repr(h.get_variable('argv')) print 'stderr:', repr(stderr) h.assertNotEqual(m, None)