Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make mh commands, specifically ghost inspector tests, work in context…
… of mh-opsworks includes: * removed .mh-ui-testing config file stuff; most options can be derived from the mh-opsworks cluster env * `gi` commands now have explicit options rather than doing a pass-through to py.test * top-level `mh` command now takes a `--working-dir` option and will chdir if specified
- Loading branch information
Showing
3 changed files
with
94 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,100 @@ | ||
import click | ||
from mh_cli import cli | ||
from mh_cli.common import pass_state | ||
from mh_cli.common import pass_state, host_option, state_callback | ||
|
||
from os.path import dirname | ||
from fabric.api import local, lcd | ||
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', context_settings=dict(ignore_unknown_options=True)) | ||
@click.argument('gi_args', nargs=-1, type=click.UNPROCESSED) | ||
@gi.command(name='list') | ||
@gi_list_options | ||
@pass_state | ||
def gi_list(state, gi_args): | ||
def gi_list(state): | ||
"""Collect and list available tests""" | ||
cmd = "py.test -c %s --verbose --collect-only %s" % (state.conf_file, " ".join(gi_args)) | ||
with(lcd(dirname(dirname(__file__)))): | ||
local(cmd) | ||
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', context_settings=dict(ignore_unknown_options=True)) | ||
@click.argument('gi_args', nargs=-1, type=click.UNPROCESSED) | ||
@gi.command(name='exec') | ||
@gi_exec_options | ||
@pass_state | ||
def gi_exec(state, gi_args): | ||
def gi_exec(state): | ||
"""Execute tests""" | ||
cmd = "py.test -c %s --verbose %s" % (state.conf_file, " ".join(gi_args)) | ||
with(lcd(dirname(dirname(__file__)))): | ||
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) |