|
2 | 2 | import copy |
3 | 3 | import unittest |
4 | 4 | from pathlib import Path |
5 | | -from unittest.mock import MagicMock |
6 | 5 |
|
7 | 6 | from mdxpy import MdxBuilder |
8 | 7 |
|
|
17 | 16 | TM1pyWritePartialFailureException, |
18 | 17 | ) |
19 | 18 | from TM1py.Objects import Dimension, Element, ElementAttribute, Hierarchy |
20 | | -from TM1py.Services import TM1Service, ElementService |
| 19 | +from TM1py.Services import TM1Service |
21 | 20 |
|
22 | 21 |
|
23 | 22 | class TestElementService(unittest.TestCase): |
@@ -1607,33 +1606,38 @@ def test_element_is_ancestor_ti_method_not_existing_hierarchy(self): |
1607 | 1606 | method="TI", |
1608 | 1607 | ) |
1609 | 1608 |
|
1610 | | - @classmethod |
1611 | | - def tearDownClass(cls): |
1612 | | - cls.tm1.logout() |
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.""" |
| 1609 | + def test_get_parents_of_all_elements_with_closing_brace_in_dimension_name(self): |
| 1610 | + # regression: control dimensions (names starting with "}", e.g. |
| 1611 | + # "}APQ Time Second") must not break URL construction in |
| 1612 | + # get_parents_of_all_elements (formerly raised |
| 1613 | + # "Single '}' encountered in format string"). |
| 1614 | + dimension_name = "}TM1py_unittest_close_brace_" + generate_test_uuid() |
| 1615 | + hierarchy_name = dimension_name |
| 1616 | + |
| 1617 | + dimension = Dimension(dimension_name) |
| 1618 | + hierarchy = Hierarchy(dimension_name, hierarchy_name) |
| 1619 | + hierarchy.add_element("Total", "Consolidated") |
| 1620 | + hierarchy.add_element("Child1", "Numeric") |
| 1621 | + hierarchy.add_element("Child2", "Numeric") |
| 1622 | + hierarchy.add_edge("Total", "Child1", 1) |
| 1623 | + hierarchy.add_edge("Total", "Child2", 1) |
| 1624 | + dimension.add_hierarchy(hierarchy) |
| 1625 | + self.tm1.dimensions.update_or_create(dimension) |
1618 | 1626 |
|
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": []} |
| 1627 | + try: |
| 1628 | + parents = self.tm1.elements.get_parents_of_all_elements( |
| 1629 | + dimension_name=dimension_name, hierarchy_name=hierarchy_name |
| 1630 | + ) |
| 1631 | + finally: |
| 1632 | + self.tm1.dimensions.delete(dimension_name) |
1626 | 1633 |
|
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 | | - ) |
| 1634 | + self.assertEqual(["Total"], parents["Child1"]) |
| 1635 | + self.assertEqual(["Total"], parents["Child2"]) |
| 1636 | + self.assertEqual([], parents["Total"]) |
1631 | 1637 |
|
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 | | - ) |
| 1638 | + @classmethod |
| 1639 | + def tearDownClass(cls): |
| 1640 | + cls.tm1.logout() |
1637 | 1641 |
|
1638 | 1642 |
|
1639 | 1643 | if __name__ == "__main__": |
|
0 commit comments