-
Notifications
You must be signed in to change notification settings - Fork 1
/
gi.py
100 lines (87 loc) · 3.05 KB
/
gi.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import click
from mh_cli import cli
from mh_cli.common import pass_state, host_option, state_callback
from urlparse import urlunparse
from fabric.api import local, lcd, settings, quiet, abort, hide
def test_option(f):
return click.option('--test',
expose_value=False,
help='ID of a ghost inspector test',
multiple=True,
callback=state_callback)(f)
def suite_option(f):
return click.option('--suite',
expose_value=False,
help='ID of a ghost inspector suite',
multiple=True,
callback=state_callback)(f)
def key_option(f):
return click.option('--key',
expose_value=False,
help='ghost inspector API key',
envvar='GI_API_KEY',
callback=state_callback)(f)
def var_option(f):
return click.option('--var',
expose_value=False,
help='extra test variable(s); repeatable',
multiple=True,
callback=state_callback)(f)
def path_option(f):
return click.option('--path',
expose_value=False,
help='url path to add to base start url',
default='',
callback=state_callback)(f)
def protocol_option(f):
return click.option('--protocol',
expose_value=False,
help='defaults to http',
default='http',
callback=state_callback)(f)
def gi_list_options(f):
f = test_option(f)
f = suite_option(f)
f = key_option(f)
return f
def gi_exec_options(f):
f = gi_list_options(f)
f = var_option(f)
f = path_option(f)
f = host_option(f, required=True)
f = protocol_option(f)
return f
@cli.group()
def gi():
"""Do stuff with Ghost Inspector tests"""
@gi.command(name='list')
@gi_list_options
@pass_state
def gi_list(state):
"""Collect and list available tests"""
params = ['--gi_key %s' % state.key]
if state.test:
params.extend('--gi_test %s' % x for x in state.test)
if state.suite:
params.extend('--gi_suite %s' % x for x in state.suite)
_pytest_cmd('py.test --collect-only ' + ' '.join(params))
@gi.command(name='exec')
@gi_exec_options
@pass_state
def gi_exec(state):
"""Execute tests"""
start_url = urlunparse((state.protocol, state.host, state.path, '', '', ''))
params = [
'--gi_start_url %s' % start_url,
'--gi_key %s' % state.key
]
if state.test:
params.extend('--gi_test %s' % x for x in state.test)
if state.suite:
params.extend('--gi_suite %s' % x for x in state.suite)
if state.var:
params.extend('--gi_param %s' % x for x in state.var)
_pytest_cmd('py.test ' + ' '.join(params))
def _pytest_cmd(cmd):
with settings(hide('running', 'warnings'), warn_only=True):
local(cmd)