def setup_class(cls): # hard coded stuff cls.dimension_name = dimension_prefix.format(uuid.uuid4()) cls.hierarchy_name = cls.dimension_name # Connection to TM1 cls.tm1 = TM1Service(**config['tm1srv01']) # Elements cls.years = ("No Year", "1989", "1990", "1991", "1992") cls.extra_year = "4321" # Element Attributes cls.attributes = ('Previous Year', 'Next Year') # create dimension with a default hierarchy d = Dimension(cls.dimension_name) h = Hierarchy(cls.dimension_name, cls.hierarchy_name) h.add_element('Total Years', 'Consolidated') h.add_element('All Consolidations', 'Consolidated') h.add_edge("All Consolidations", "Total Years", 1) for year in cls.years: h.add_element(year, 'Numeric') h.add_edge('Total Years', year, 1) for attribute in cls.attributes: h.add_element_attribute(attribute, "String") d.add_hierarchy(h) cls.tm1.dimensions.create(d) # write one element attribute value cls.tm1.cubes.cells.write_value('1988', '}ElementAttributes_' + cls.dimension_name, ('1989', 'Previous Year'))
def setUp(cls): # Elements cls.years = ("No Year", "1989", "1990", "1991", "1992") cls.extra_year = "4321" # Element Attributes cls.attributes = ('Previous Year', 'Next Year') cls.alias_attributes = ("Financial Year",) # create dimension with a default hierarchy d = Dimension(DIMENSION_NAME) h = Hierarchy(DIMENSION_NAME, HIERARCHY_NAME) h.add_element('Total Years', 'Consolidated') h.add_element('All Consolidations', 'Consolidated') h.add_edge("All Consolidations", "Total Years", 1) for year in cls.years: h.add_element(year, 'Numeric') h.add_edge('Total Years', year, 1) for attribute in cls.attributes: h.add_element_attribute(attribute, "String") for attribute in cls.alias_attributes: h.add_element_attribute(attribute, "Alias") d.add_hierarchy(h) cls.tm1.dimensions.create(d) # write attribute values cls.tm1.cubes.cells.write_value('1988', '}ElementAttributes_' + DIMENSION_NAME, ('1989', 'Previous Year')) cls.tm1.cubes.cells.write_value('1989', '}ElementAttributes_' + DIMENSION_NAME, ('1990', 'Previous Year')) cls.tm1.cubes.cells.write_value('1990', '}ElementAttributes_' + DIMENSION_NAME, ('1991', 'Previous Year')) cls.tm1.cubes.cells.write_value('1991', '}ElementAttributes_' + DIMENSION_NAME, ('1992', 'Previous Year')) cls.tm1.cubes.cells.write_value('1988/89', '}ElementAttributes_' + DIMENSION_NAME, ('1989', 'Financial Year')) cls.tm1.cubes.cells.write_value('1989/90', '}ElementAttributes_' + DIMENSION_NAME, ('1990', 'Financial Year')) cls.tm1.cubes.cells.write_value('1990/91', '}ElementAttributes_' + DIMENSION_NAME, ('1991', 'Financial Year')) cls.tm1.cubes.cells.write_value('1991/92', '}ElementAttributes_' + DIMENSION_NAME, ('1992', 'Financial Year'))
def setUpClass(cls): # Namings cls.prefix = "TM1py_unittest_server_" cls.dimension_name1 = cls.prefix + str(uuid.uuid4()) cls.dimension_name2 = cls.prefix + str(uuid.uuid4()) cls.cube_name = cls.prefix + str(uuid.uuid4()) cls.process_name1 = cls.prefix + str(uuid.uuid4()) cls.process_name2 = cls.prefix + str(uuid.uuid4()) # Connect to TM1 cls.tm1 = TM1Service(**config['tm1srv01']) # create a simple cube with dimensions to test transactionlog methods if not cls.tm1.dimensions.exists(cls.dimension_name1): d = Dimension(cls.dimension_name1) h = Hierarchy(cls.dimension_name1, cls.dimension_name1) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') for year in range(1989, 2040, 1): h.add_element(str(year), 'Numeric') h.add_edge('Total Years', str(year), 1) d.add_hierarchy(h) cls.tm1.dimensions.create(d) if not cls.tm1.dimensions.exists(cls.dimension_name2): d = Dimension(cls.dimension_name2) h = Hierarchy(cls.dimension_name2, cls.dimension_name2) h.add_element('Value', 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) if not cls.tm1.cubes.exists(cls.cube_name): cube = Cube(cls.cube_name, [cls.dimension_name1, cls.dimension_name2]) cls.tm1.cubes.create(cube)
def test1_create_hierarchy(self): d = Dimension(self.dimension_name) h = Hierarchy(self.dimension_name, self.dimension_name) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') h.add_element('1989', 'Numeric') h.add_element_attribute('Previous Year', 'String') h.add_element_attribute('Next Year', 'String') h.add_edge('Total Years', '1989', 2) d.add_hierarchy(h) self.tm1.dimensions.create(d)
def create_dimension(cls): d = Dimension(DIMENSION_NAME) h = Hierarchy(DIMENSION_NAME, DIMENSION_NAME) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') h.add_element('1989', 'Numeric') h.add_element("Marius's Element", "Numeric") h.add_element_attribute('Previous Year', 'String') h.add_element_attribute('Next Year', 'String') h.add_edge('Total Years', '1989', 2) d.add_hierarchy(h) cls.tm1.dimensions.create(d)
def create_dimension(cls): dimension = Dimension(DIMENSION_NAME) hierarchy = Hierarchy(name=DIMENSION_NAME, dimension_name=DIMENSION_NAME) hierarchy.add_element('Total Years', 'Consolidated') hierarchy.add_element('No Year', 'Numeric') hierarchy.add_element('1989', 'Numeric') hierarchy.add_element("My Element", "Numeric") hierarchy.add_element_attribute('Previous Year', 'String') hierarchy.add_element_attribute('Next Year', 'String') hierarchy.add_edge('Total Years', '1989', 2) dimension.add_hierarchy(hierarchy) cls.tm1.dimensions.create(dimension)
def setUpClass(cls): """ Establishes a connection to TM1 and creates TM! objects to use across all tests """ # Connection to TM1 cls.config = configparser.ConfigParser() cls.config.read(Path(__file__).parent.joinpath('config.ini')) cls.tm1 = TM1Service(**cls.config['tm1srv01']) # Namings cls.dimension_name1 = PREFIX + "Dimension1" cls.dimension_name2 = PREFIX + "Dimension2" cls.cube_name = PREFIX + "Cube1" cls.process_name1 = PREFIX + "Process1" cls.process_name2 = PREFIX + "Process2" # create a simple cube with dimensions to test transactionlog methods if not cls.tm1.dimensions.exists(cls.dimension_name1): d = Dimension(cls.dimension_name1) h = Hierarchy(cls.dimension_name1, cls.dimension_name1) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') for year in range(1989, 2040, 1): h.add_element(str(year), 'Numeric') h.add_edge('Total Years', str(year), 1) d.add_hierarchy(h) cls.tm1.dimensions.update_or_create(d) if not cls.tm1.dimensions.exists(cls.dimension_name2): d = Dimension(cls.dimension_name2) h = Hierarchy(cls.dimension_name2, cls.dimension_name2) h.add_element('Value', 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.update_or_create(d) if not cls.tm1.cubes.exists(cls.cube_name): cube = Cube(cls.cube_name, [cls.dimension_name1, cls.dimension_name2]) cls.tm1.cubes.update_or_create(cube) # inject process with ItemReject cls.process1 = Process(name=cls.process_name1, prolog_procedure="ItemReject('TM1py Tests');") cls.tm1.processes.update_or_create(cls.process1) # inject process that does nothing and runs successful cls.process2 = Process(name=cls.process_name2, prolog_procedure="sText = 'text';") cls.tm1.processes.update_or_create(cls.process2) cls.tm1.server.activate_audit_log()
def setUp(cls): # create dimension with a default hierarchy d = Dimension(cls.dimension_name) h = Hierarchy(cls.dimension_name, cls.hierarchy_name) # add elements cls.years = ("No Year", "1989", "1990", "1991", "1992") cls.extra_year = "4321" h.add_element('Total Years', 'Consolidated') h.add_element('All Consolidations', 'Consolidated') h.add_edge("All Consolidations", "Total Years", 1) for year in cls.years: h.add_element(year, 'Numeric') h.add_edge('Total Years', year, 1) # add attributes cls.attributes = ('Previous Year', 'Next Year') cls.alias_attributes = ("Financial Year", ) for attribute in cls.attributes: h.add_element_attribute(attribute, "String") for attribute in cls.alias_attributes: h.add_element_attribute(attribute, "Alias") d.add_hierarchy(h) cls.tm1.dimensions.update_or_create(d) cls.added_attribute_name = "NewAttribute" # write attribute values cls.tm1.cubes.cells.write_value('1988', cls.attribute_cube_name, ('1989', 'Previous Year')) cls.tm1.cubes.cells.write_value('1989', cls.attribute_cube_name, ('1990', 'Previous Year')) cls.tm1.cubes.cells.write_value('1990', cls.attribute_cube_name, ('1991', 'Previous Year')) cls.tm1.cubes.cells.write_value('1991', cls.attribute_cube_name, ('1992', 'Previous Year')) cls.tm1.cubes.cells.write_value('1988/89', cls.attribute_cube_name, ('1989', 'Financial Year')) cls.tm1.cubes.cells.write_value('1989/90', cls.attribute_cube_name, ('1990', 'Financial Year')) cls.tm1.cubes.cells.write_value('1990/91', cls.attribute_cube_name, ('1991', 'Financial Year')) cls.tm1.cubes.cells.write_value('1991/92', cls.attribute_cube_name, ('1992', 'Financial Year')) cls.create_or_update_dimension_with_hierarchies()
def setUpClass(cls): # Connect to TM1 cls.tm1 = TM1Service(**config['tm1srv01']) # Build 4 Dimensions cls.dim1_name = str(uuid.uuid4()) cls.dim1_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim1_name) h = Hierarchy(cls.dim1_name, cls.dim1_name) for element_name in cls.dim1_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.dim2_name = str(uuid.uuid4()) cls.dim2_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim2_name) h = Hierarchy(cls.dim2_name, cls.dim2_name) for element_name in cls.dim2_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.dim3_name = str(uuid.uuid4()) cls.dim3_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim3_name) h = Hierarchy(cls.dim3_name, cls.dim3_name) for element_name in cls.dim3_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.dim4_name = str(uuid.uuid4()) cls.dim4_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim4_name) h = Hierarchy(cls.dim4_name, cls.dim4_name) for element_name in cls.dim4_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) # Build Subset cls.dim4_subset_Name = "TM1pyTests" cls.dim4_subset = cls.tm1.dimensions.subsets.create( Subset(subset_name=cls.dim4_subset_Name, dimension_name=cls.dim4_name, hierarchy_name=cls.dim4_name, expression="HEAD([{}].Members, 1)".format(cls.dim4_name))) # Build Cube with 4 Dimensions cls.cube_name = str(uuid.uuid4()) cube = Cube(name=cls.cube_name, dimensions=[ cls.dim1_name, cls.dim2_name, cls.dim3_name, cls.dim4_name ]) cls.tm1.cubes.create(cube)
def test1_create_hierarchy(self): d = Dimension(self.dimension_name) h = Hierarchy(self.dimension_name, self.dimension_name) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') h.add_element('1989', 'Numeric') h.add_element_attribute('Previous Year', 'String') h.add_element_attribute('Next Year', 'String') h.add_edge('Total Years', '1989', 2) d.add_hierarchy(h) self.tm1.dimensions.create(d) time.sleep(1) s = Subset(self.subset_name, self.dimension_name, self.dimension_name, expression="{{[{}].Members}}".format(self.dimension_name)) self.tm1.dimensions.subsets.create(s, False)
def setUpClass(cls): # Namings cls.dimension_name1 = PREFIX + "Dimension1" cls.dimension_name2 = PREFIX + "Dimension2" cls.cube_name = PREFIX + "Cube1" cls.process_name1 = PREFIX + "Process1" cls.process_name2 = PREFIX + "Process2" # Connect to TM1 cls.tm1 = TM1Service(**config['tm1srv01']) # create a simple cube with dimensions to test transactionlog methods if not cls.tm1.dimensions.exists(cls.dimension_name1): d = Dimension(cls.dimension_name1) h = Hierarchy(cls.dimension_name1, cls.dimension_name1) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') for year in range(1989, 2040, 1): h.add_element(str(year), 'Numeric') h.add_edge('Total Years', str(year), 1) d.add_hierarchy(h) cls.tm1.dimensions.create(d) if not cls.tm1.dimensions.exists(cls.dimension_name2): d = Dimension(cls.dimension_name2) h = Hierarchy(cls.dimension_name2, cls.dimension_name2) h.add_element('Value', 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) if not cls.tm1.cubes.exists(cls.cube_name): cube = Cube(cls.cube_name, [cls.dimension_name1, cls.dimension_name2]) cls.tm1.cubes.create(cube) # inject process with ItemReject cls.process1 = Process(name=cls.process_name1, prolog_procedure="ItemReject('TM1py Tests');") cls.tm1.processes.create(cls.process1) # inject process that does nothing and runs successfull cls.process2 = Process(name=cls.process_name2, prolog_procedure="sText = 'text';") cls.tm1.processes.create(cls.process2)
def setUpClass(cls): """ Establishes a connection to TM1 and creates TM! objects to use across all tests """ # Connection to TM1 cls.config = configparser.ConfigParser() cls.config.read(Path(__file__).parent.joinpath('config.ini')) cls.tm1 = TM1Service(**cls.config['tm1srv01']) cls.prefix = 'TM1py_unittest_element_' cls.dimension_name = f"{cls.prefix}{uuid.uuid4()}" cls.hierarchy_name = cls.dimension_name cls.attribute_cube_name = '}ElementAttributes_' + cls.dimension_name # create dimension with a default hierarchy d = Dimension(cls.dimension_name) h = Hierarchy(cls.dimension_name, cls.hierarchy_name) # add elements cls.years = ("No Year", "1989", "1990", "1991", "1992") cls.extra_year = "4321" h.add_element('Total Years', 'Consolidated') h.add_element('All Consolidations', 'Consolidated') h.add_edge("All Consolidations", "Total Years", 1) for year in cls.years: h.add_element(year, 'Numeric') h.add_edge('Total Years', year, 1) # add attributes cls.attributes = ('Previous Year', 'Next Year') cls.alias_attributes = ("Financial Year",) for attribute in cls.attributes: h.add_element_attribute(attribute, "String") for attribute in cls.alias_attributes: h.add_element_attribute(attribute, "Alias") d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.added_attribute_name = "NewAttribute"
def test_rename_dimension(self): original_dimension_name = self.prefix + "Original_Dimension" renamed_dimension_name = self.prefix + "Renamed_Dimension" # if dimensions exist in TM1.. delete them for dim_name in (original_dimension_name, renamed_dimension_name): if self.tm1.dimensions.exists(dim_name): self.tm1.dimensions.delete(dimension_name=dim_name) # create dimension original_dimension = Dimension(original_dimension_name) hierarchy = Hierarchy(name=original_dimension_name, dimension_name=original_dimension_name) hierarchy.add_element(element_name="Total", element_type="Consolidated") hierarchy.add_element(element_name="Elem1", element_type="Numeric") hierarchy.add_element(element_name="Elem2", element_type="Numeric") hierarchy.add_element(element_name="Elem3", element_type="Numeric") hierarchy.add_edge(parent="Total", component="Elem1", weight=1) hierarchy.add_edge(parent="Total", component="Elem2", weight=1) hierarchy.add_edge(parent="Total", component="Elem3", weight=1) original_dimension.add_hierarchy(hierarchy) self.tm1.dimensions.create(original_dimension) # rename renamed_dimension = self.tm1.dimensions.get(original_dimension.name) renamed_dimension.name = renamed_dimension_name self.tm1.dimensions.create(renamed_dimension) # challenge equality of dimensions summary1 = self.tm1.dimensions.hierarchies.get_hierarchy_summary( dimension_name=original_dimension_name, hierarchy_name=original_dimension_name) summary2 = self.tm1.dimensions.hierarchies.get_hierarchy_summary( dimension_name=renamed_dimension_name, hierarchy_name=renamed_dimension_name) self.assertEqual(summary1, summary2) # delete for dim_name in (original_dimension_name, renamed_dimension_name): self.tm1.dimensions.delete(dimension_name=dim_name)
def create_dimension_with_multiple_hierarchies(cls): dimension = Dimension(cls.dimension_name_with_multi_hierarchy) dimension.add_hierarchy( Hierarchy(name="Hierarchy1", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) dimension.add_hierarchy( Hierarchy(name="Hierarchy2", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) dimension.add_hierarchy( Hierarchy(name="Hierarchy3", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) cls.tm1.dimensions.create(dimension)
def create_dimension_with_multiple_hierarchies(cls): dimension = Dimension(DIMENSION_NAME_WITH_MULTI_HIERARCHY) dimension.add_hierarchy( Hierarchy(name="Hierarchy1", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) dimension.add_hierarchy( Hierarchy(name="Hierarchy2", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) dimension.add_hierarchy( Hierarchy(name="Hierarchy3", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) cls.tm1.dimensions.create(dimension)
def create_or_update_dimension_with_hierarchies(cls): dimension = Dimension(cls.dimension_with_hierarchies_name) dimension.add_hierarchy( Hierarchy(name="Hierarchy1", dimension_name=dimension.name, elements=[ Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric") ])) dimension.add_hierarchy( Hierarchy(name="Hierarchy2", dimension_name=dimension.name, elements=[ Element("Elem4", "Numeric"), Element("Elem6", "Numeric"), Element("Cons1", "Consolidated") ])) dimension.add_hierarchy( Hierarchy(name="Hierarchy3", dimension_name=dimension.name, elements=[ Element("Elem5", "Numeric"), Element("Cons2", "Consolidated"), Element("Cons3", "Consolidated") ])) cls.tm1.dimensions.update_or_create(dimension)
def setUpClass(cls): # Connect to TM1 cls.tm1 = TM1Service(**config['tm1srv01']) # Build 4 Dimensions cls.dim1_name = str(uuid.uuid4()) cls.dim1_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim1_name) h = Hierarchy(cls.dim1_name, cls.dim1_name) for element_name in cls.dim1_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.dim2_name = str(uuid.uuid4()) cls.dim2_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim2_name) h = Hierarchy(cls.dim2_name, cls.dim2_name) for element_name in cls.dim2_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.dim3_name = str(uuid.uuid4()) cls.dim3_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim3_name) h = Hierarchy(cls.dim3_name, cls.dim3_name) for element_name in cls.dim3_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) cls.dim4_name = str(uuid.uuid4()) cls.dim4_element_names = [str(uuid.uuid4()) for _ in range(10)] d = Dimension(cls.dim4_name) h = Hierarchy(cls.dim4_name, cls.dim4_name) for element_name in cls.dim4_element_names: h.add_element(element_name, 'Numeric') d.add_hierarchy(h) cls.tm1.dimensions.create(d) # Build Cube with 4 Dimensions cls.cube_name = str(uuid.uuid4()) cube = Cube(name=cls.cube_name, dimensions=[ cls.dim1_name, cls.dim2_name, cls.dim3_name, cls.dim4_name ]) cls.tm1.cubes.create(cube)
def setUpClass(cls): # Namings cls.expand_process_name = str(uuid.uuid4()) cls.expand_process_name_obf = str(uuid.uuid4()) cls.process_name = str(uuid.uuid4()) cls.process_name_obf = str(uuid.uuid4()) cls.dimension_name = str(uuid.uuid4()) cls.dimension_name_cloned = str(uuid.uuid4()) cls.cube_name = str(uuid.uuid4()) cls.cube_name_cloned = str(uuid.uuid4()) # Connect to TM1 cls.tm1 = TM1Service(**config['tm1srv01']) # create process prolog = "\r\nSaveDataAll;\r\nsText='abcABC';\r\n" epilog = "SaveDataAll;" cls.process = Process( name=cls.process_name, prolog_procedure=prolog, epilog_procedure=epilog) # create process with expand in TM1 if cls.tm1.processes.exists(cls.process.name): cls.tm1.processes.delete(cls.process.name) cls.tm1.processes.create(cls.process) # create process with expand prolog = "\r\nnRevenue = 20;\r\nsRevenue = EXPAND('%nrevenue%');\r\nIF(sRevenue @ <> '20.000');\r\n" \ "ProcessBreak;\r\nENDIF;" cls.expand_process = Process( name=cls.expand_process_name, prolog_procedure=prolog) # create process with expand in TM1 if cls.tm1.processes.exists(cls.expand_process.name): cls.tm1.processes.delete(cls.expand_process.name) cls.tm1.processes.create(cls.expand_process) # create dimension that we clone through obfuscated bedrock as part of the test if not cls.tm1.dimensions.exists(cls.dimension_name): d = Dimension(cls.dimension_name) h = Hierarchy(cls.dimension_name, cls.dimension_name) h.add_element('Total Years', 'Consolidated') h.add_element('No Year', 'Numeric') for year in range(1989, 2040, 1): h.add_element(str(year), 'Numeric') h.add_edge('Total Years', str(year), 1) d.add_hierarchy(h) cls.tm1.dimensions.create(d) # Create 2 Attributes through TI ti_statements = ["AttrInsert('{}','','Previous Year', 'S')".format(cls.dimension_name), "AttrInsert('{}','','Next Year', 'S');".format(cls.dimension_name)] ti = ';'.join(ti_statements) cls.tm1.processes.execute_ti_code(lines_prolog=ti) # create }ElementAttribute values cellset = {} for year in range(1989, 2040, 1): cellset[(str(year), 'Previous Year')] = year - 1 cellset[(str(year), 'Next Year')] = year + 1 cls.tm1.cubes.cells.write_values("}ElementAttributes_" + cls.dimension_name, cellset) # create a simple cube to be cloned through bedrock if not cls.tm1.cubes.exists(cls.cube_name): cube = Cube(cls.cube_name, ["}Dimensions", "}Cubes"], "[]=S:'TM1py';") cls.tm1.cubes.create(cube) # create bedrocks if they doesn't exist for bedrock in ("Bedrock.Dim.Clone", "Bedrock.Cube.Clone"): if not cls.tm1.processes.exists(bedrock): with open(os.path.join("resources", bedrock + ".json"), "r") as file: process = Process.from_json(file.read()) cls.tm1.processes.create(process)
def setUpClass(cls): """ Establishes a connection to TM1 and creates TM! objects to use across all tests """ # Connection to TM1 cls.config = configparser.ConfigParser() cls.config.read(Path(__file__).parent.joinpath('config.ini')) cls.tm1 = TM1Service(**cls.config['tm1srv01']) # generate random coordinates cls.target_coordinates = list( zip(('Element ' + str(e) for e in range(1, 100)), ('Element ' + str(e) for e in range(1, 100)), ('Element ' + str(e) for e in range(1, 100)))) # Build Dimensions for dimension_name in DIMENSION_NAMES: elements = [ Element('Element {}'.format(str(j)), 'Numeric') for j in range(1, 1001) ] element_attributes = [ ElementAttribute("Attr1", "String"), ElementAttribute("Attr2", "Numeric"), ElementAttribute("Attr3", "Numeric") ] hierarchy = Hierarchy(dimension_name=dimension_name, name=dimension_name, elements=elements, element_attributes=element_attributes) dimension = Dimension(dimension_name, [hierarchy]) if cls.tm1.dimensions.exists(dimension.name): cls.tm1.dimensions.update(dimension) else: cls.tm1.dimensions.create(dimension) attribute_cube = "}ElementAttributes_" + dimension_name attribute_values = dict() for element in elements: attribute_values[(element.name, "Attr1")] = "TM1py" attribute_values[(element.name, "Attr2")] = "2" attribute_values[(element.name, "Attr3")] = "3" cls.tm1.cubes.cells.write_values(attribute_cube, attribute_values) # Build Cube cube = Cube(CUBE_NAME, DIMENSION_NAMES) if not cls.tm1.cubes.exists(CUBE_NAME): cls.tm1.cubes.create(cube) # Sum of all the values that we write in the cube. serves as a checksum. cls.total_value = 0 # cellset of data that shall be written cls.cellset = {} for element1, element2, element3 in cls.target_coordinates: value = 1 cls.cellset[(element1, element2, element3)] = value # update the checksum cls.total_value += value # Fill cube with values cls.tm1.cubes.cells.write_values(CUBE_NAME, cls.cellset) # Elements cls.years = ("No Year", "1989", "1990", "1991", "1992") cls.extra_year = "4321" # Element Attributes cls.attributes = ('Previous Year', 'Next Year') cls.alias_attributes = ("Financial Year", ) # create dimension with a default hierarchy d = Dimension(DIMENSION_NAME) h = Hierarchy(DIMENSION_NAME, DIMENSION_NAME) h.add_element('Total Years', 'Consolidated') h.add_element('All Consolidations', 'Consolidated') h.add_edge("All Consolidations", "Total Years", 1) for year in cls.years: h.add_element(year, 'Numeric') h.add_edge('Total Years', year, 1) for attribute in cls.attributes: h.add_element_attribute(attribute, "String") for attribute in cls.alias_attributes: h.add_element_attribute(attribute, "Alias") d.add_hierarchy(h) cls.tm1.dimensions.update_or_create(d) # write attribute values cls.tm1.cubes.cells.write_value('1988', '}ElementAttributes_' + DIMENSION_NAME, ('1989', 'Previous Year')) cls.tm1.cubes.cells.write_value('1989', '}ElementAttributes_' + DIMENSION_NAME, ('1990', 'Previous Year')) cls.tm1.cubes.cells.write_value('1990', '}ElementAttributes_' + DIMENSION_NAME, ('1991', 'Previous Year')) cls.tm1.cubes.cells.write_value('1991', '}ElementAttributes_' + DIMENSION_NAME, ('1992', 'Previous Year')) cls.tm1.cubes.cells.write_value('1988/89', '}ElementAttributes_' + DIMENSION_NAME, ('1989', 'Financial Year')) cls.tm1.cubes.cells.write_value('1989/90', '}ElementAttributes_' + DIMENSION_NAME, ('1990', 'Financial Year')) cls.tm1.cubes.cells.write_value('1990/91', '}ElementAttributes_' + DIMENSION_NAME, ('1991', 'Financial Year')) cls.tm1.cubes.cells.write_value('1991/92', '}ElementAttributes_' + DIMENSION_NAME, ('1992', 'Financial Year'))