From 97a4261314dc987fae02974be1cb7d7c9cad2bd1 Mon Sep 17 00:00:00 2001 From: Maxime Morille Date: Mon, 25 Oct 2021 08:39:17 +0200 Subject: [PATCH] Fix #32, replace {braincube-name} placeholder by braincube's name in data module --- CHANGELOG.md | 6 ++++++ braincube_connector/data/data.py | 14 +++++++++++--- braincube_connector/memory_base/memory_base.py | 4 +++- pyproject.toml | 2 +- tests/test_data/test_data.py | 8 ++++++-- tests_integration/mocks.py | 6 ++++++ tests_integration/test_integration.py | 16 ++++++++++++++++ 7 files changed, 49 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea448c..3126931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.5.1 - 2021-10-25](https://github.com/braincube-io/python-connector/compare/2.5.0...2.5.1) + +### FIXED + +- #[32](https://github.com/braincube-io/python-connector/issues/32): Fix `{braincube-name}` placeholder usage in data module + ## [2.5.0 - 2021-10-13](https://github.com/braincube-io/python-connector/compare/2.4.1...2.5.0) ### Changed diff --git a/braincube_connector/data/data.py b/braincube_connector/data/data.py index 75139eb..98778fa 100644 --- a/braincube_connector/data/data.py +++ b/braincube_connector/data/data.py @@ -81,12 +81,15 @@ def _extract_format_data(raw_dataset: Dict[str, Any]) -> Dict[int, Any]: return formatted_dataset -def get_braindata_memory_base_info(braincube_path: str, memory_base_bcid: str) -> Dict[str, str]: +def get_braindata_memory_base_info( + braincube_path: str, memory_base_bcid: str, braincube_name="" +) -> Dict[str, str]: """Get the memory base informations from the braindata. Args: braincube_path: Path of the memory base's parent braincube. memory_base_bcid: memory base's bcid. + braincube_name: Name of the braincube to use to replace the `{braincube-name}` placeholder Returns: Json dictionary with the memory base informations. @@ -94,7 +97,7 @@ def get_braindata_memory_base_info(braincube_path: str, memory_base_bcid: str) - long_mb_id = "mb{bcid}".format(bcid=memory_base_bcid) braindata_info_path = "braindata/{mb_id}/simple".format(mb_id=long_mb_id) data_path = tools.join_path([braincube_path, braindata_info_path.format()]) - return client.request_ws(data_path) + return client.request_ws(data_path, braincube_name=braincube_name) def collect_data( @@ -126,5 +129,10 @@ def collect_data( if len(filters) == 1: body_data["context"]["filter"] = filters[0] # type: ignore return _extract_format_data( - client.request_ws(data_path, body_data=json.dumps(body_data), rtype="POST") + client.request_ws( + data_path, + body_data=json.dumps(body_data), + rtype="POST", + braincube_name=memory_base.get_braincube_name(), + ) ) diff --git a/braincube_connector/memory_base/memory_base.py b/braincube_connector/memory_base/memory_base.py index 289bad6..e57f3a8 100644 --- a/braincube_connector/memory_base/memory_base.py +++ b/braincube_connector/memory_base/memory_base.py @@ -166,7 +166,9 @@ def get_order_variable_long_id(self) -> str: Returns: A variable long id. """ - infos = data.get_braindata_memory_base_info(self.get_braincube_path(), self._bcid) + infos = data.get_braindata_memory_base_info( + self.get_braincube_path(), self._bcid, self.get_braincube_name() + ) for order_key in ("reference", "order"): order_id = infos.get(order_key) if order_id: diff --git a/pyproject.toml b/pyproject.toml index 0332d44..b092fc7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -version = "2.5.0" +version = "2.5.1" name = "braincube-connector" description = "python client to the braincube web services" authors = ["Braincube "] diff --git a/tests/test_data/test_data.py b/tests/test_data/test_data.py index f53a920..52037cf 100644 --- a/tests/test_data/test_data.py +++ b/tests/test_data/test_data.py @@ -68,13 +68,17 @@ def test_collect_data(mocker, filters, body_data): mb_obj.get_bcid.return_value = "1" mb_obj.get_order_variable_long_id.return_value = "mb1/d4" mb_obj.get_braincube_path.return_value = "braincube/bcname" + mb_obj.get_braincube_name.return_value = "bcname" rpatch = mocker.patch("braincube_connector.client.request_ws", return_value=DATASET) received_data = data.collect_data(["1", "2", "3", "4", "5"], mb_obj, filters) if filters: body_data["context"]["filter"] = filters[0] rpatch.assert_called_with( - "braincube/bcname/braindata/mb1/LF", body_data=json.dumps(body_data), rtype="POST" + "braincube/bcname/braindata/mb1/LF", + body_data=json.dumps(body_data), + rtype="POST", + braincube_name="bcname", ) @@ -84,4 +88,4 @@ def test_get_braindata_memory_base_info(mocker): expected_endpoint = "{bc_path}/braindata/mb{mb_id}/simple".format(bc_path=bc_path, mb_id=mb_id) request_patch = mocker.patch("braincube_connector.client.request_ws") data.get_braindata_memory_base_info(bc_path, mb_id) - request_patch.assert_called_once_with(expected_endpoint) + request_patch.assert_called_once_with(expected_endpoint, braincube_name="") diff --git a/tests_integration/mocks.py b/tests_integration/mocks.py index d7ea009..d588d50 100644 --- a/tests_integration/mocks.py +++ b/tests_integration/mocks.py @@ -98,6 +98,12 @@ "status": 200, "json": {"items": [],}, }, + { + "method": "GET", + "url": "http://demo.plop.com/prefix/v1.0/braindata/mb1/simple", + "status": 200, + "json": {"name": "mb1", "reference": "100001"}, + }, ] for bcid in ["101", "102", "103"]: diff --git a/tests_integration/test_integration.py b/tests_integration/test_integration.py index 6c8bd86..e08d7bb 100644 --- a/tests_integration/test_integration.py +++ b/tests_integration/test_integration.py @@ -126,6 +126,22 @@ def test_get_data(patch_endpoints): raise err +@responses.activate +def test_get_braindata_memory_base_info_with_custom_domains(custom_patch_endpoints): + custom_config = { + "sso_base_url": "http://another.plop.com", + "braincube_base_url": "http://{braincube-name}.plop.com/prefix/v1.0/", + "api_key": "abcd", + } + + bc = test_braincube(custom_patch_endpoints, custom_config) + custom_patch_endpoints() + mb = bc.get_memory_base(1) + + order_id = mb.get_order_variable_long_id() + assert order_id == "100001" + + @responses.activate def test_variable(patch_endpoints): mb = test_memorybase(patch_endpoints)