From ac37819cad08b92cc8eba808f2a7ce1a5442276e Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 8 Jul 2024 13:50:50 -0400 Subject: [PATCH] wrap URIs in double quotes --- process_request/helpers.py | 7 ++++--- process_request/tests.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/process_request/helpers.py b/process_request/helpers.py index 8f366d7..977377b 100644 --- a/process_request/helpers.py +++ b/process_request/helpers.py @@ -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. @@ -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"] diff --git a/process_request/tests.py b/process_request/tests.py index 5300f15..acfce0d 100644 --- a/process_request/tests.py +++ b/process_request/tests.py @@ -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")