Skip to content

Commit

Permalink
2 accessor for github_oauth and bug fix
Browse files Browse the repository at this point in the history
Previously run_tests.sh would override the command line
(and test.conf) value for host.allowwrite with "false".

The 2 new accessors are just sugar for making sure
that you are not running write-only tests in readonly
mode, or against the production api server, and that you
have the (necessary) env variable.
mtholder committed Oct 3, 2016
1 parent 3ca0177 commit be8cbd0
Showing 2 changed files with 38 additions and 2 deletions.
33 changes: 32 additions & 1 deletion ws-tests/opentreetesting.py
Original file line number Diff line number Diff line change
@@ -210,7 +210,8 @@ def raise_for_status(resp):


def api_is_readonly():
return config('host', 'allowwrite', 'false').lower() == 'false'
s = config('host', 'allowwrite', 'false').lower()
return not (s == 'true')

def exit_if_api_is_readonly(fn):
if not api_is_readonly():
@@ -220,6 +221,36 @@ def exit_if_api_is_readonly(fn):
# This coordinates with run_tests.sh
sys.exit(3)

def github_oauth_for_write_or_exit(fn):
"""Pass in the name of test file and get back the OAUTH token from
the GITHUB_OAUTH_TOKEN environment if the test is not readonly.
Otherwise, exit with the exit code (3) that signals tests skipping.
"""
exit_if_api_is_readonly(fn)
auth_token = os.environ.get('GITHUB_OAUTH_TOKEN')
if auth_token is None:
debug('{} skipped due to lack of GITHUB_OAUTH_TOKEN in env\n'.format(fn))
# This coordinates with run_tests.sh
sys.exit(3)
return auth_token

def writable_api_host_and_oauth_or_exit(fn):
"""Convenience/safety function to makes sure you aren't running
writable phylesystem tests against the production api server.
Returns the domain and GITHUB_OAUTH_TOKEN token if the test configuration
is not readonly, the server is not "https://api.opentree.*" and GITHUB_OAUTH_TOKEN
is in your env. Otherwise exits with the "skip" test code.
"""
apihost = config('host', 'apihost').strip()
if apihost.startswith('https://api.opentree'):
debug('{} skipped because host is set to production api server. This test must be run locally or against devapi.\n'.format(fn))
# This coordinates with run_tests.sh
sys.exit(3)
auth_token = github_oauth_for_write_or_exit(fn)
return apihost, auth_token



# Mimic the behavior of apache so that services can be tested without
# having apache running. See deploy/setup/opentree-shared.conf
7 changes: 6 additions & 1 deletion ws-tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -66,7 +66,12 @@ if [[ ! "$first_config_spec" =~ "=" ]]; then
first_config_spec=host:apihost=$first_config_spec
fi

config_specs="$first_config_spec $* host:allowwrite=false"

config_specs="$first_config_spec $*"
if [[ ! "$config_specs" =~ "host:allowwrite=" ]]; then
config_specs="$first_config_spec $* host:allowwrite=false"
fi


# The python test scripts all use the opentreetesting.py library,
# so its location has to be on PYTHONPATH.

0 comments on commit be8cbd0

Please sign in to comment.