def test_start_time_string_happy_case(self): chore_start_time = ChoreStartTime(year=2020, month=11, day=26, hour=10, minute=11, second=2) self.assertEqual(chore_start_time.start_time_string, "2020-11-26T10:11:02Z")
def test_start_time_string_no_minutes_no_seconds(self): chore_start_time = ChoreStartTime(year=2020, month=11, day=26, hour=10, minute=0, second=0) self.assertEqual(chore_start_time.start_time_string, "2020-11-26T10:00Z")
def test_start_time_string_without_tz(self): chore_start_time = ChoreStartTime(year=2020, month=11, day=26, hour=10, minute=1, second=1) self.assertEqual(chore_start_time.start_time_string, "2020-11-26T10:01:01Z")
def test_3update_chore(self): # get chore c = self.tm1.get_chore(self.chore_name) # update all properties # update start time start_time = datetime.now() c._start_time = ChoreStartTime(start_time.year, start_time.month, start_time.day, start_time.hour, start_time.minute, start_time.second) # update frequency frequency_days = int(random.uniform(0, 355)) frequency_hours = int(random.uniform(0, 23)) frequency_minutes = int(random.uniform(0, 59)) frequency_seconds = int(random.uniform(0, 59)) c._frequency = ChoreFrequency(days=frequency_days, hours=frequency_hours, minutes=frequency_minutes, seconds=frequency_seconds) # update tasks tasks = [ChoreTask(0, 'import_forecast', parameters=[{'Name': 'region', 'Value': 'DE'}]), ChoreTask(1, 'import_forecast', parameters=[{'Name': 'region', 'Value': 'ES'}]), ChoreTask(2, 'import_forecast', parameters=[{'Name': 'region', 'Value': 'US'}])] c._tasks = tasks # execution mode c._execution_mode = "SingleCommit" # active c.deactivate() # update chore in TM1 print(c.body) self.tm1.update_chore(c) # get chore and check all properties c = self.tm1.get_chore(chore_name=self.chore_name) self.assertEqual(c._start_time._datetime, self.start_time.replace(microsecond=0)) self.assertEqual(c._name, self.chore_name) self.assertEqual(c._dst_sensitivity, False) self.assertEqual(c._active, False) self.assertEqual(c._execution_mode, 'SingleCommit') self.assertEqual(c._frequency._days, str(frequency_days)) self.assertEqual(c._frequency._hours, str(frequency_hours).zfill(2)) self.assertEqual(c._frequency._minutes, str(frequency_minutes).zfill(2)) self.assertEqual(c._frequency._seconds, str(frequency_seconds).zfill(2)) for task1, task2 in zip(tasks, c._tasks): self.assertEqual(task1, task2)
def test_1create_chore(self): frequency = ChoreFrequency(days=self.frequency_days, hours=self.frequency_hours, minutes=self.frequency_minutes, seconds=self.frequency_seconds) c = Chore(name=self.chore_name, start_time=ChoreStartTime(self.start_time.year, self.start_time.month, self.start_time.day, self.start_time.hour, self.start_time.minute, self.start_time.second), dst_sensitivity=False, active=True, execution_mode='MultipleCommit', frequency=frequency, tasks=self.tasks) # no exceptions means test passed self.tm1.create_chore(c)
def setUpClass(cls) -> None: # 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) # Build Cube cube = Cube(CUBE_NAME, DIMENSION_NAMES) if not cls.tm1.cubes.exists(CUBE_NAME): cls.tm1.cubes.create(cube) # Build cube view view = NativeView(cube_name=CUBE_NAME, view_name=VIEW_NAME, suppress_empty_columns=True, suppress_empty_rows=True) view.add_row(dimension_name=DIMENSION_NAMES[0], subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[0], expression='{[' + DIMENSION_NAMES[0] + '].Members}')) view.add_row(dimension_name=DIMENSION_NAMES[1], subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[1], expression='{[' + DIMENSION_NAMES[1] + '].Members}')) view.add_column( dimension_name=DIMENSION_NAMES[2], subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[2], expression='{[' + DIMENSION_NAMES[2] + '].Members}')) if not cls.tm1.cubes.views.exists(CUBE_NAME, view.name, private=False): cls.tm1.cubes.views.create(view=view, private=False) # Build subset subset = Subset(SUBSET_NAME, DIMENSION_NAMES[0], DIMENSION_NAMES[0], None, None, ["Element 1"]) if cls.tm1.dimensions.hierarchies.subsets.exists( subset.name, subset.dimension_name, subset.hierarchy_name, False): cls.tm1.dimensions.hierarchies.subsets.delete( subset.name, subset.dimension_name, subset.hierarchy_name, False) cls.tm1.dimensions.hierarchies.subsets.create(subset, False) # Build process p1 = Process(name=PROCESS_NAME) p1.add_parameter('pRegion', 'pRegion (String)', value='US') if cls.tm1.processes.exists(p1.name): cls.tm1.processes.delete(p1.name) cls.tm1.processes.create(p1) # Build chore c1 = Chore(name=CHORE_NAME, start_time=ChoreStartTime(datetime.now().year, datetime.now().month, datetime.now().day, datetime.now().hour, datetime.now().minute, datetime.now().second), dst_sensitivity=False, active=True, execution_mode=Chore.MULTIPLE_COMMIT, frequency=ChoreFrequency(days=int(random.uniform(0, 355)), hours=int(random.uniform(0, 23)), minutes=int(random.uniform(0, 59)), seconds=int(random.uniform(0, 59))), tasks=[ ChoreTask(0, PROCESS_NAME, parameters=[{ 'Name': 'pRegion', 'Value': 'UK' }]) ]) cls.tm1.chores.create(c1) # create Folder app = FolderApplication("", TM1PY_APP_FOLDER) cls.tm1.applications.create(application=app, private=False)
def setUpClass(cls) -> None: """ Establishes a connection to TM1 and creates TM1 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']) # Build Dimensions for dimension_name in cls.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) # Build Cube cube = Cube(cls.cube_name, cls.dimension_names) if not cls.tm1.cubes.exists(cls.cube_name): cls.tm1.cubes.create(cube) # Build cube view view = NativeView(cube_name=cls.cube_name, view_name=cls.view_name, suppress_empty_columns=True, suppress_empty_rows=True) view.add_row( dimension_name=cls.dimension_names[0], subset=AnonymousSubset(dimension_name=cls.dimension_names[0], expression='{[' + cls.dimension_names[0] + '].Members}')) view.add_row( dimension_name=cls.dimension_names[1], subset=AnonymousSubset(dimension_name=cls.dimension_names[1], expression='{[' + cls.dimension_names[1] + '].Members}')) view.add_column( dimension_name=cls.dimension_names[2], subset=AnonymousSubset(dimension_name=cls.dimension_names[2], expression='{[' + cls.dimension_names[2] + '].Members}')) if not cls.tm1.cubes.views.exists( cls.cube_name, view.name, private=False): cls.tm1.cubes.views.create(view=view, private=False) # Build subset subset = Subset(cls.subset_name, cls.dimension_names[0], cls.dimension_names[0], None, None, ["Element 1"]) if cls.tm1.dimensions.hierarchies.subsets.exists( subset.name, subset.dimension_name, subset.hierarchy_name, False): cls.tm1.dimensions.hierarchies.subsets.delete( subset.name, subset.dimension_name, subset.hierarchy_name, False) cls.tm1.dimensions.hierarchies.subsets.create(subset, False) # Build process p1 = Process(name=cls.process_name) p1.add_parameter('pRegion', 'pRegion (String)', value='US') if cls.tm1.processes.exists(p1.name): cls.tm1.processes.delete(p1.name) cls.tm1.processes.create(p1) # Build chore c1 = Chore(name=cls.chore_name, start_time=ChoreStartTime(datetime.now().year, datetime.now().month, datetime.now().day, datetime.now().hour, datetime.now().minute, datetime.now().second), dst_sensitivity=False, active=True, execution_mode=Chore.MULTIPLE_COMMIT, frequency=ChoreFrequency(days=int(random.uniform(0, 355)), hours=int(random.uniform(0, 23)), minutes=int(random.uniform(0, 59)), seconds=int(random.uniform(0, 59))), tasks=[ ChoreTask(0, cls.process_name, parameters=[{ 'Name': 'pRegion', 'Value': 'UK' }]) ]) cls.tm1.chores.create(c1) # create Folder app = FolderApplication("", cls.tm1py_app_folder) cls.tm1.applications.create(application=app, private=False)
from TM1py import TM1pyQueries as TM1, TM1pyLogin, Chore, ChoreFrequency, ChoreTask, ChoreStartTime import uuid from datetime import datetime, date, time # connection to TM1 Server login = TM1pyLogin.native('admin', 'apple') tm1 = TM1(ip='', port=8001, login=login, ssl=False) now = datetime.now() frequency = ChoreFrequency(days='7', hours='9', minutes='2', seconds='45') tasks = [ ChoreTask(0, 'import_actuals', parameters=[{ 'Name': 'region', 'Value': 'UK' }]) ] c = Chore(name='TM1py_' + str(uuid.uuid4()), start_time=ChoreStartTime(now.year, now.month, now.day, now.hour, now.minute, now.second), dst_sensitivity=False, active=True, execution_mode='SingleCommit', frequency=frequency, tasks=tasks) tm1.create_chore(c) tm1.logout()