From 7758d5e7e7a2952b7663e5648cdd6dd6474bac23 Mon Sep 17 00:00:00 2001 From: Chuong Ho Date: Tue, 10 Sep 2024 13:14:43 +0800 Subject: [PATCH] add get project --- .../src/aps_toolkit/AECDataModel.py | 27 +++++++++++++++++++ .../src/test/test_aec_data_model.py | 21 +-------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/APSToolkitPython/src/aps_toolkit/AECDataModel.py b/APSToolkitPython/src/aps_toolkit/AECDataModel.py index b38aa71..04fa35e 100644 --- a/APSToolkitPython/src/aps_toolkit/AECDataModel.py +++ b/APSToolkitPython/src/aps_toolkit/AECDataModel.py @@ -48,3 +48,30 @@ def get_hubs(self) -> pd.DataFrame: result = self.execute_query(data) hubs = result['data']['hubs']['results'] return pd.json_normalize(hubs) + + def get_projects(self, hub_id: str) -> pd.DataFrame: + data = { + "query": """ + query GetProjects($hubId: ID!) { + projects(hubId: $hubId) { + results { + id + name + hub { + id + name + } + alternativeIdentifiers{ + dataManagementAPIProjectId + } + } + } + } + """, + "variables": { + "hubId": hub_id + } + } + result = self.execute_query(data) + projects = result['data']['projects']['results'] + return pd.json_normalize(projects) \ No newline at end of file diff --git a/APSToolkitPython/src/test/test_aec_data_model.py b/APSToolkitPython/src/test/test_aec_data_model.py index 7c036a7..658ebb9 100644 --- a/APSToolkitPython/src/test/test_aec_data_model.py +++ b/APSToolkitPython/src/test/test_aec_data_model.py @@ -27,26 +27,7 @@ def test_get_hubs(self): self.assertIsNotNone(df_result) def test_get_projects(self): - data = { - "query": """ - query GetProjects($hubId: ID!) { - projects(hubId: $hubId) { - results { - id - name - hub { - id - name - } - } - } - } - """, - "variables": { - "hubId": f"{self.hub_id}" - } - } - result = self.aec_data_model.execute_query(data) + result = self.aec_data_model.get_projects(self.hub_id) self.assertIsNotNone(result) def test_version_group_by_project(self):