|
2 | 2 | import copy |
3 | 3 | import unittest |
4 | 4 | from pathlib import Path |
| 5 | +from unittest.mock import MagicMock |
5 | 6 |
|
6 | 7 | from mdxpy import MdxBuilder |
7 | 8 |
|
|
16 | 17 | TM1pyWritePartialFailureException, |
17 | 18 | ) |
18 | 19 | from TM1py.Objects import Dimension, Element, ElementAttribute, Hierarchy |
19 | | -from TM1py.Services import TM1Service |
| 20 | +from TM1py.Services import TM1Service, ElementService |
20 | 21 |
|
21 | 22 |
|
22 | 23 | class TestElementService(unittest.TestCase): |
@@ -1611,5 +1612,29 @@ def tearDownClass(cls): |
1611 | 1612 | cls.tm1.logout() |
1612 | 1613 |
|
1613 | 1614 |
|
| 1615 | +class TestElementServiceUrlBuilding(unittest.TestCase): |
| 1616 | + """URL construction unit tests. Do not require a running TM1 server; |
| 1617 | + the REST service is mocked to verify URL building in isolation.""" |
| 1618 | + |
| 1619 | + def test_get_parents_of_all_elements_with_closing_brace_in_name(self): |
| 1620 | + # regression: dimension/hierarchy names may contain a closing brace |
| 1621 | + # (e.g. TM1 control objects like "}APQ Time Second"). URL construction |
| 1622 | + # must not raise "Single '}' encountered in format string". |
| 1623 | + element_service = ElementService.__new__(ElementService) |
| 1624 | + element_service._rest = MagicMock() |
| 1625 | + element_service._rest.GET.return_value.json.return_value = {"value": []} |
| 1626 | + |
| 1627 | + dimension_name = "}APQ Time Second" |
| 1628 | + result = element_service.get_parents_of_all_elements( |
| 1629 | + dimension_name=dimension_name, hierarchy_name=dimension_name |
| 1630 | + ) |
| 1631 | + |
| 1632 | + self.assertEqual({}, result) |
| 1633 | + element_service._rest.GET.assert_called_once_with( |
| 1634 | + url="/Dimensions('}APQ Time Second')/Hierarchies('}APQ Time Second')" |
| 1635 | + "/Elements?$select=Name&$expand=Parents($select=Name)" |
| 1636 | + ) |
| 1637 | + |
| 1638 | + |
1614 | 1639 | if __name__ == "__main__": |
1615 | 1640 | unittest.main() |
0 commit comments