Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions braincube_connector/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,23 @@ 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.
"""
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(
Expand Down Expand Up @@ -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(),
)
)
4 changes: 3 additions & 1 deletion braincube_connector/memory_base/memory_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <io@braincube.com>"]
Expand Down
8 changes: 6 additions & 2 deletions tests/test_data/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)


Expand All @@ -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="")
6 changes: 6 additions & 0 deletions tests_integration/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
16 changes: 16 additions & 0 deletions tests_integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down