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
4 changes: 2 additions & 2 deletions Tests/AnnotationService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions Tests/ElementService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"

Expand Down
17 changes: 9 additions & 8 deletions Tests/SubsetService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
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


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):
"""
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Tests/Utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down