Skip to content

Commit

Permalink
fix(run.py): mock arborist calls (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre authored Sep 13, 2019
1 parent 3b0346f commit 8d10797
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ flasgger==0.9.1
-e git+https://[email protected]/uc-cdis/[email protected]#egg=cdisutilstest
-e git+https://[email protected]/uc-cdis/[email protected]#egg=indexd
# indexd dependencies
authutils==3.1.0
authutils==3.1.1
gen3rbac==0.1.2
-e git+https://[email protected]/uc-cdis/[email protected]#egg=doiclient
-e git+https://[email protected]/uc-cdis/[email protected]#egg=dosclient
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
authutils==3.1.1
boto==2.36.0
cryptography==2.3
dictionaryutils==2.0.7
Expand All @@ -22,7 +23,6 @@ sqlalchemy==1.3.5
Werkzeug==0.12.2
xmltodict==0.9.2
more-itertools==5.0.0
-e git+https://[email protected]/uc-cdis/[email protected]#egg=authutils
-e git+https://[email protected]/uc-cdis/[email protected]#egg=cdis_oauth2client
cdispyutils==0.2.13
datamodelutils==0.4.7
Expand Down
20 changes: 18 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from authutils import ROLES as all_roles
from collections import defaultdict
from mock import patch, PropertyMock
import os
Expand All @@ -10,7 +11,6 @@
from psqlgraph import PolyNode as Node

from sheepdog.api import run_for_development
from sheepdog.auth import ROLES as all_roles


requests.packages.urllib3.disable_warnings()
Expand Down Expand Up @@ -117,6 +117,22 @@ def get_project_ids(role="_member_", project_ids=None):
run_for_development(debug=debug, threaded=True)


def run_with_fake_authz():
"""
Mocks arborist calls.
"""
authorized = True # modify this to mock authorized/unauthorized
with patch(
'gen3authz.client.arborist.client.ArboristClient.create_resource',
new_callable=PropertyMock,
), patch(
'gen3authz.client.arborist.client.ArboristClient.auth_request',
new_callable=PropertyMock,
return_value=lambda jwt, service, methods, resources: authorized,
):
run_for_development(debug=debug, threaded=True)


def run_with_fake_download():
with patch("sheepdog.download.get_nodes", fake_get_nodes):
with patch.multiple(
Expand All @@ -139,4 +155,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 8d10797

Please sign in to comment.