Skip to content

Commit

Permalink
feat(arborist): no error if mapping={} + fix run.py
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Sep 12, 2019
1 parent 03b14ca commit 11c08ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 5 additions & 3 deletions peregrine/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from authutils.user import current_user
from cdislogging import get_logger
from datamodelutils import models
from gen3authz.client.arborist.errors import ArboristError
import flask

from peregrine.errors import AuthNError
Expand Down Expand Up @@ -89,9 +90,10 @@ def get_read_access_projects():
"""
Get all resources the user has read access to and parses the Arborist resource paths into a program.name and a project.code.
"""
mapping = flask.current_app.auth.auth_mapping(current_user.username)
if not mapping:
raise AuthNError("Unable to retrieve auth mapping")
try:
mapping = flask.current_app.auth.auth_mapping(current_user.username)
except ArboristError as e:
raise AuthNError("Unable to retrieve auth mapping: {}".format(e))

with flask.current_app.db.session_scope():
read_access_projects = [
Expand Down
15 changes: 14 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ def run_with_fake_auth():
run_for_development(debug=debug, threaded=True)


def run_with_fake_authz():
"""
Mocks arborist calls.
"""
auth_mapping = {} # modify this to mock specific access
with patch(
'gen3authz.client.arborist.client.ArboristClient.auth_mapping',
new_callable=PropertyMock,
return_value=lambda x: auth_mapping,
):
run_for_development(debug=debug, threaded=True)


def run_with_fake_download():
with patch("peregrine.download.get_nodes", fake_get_nodes):
with patch.multiple("peregrine.download",
Expand All @@ -116,4 +129,4 @@ def run_with_fake_download():
if os.environ.get("GDC_FAKE_AUTH") == 'True':
run_with_fake_auth()
else:
run_for_development(debug=debug, threaded=True)
run_with_fake_authz()

0 comments on commit 11c08ef

Please sign in to comment.