Skip to content

Commit

Permalink
fix unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deargle committed May 3, 2021
1 parent e854128 commit 7579cfd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions psiturk/dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@
# if you want to add a password protect route use this
myauth = PsiTurkAuthorization(config)

# this dashboard requires a valid mturk connection -- try for one here
try:
_ = services_manager.amt_services_wrapper # may throw error if aws keys not set
except NoMturkConnectionError:
raise Exception((
'Dashboard requested, but no valid mturk credentials found. '
'Either disable the dashboard in config, or set valid mturk credentials -- '
'see https://psiturk.readthedocs.io/en/latest/amt_setup.html#aws-credentials . '
'\nRefusing to start.'
))

# import the Blueprint
dashboard = Blueprint('dashboard', __name__,
template_folder='templates',
Expand All @@ -43,6 +32,17 @@


def init_app(app):
if not app.config.get('LOGIN_DISABLED'):
# this dashboard requires a valid mturk connection -- try for one here
try:
_ = services_manager.amt_services_wrapper # may throw error if aws keys not set
except NoMturkConnectionError:
raise Exception((
'Dashboard requested, but no valid mturk credentials found. '
'Either disable the dashboard in config, or set valid mturk credentials -- '
'see https://psiturk.readthedocs.io/en/latest/amt_setup.html#aws-credentials . '
'\nRefusing to start.'
))
login_manager.init_app(app)


Expand All @@ -66,7 +66,7 @@ def login_required(view):
def wrapped_view(*args, **kwargs):
if current_user.is_authenticated:
pass
elif app.login_manager._login_disabled: # for unit testing
elif app.config.get('LOGIN_DISABLED'): # for unit testing
pass
elif is_static_resource_call() or is_login_route():
pass
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def experiment_dir(tmpdir, bork_aws_environ, edit_config_file):
os.environ['PSITURK_AD_URL_DOMAIN'] = 'example.com'
os.environ['PSITURK_LOGIN_USERNAME'] = 'foo'
os.environ['PSITURK_LOGIN_PW'] = 'bar'
os.environ['PSITURK_SECRET_KEY'] = 'baz'

# the setup script already chdirs into here,
# although I don't like that it does that
Expand Down

0 comments on commit 7579cfd

Please sign in to comment.