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 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 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 add_other_hierarchy(self): dimension = self.tm1.dimensions.get(DIMENSION_NAME) # other hierarchy hierarchy = Hierarchy(name="Other Hierarchy", dimension_name=DIMENSION_NAME) hierarchy.add_element('Other Total Years', 'Consolidated') hierarchy.add_element('No Year', 'Numeric') hierarchy.add_element('1989', 'Numeric') hierarchy.add_element("Element With ' in the name", "Numeric") hierarchy.add_element_attribute('Previous Year', 'String') hierarchy.add_element_attribute('Next Year', 'String') hierarchy.add_edge('Other Total Years', '1989', 2) dimension.add_hierarchy(hierarchy) self.tm1.dimensions.update(dimension)
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 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): """ 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 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'))