Skip to content

Commit

Permalink
Merge pull request #346 from RockefellerArchiveCenter/issue-345
Browse files Browse the repository at this point in the history
Wrap URIs in double quotes
  • Loading branch information
helrond authored Jul 8, 2024
2 parents 89cfe21 + ac37819 commit 71befcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions process_request/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def get_rights_text(item_json, client):

def get_resource_creators(resource, client):
"""Gets all creators of a resource record and concatenate them into a string
separated by commas.
separated by commas. URIs must be wrapped in double quotes.
Args:
resource (dict): resource record data.
Expand All @@ -304,8 +304,9 @@ def get_resource_creators(resource, client):
"""
creators = []
if resource.get("linked_agents"):
linked_agent_uris = [a["ref"].replace("/", "\\/") for a in resource["linked_agents"] if a["role"] == "creator"]
search_uri = f"/repositories/{settings.ARCHIVESSPACE['repo_id']}/search?fields[]=title&type[]=agent_person&type[]=agent_corporate_entity&type[]=agent_family&page=1&q={' OR '.join(linked_agent_uris)}"
linked_agent_uris = [a["ref"] for a in resource["linked_agents"] if a["role"] == "creator"]
query_param = f'\"{" OR ".join(linked_agent_uris)}\"'
search_uri = f"/repositories/{settings.ARCHIVESSPACE['repo_id']}/search?fields[]=title&type[]=agent_person&type[]=agent_corporate_entity&type[]=agent_family&page=1&q={query_param}"
resp = client.get(search_uri)
resp.raise_for_status()
creators = resp.json()["results"]
Expand Down
2 changes: 1 addition & 1 deletion process_request/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_get_resource_creators(self, mock_client):
mock_client.get.return_value.json.return_value = {"results": [{"title": "Philanthropy Foundation"}]}
obj_data = json_from_fixture("object_all.json")
self.assertEqual(get_resource_creators(obj_data.get("ancestors")[-1].get("_resolved"), mock_client), "Philanthropy Foundation")
mock_client.get.assert_called_with("/repositories/2/search?fields[]=title&type[]=agent_person&type[]=agent_corporate_entity&type[]=agent_family&page=1&q=\\/agents\\/corporate_entities\\/123")
mock_client.get.assert_called_with('/repositories/2/search?fields[]=title&type[]=agent_person&type[]=agent_corporate_entity&type[]=agent_family&page=1&q="/agents/corporate_entities/123"')

def test_get_dates(self):
obj_data = json_from_fixture("object_all.json")
Expand Down

0 comments on commit 71befcc

Please sign in to comment.