diff --git a/Tests/AnnotationService_test.py b/Tests/AnnotationService_test.py index f19ac34c..b35229a2 100644 --- a/Tests/AnnotationService_test.py +++ b/Tests/AnnotationService_test.py @@ -3,8 +3,8 @@ import string import unittest from pathlib import Path -from uuid import uuid1 +from Tests.Utils import generate_test_uuid from TM1py.Objects import Annotation, Cube, Dimension, Element, Hierarchy from TM1py.Services import TM1Service @@ -35,7 +35,7 @@ def setUp(self): Run before each test to create a cube with test annotations """ # Build Dimensions - test_uuid = str(uuid1()).replace("-", "_") + test_uuid = generate_test_uuid() self.dimension_names = ( "TM1py_tests_annotations_dimension1_" + test_uuid, "TM1py_tests_annotations_dimension2_" + test_uuid, diff --git a/Tests/ElementService_test.py b/Tests/ElementService_test.py index edba7071..9a86654d 100644 --- a/Tests/ElementService_test.py +++ b/Tests/ElementService_test.py @@ -2,11 +2,14 @@ import copy import unittest from pathlib import Path -from uuid import uuid1 from mdxpy import MdxBuilder -from Tests.Utils import skip_if_no_pandas, skip_if_version_lower_than +from Tests.Utils import ( + generate_test_uuid, + skip_if_no_pandas, + skip_if_version_lower_than, +) from TM1py.Exceptions import TM1pyException, TM1pyRestException from TM1py.Objects import Dimension, Element, ElementAttribute, Hierarchy from TM1py.Services import TM1Service @@ -27,7 +30,7 @@ def setUpClass(cls): cls.tm1 = TM1Service(**cls.config["tm1srv01"]) def setUp(self): - dimension_uuid = str(uuid1()).replace("-", "_") + dimension_uuid = generate_test_uuid() prefix = "TM1py_unittest_element" pure_dimension_name = f"{prefix}_dimension_{dimension_uuid}" diff --git a/Tests/SubsetService_test.py b/Tests/SubsetService_test.py index 41f7884b..cfb70385 100644 --- a/Tests/SubsetService_test.py +++ b/Tests/SubsetService_test.py @@ -2,6 +2,7 @@ import unittest from pathlib import Path +from Tests.Utils import generate_test_uuid from TM1py.Objects import Dimension, Element, ElementAttribute, Hierarchy, Subset from TM1py.Services import TM1Service @@ -9,14 +10,6 @@ class TestSubsetService(unittest.TestCase): tm1: TM1Service - prefix = "TM1py_Tests_Subset_" - dimension_name = prefix + "Dimension" - subset_name_static = prefix + "static" - subset_name_dynamic = prefix + "dynamic" - unfriendly_dimension_name = prefix + "Dimension#%AD" - unfriendly_subset_name = prefix + "Subset#%AD" - unfriendly_element_name = prefix + "Element#%AD" - @classmethod def setUpClass(cls): """ @@ -29,6 +22,14 @@ def setUpClass(cls): cls.tm1 = TM1Service(**cls.config["tm1srv01"]) # Define Names + test_uuid = generate_test_uuid() + cls.prefix = "TM1py_Tests_Subset_" + cls.dimension_name = cls.prefix + "Dimension_" + test_uuid + cls.subset_name_static = cls.prefix + "static_" + test_uuid + cls.subset_name_dynamic = cls.prefix + "dynamic_" + test_uuid + cls.unfriendly_dimension_name = cls.prefix + "Dimension#%AD_" + test_uuid + cls.unfriendly_subset_name = cls.prefix + "Subset#%AD_" + test_uuid + cls.unfriendly_element_name = cls.prefix + "Element#%AD_" + test_uuid def setUp(self): # Instantiate Subsets diff --git a/Tests/Utils.py b/Tests/Utils.py index 549f60f9..1d344d7e 100644 --- a/Tests/Utils.py +++ b/Tests/Utils.py @@ -1,9 +1,24 @@ import functools +from uuid import uuid1 from TM1py.Services.RestService import AuthenticationMode from TM1py.Utils.Utils import verify_version +def generate_test_uuid() -> str: + """ + Generate a unique identifier for test objects. + + Creates a UUID-based string suitable for appending to TM1 object names + to ensure test isolation and uniqueness. + + :return: A unique identifier with hyphens replaced by underscores. + :rtype: str + """ + test_uuid = str(uuid1()).replace("-", "_") + return test_uuid + + def skip_if_no_pandas(func): """ Checks whether pandas is installed and skips the test if not