Skip to content

Commit

Permalink
Merge pull request #656 from uc-cdis/fix/dbgap-combination
Browse files Browse the repository at this point in the history
Fix/dbgap combination
  • Loading branch information
Avantol13 authored Jul 5, 2019
2 parents e9b46f5 + b1bc1ea commit 1d29820
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions fence/sync/sync_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ def _parse_csv(self, file_dict, sess, encrypted=True):

if dbgap_project not in self.project_mapping:
if dbgap_project not in self._projects:

self.logger.debug(
"creating Project in fence from dbGaP study: {}".format(
dbgap_project
)
)

project = self._get_or_create(
sess, Project, auth_id=dbgap_project
)
Expand Down Expand Up @@ -858,6 +865,9 @@ def _init_projects(self, user_project, sess):
if self.project_mapping:
for projects in self.project_mapping.values():
for p in projects:
self.logger.debug(
"creating Project with info from project_mapping: {}".format(p)
)
project = self._get_or_create(sess, Project, **p)
self._projects[p["auth_id"]] = project
for _, projects in user_project.iteritems():
Expand Down Expand Up @@ -1028,6 +1038,9 @@ def _update_arborist(self, session, user_yaml):
for path_list in self._dbgap_study_to_resources.values():
dbgap_resource_paths.extend(path_list)

self.logger.debug("user_yaml resources: {}".format(resources))
self.logger.debug("dbgap resource paths: {}".format(dbgap_resource_paths))

combined_resources = utils.combine_provided_and_dbgap_resources(
resources, dbgap_resource_paths
)
Expand Down
4 changes: 4 additions & 0 deletions fence/sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def insert_segment(current, segment):
# In [3]: list(map(lambda x: x["name"] == "b", xs)).index(True)
# Out[3]: 1
i = list(map(lambda c: c["name"] == segment, current)).index(True)

if "subresources" not in current[i]:
current[i]["subresources"] = []

return current[i]["subresources"]

reduce(insert_segment, segments, start)
Expand Down
17 changes: 14 additions & 3 deletions tests/dbgap_sync/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_combine_arborist_resources():
yaml_string = """
rbac:
resources:
- name: 'root_no_subresources'
- name: 'gen3'
subresources:
- name: 'programs'
Expand All @@ -36,6 +37,7 @@ def test_combine_arborist_resources():
useryaml_resources = useryaml.get("rbac", {}).get("resources")

test_paths = [
"/root_no_subresources",
"/programs/phs000172",
"/orgA/programs/phs000175",
"/orgC/programs/phs000175",
Expand All @@ -48,7 +50,14 @@ def test_combine_arborist_resources():
useryaml_resources, test_paths
)

expected_roots = ["orgA", "orgB", "orgC", "programs", "gen3"]
expected_roots = [
"root_no_subresources",
"orgA",
"orgB",
"orgC",
"programs",
"gen3",
]
for item in combined:
# ensure one of each of the items in expected roots
assert item.get("name") in expected_roots
Expand All @@ -57,7 +66,9 @@ def test_combine_arborist_resources():
subresources = _get_subresources(item)

# ensure result has correct subresources
if item.get("name") == "orgA":
if item.get("name") == "root_no_subresources":
assert not subresources
elif item.get("name") == "orgA":
program_subresources = _get_subresources(subresources["programs"])
assert "phs000179" in program_subresources
assert "phs000175" in program_subresources
Expand Down Expand Up @@ -97,4 +108,4 @@ def test_combine_arborist_resources():


def _get_subresources(item):
return {subr.get("name"): subr for subr in item.get("subresources")}
return {subr.get("name"): subr for subr in item.get("subresources", [])}

0 comments on commit 1d29820

Please sign in to comment.