def test3_update_process(self): # get p = self.tm1.get_process(self.p_ascii.name) # modify p.set_data_procedure(Process.auto_generated_string() + "SaveDataAll;") # update on Server self.tm1.update_process(p) # get again p_ascii_updated = self.tm1.get_process(p.name) # assert self.assertNotEqual(p_ascii_updated.data_procedure, self.p_ascii.data_procedure)
def clear_cube_cache(self): process = Process( name="", prolog_procedure= f"DebugUtility(125 ,0 ,0 ,'{self.cube_name}' ,'' ,'');") success, status, error_log_file = self.tm1.processes.execute_process_with_return( process) if not success: raise RuntimeError( f"Failed to clear cache for cube '{self.cube_name}'. Status: '{status}'" )
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 TM1Queries, Process import uuid # connection to TM1 Server q = TM1Queries(ip='', port=8008, user='******', password='******', ssl=True) # just a random string random_string = str(uuid.uuid4()).replace('-', '_') # create new Process p_ascii = Process(name='unittest_ascii_' + random_string, datasource_type='ASCII', datasource_ascii_delimiter_char=',', datasource_data_source_name_for_server='C:\Data\simple_csv.csv', datasource_data_source_name_for_client='C:\Data\simple_csv.csv') # variables p_ascii.add_variable('v_1', 'Numeric') p_ascii.add_variable('v_2', 'Numeric') p_ascii.add_variable('v_3', 'Numeric') p_ascii.add_variable('v_4', 'Numeric') # parameters p_ascii.add_parameter('p_Year', 'year?', '2016') # create process on Server q.create_process(p_ascii) # update existing Process: p_new = q.get_process(p_ascii.name) # modify p_new.set_data_procedure(Process.auto_generated_string() + "x = 'Hi this is a test';") # update on Server q.update_process(p_new) # delete Process from Server
from TM1py import TM1pyQueries as TM1, TM1pyLogin, Process import uuid # connection to TM1 Server login = TM1pyLogin.native('admin', 'apple') tm1 = TM1(ip='', port=8001, login=login, ssl=False) # just a random string process_name = 'TM1py process' # create new Process p_ascii = Process(name=process_name, datasource_type='ASCII', datasource_ascii_delimiter_char=',', datasource_data_source_name_for_server=r'C:\Data\file.csv', datasource_data_source_name_for_client=r'C:\Data\file.csv') # variables p_ascii.add_variable('v_1', 'Numeric') p_ascii.add_variable('v_2', 'Numeric') p_ascii.add_variable('v_3', 'Numeric') p_ascii.add_variable('v_4', 'Numeric') # parameters p_ascii.add_parameter(name='CompanyCode', prompt='', value='DE04') # create process on Server tm1.create_process(p_ascii) # logout tm1.logout()
def put_turbointegrator(self, active_view): process_name = self.active_file_base sublime.status_message( 'Processing server update of ti process: {}'.format(process_name)) try: process = self._session.processes.get(process_name) update_process = True except TM1pyException as e: process = Process(name=process_name) update_process = False regions = active_view.split_by_newlines( sublime.Region(0, active_view.size())) text = [ active_view.substr(region).rstrip() + '\n' for region in regions ] # Parse Sections sections = [ 'PARAMETERS', 'DATASOURCE', 'VARIABLES', 'PROLOG', 'METADATA', 'DATA', 'EPILOG' ] section_text = {} comment_line = '###############################################################################' for section in sections: parse_section = section section_text[parse_section] = '' regex_find = re.compile('^(#+\s*?)?(' + parse_section + ')(:|;)') regex_end = re.compile('^(#+\s*?)?({})(:|;)'.format( '|'.join(sections))) search_active = False for line in text: if search_active and not regex_end.search( line) and line.rstrip() != comment_line: section_text[parse_section] += line.rstrip() + '\n' if regex_end.search(line) and search_active: break if regex_find.search(line) and not search_active: search_active = True for section in ['PARAMETERS', 'DATASOURCE', 'VARIABLES']: section_text[section] = section_text[section].replace("### ", "") parameters = yaml.load(section_text['PARAMETERS']) if parameters == 'None': parameters = [] for parameter in process.parameters.copy(): process.remove_parameter(parameter['Name']) for parameter in parameters: process.add_parameter(parameter['name'], parameter['prompt'], parameter['value']) # Datasource datasource = yaml.load(section_text['DATASOURCE']) if datasource == 'None': datasource = {'type': 'None'} for key, item in datasource.items(): obj_key = 'datasource_' + key try: if obj_key in dir(process): setattr(process, '' + obj_key, item) else: print('encountered unknown datasource setting: ' + key) except Exception as e: sublime.message_dialog( 'An error occurred updating {}\n\n{}'.format( process_name, e)) raise # Variables variables = yaml.load(section_text['VARIABLES']) for variable in process.variables.copy(): process.remove_variable(variable['Name']) if variables != 'None': for x in variables: if '(Numeric)' in x['name']: var_type = 'Numeric' var_name = x['name'].replace('(Numeric)', '') else: var_type = 'String' var_name = x['name'].replace('(String)', '') var_name = var_name.strip() process.add_variable(var_name, var_type) process.prolog_procedure = section_text['PROLOG'].strip() process.metadata_procedure = section_text['METADATA'].strip() process.data_procedure = section_text['DATA'].strip() process.epilog_procedure = section_text['EPILOG'].strip() try: if not update_process: self._session.processes.create(process) else: self._session.processes.update(process) errors = self._session.processes.compile(process_name) if errors: sublime.message_dialog( 'Error compiling {}: \n\nProcedure: {} (~Line {})\n\n{}'. format(process_name, errors[0]['Procedure'], str(errors[0]['LineNumber']), errors[0]['Message'])) else: sublime.message_dialog( 'Updated {} TI Process Successfully'.format(process_name)) except Exception as e: sublime.message_dialog( 'An error occurred updating {}\n\n{}'.format(process_name, e)) raise
from TM1py import TM1pyQueries as TM1, TM1pyLogin, Process import uuid # connection to TM1 Server login = TM1pyLogin.native('admin', 'apple') tm1 = TM1(ip='', port=8001, login=login, ssl=False) #read Process: p = tm1.get_process('TM1py process') # modify p.set_data_procedure(Process.auto_generated_string() + "a = 2;") # update on Server tm1.update_process(p) # logout tm1.logout()
from TM1py import TM1pyQueries as TM1, TM1pyLogin, Process import uuid # connection to TM1 Server login = TM1pyLogin.native('admin', 'apple') tm1 = TM1(ip='', port=8001, login=login, ssl=False) # just a random string random_string = str(uuid.uuid4()) # create new Process p_ascii = Process( name='sample_ascii_' + random_string, datasource_type='ASCII', datasource_ascii_delimiter_char=',', datasource_data_source_name_for_server='C:\Data\just_a_file.csv', datasource_data_source_name_for_client='C:\Data\just_a_file.csv') # variables p_ascii.add_variable('v_1', 'Numeric') p_ascii.add_variable('v_2', 'Numeric') p_ascii.add_variable('v_3', 'Numeric') p_ascii.add_variable('v_4', 'Numeric') # parameters p_ascii.add_parameter(name='CompanyCode', prompt='', value='DE04') # create process on Server tm1.create_process(p_ascii) # update existing Process:
class TestAnnotationMethods(unittest.TestCase): login = TM1pyLogin.native('admin', 'apple') tm1 = TM1(ip='', port=8001, login=login, ssl=False) random_string = str(uuid.uuid4()) # none process p_none = Process(name='}TM1py_unittest_none_' + random_string, datasource_type='None') # ascii process p_ascii = Process(name='}TM1py_unittest_ascii_' + random_string, datasource_type='ASCII', datasource_ascii_delimiter_type='Character', datasource_ascii_delimiter_char=',', datasource_ascii_header_records=2, datasource_ascii_quote_character='^', datasource_ascii_thousand_separator='~', prolog_procedure=Process.auto_generated_string() + ' test prolog procedure', metadata_procedure=Process.auto_generated_string() + ' test metadata procedure', data_procedure=Process.auto_generated_string() + ' test data procedure', epilog_procedure=Process.auto_generated_string() + ' test epilog procedure', datasource_data_source_name_for_server='C:\Data\file.csv', datasource_data_source_name_for_client='C:\Data\file.csv') # variables p_ascii.add_variable('v_1', 'Numeric') p_ascii.add_variable('v_2', 'Numeric') p_ascii.add_variable('v_3', 'Numeric') p_ascii.add_variable('v_4', 'Numeric') # parameters p_ascii.add_parameter('p_Year', 'year?', '2016') # view process p_view = Process(name='}TM1py_unittest_view_' + random_string, datasource_type='TM1CubeView', datasource_view='view1', datasource_data_source_name_for_client='Plan_BudgetPlan', datasource_data_source_name_for_server='Plan_BudgetPlan') # odbc process p_odbc = Process(name='}TM1py_unittest_odbc_' + random_string, datasource_type='ODBC', datasource_password='******', datasource_user_name='user') # create Process def test1_create_process(self): self.tm1.create_process(self.p_none) self.tm1.create_process(self.p_ascii) self.tm1.create_process(self.p_view) self.tm1.create_process(self.p_odbc) # get Process def test2_get_process(self): p1 = self.tm1.get_process(self.p_ascii.name) self.assertEqual(p1.body, self.p_ascii.body) p2 = self.tm1.get_process(self.p_none.name) self.assertEqual(p2.body, self.p_none.body) p3 = self.tm1.get_process(self.p_view.name) self.assertEqual(p3.body, self.p_view.body) p4 = self.tm1.get_process(self.p_odbc.name) p4.datasource_password = None self.p_odbc.datasource_password = None self.assertEqual(p4.body, self.p_odbc.body) # update process def test3_update_process(self): # get p = self.tm1.get_process(self.p_ascii.name) # modify p.set_data_procedure(Process.auto_generated_string() + "SaveDataAll;") # update on Server self.tm1.update_process(p) # get again p_ascii_updated = self.tm1.get_process(p.name) # assert self.assertNotEqual(p_ascii_updated.data_procedure, self.p_ascii.data_procedure) # delete process def test4_delete_process(self): self.tm1.delete_process(self.p_none.name) self.tm1.delete_process(self.p_ascii.name) self.tm1.delete_process(self.p_view.name) self.tm1.delete_process(self.p_odbc.name) def test5_logout(self): self.tm1.logout()
from TM1py import TM1pyQueries as TM1, TM1pyLogin, Process import uuid # connection to TM1 Server login = TM1pyLogin.native('admin', 'apple') tm1 = TM1(ip='', port=8001, login=login, ssl=False) # just a random string random_string = str(uuid.uuid4()) # create new Process p_ascii = Process(name='sample_ascii_' + random_string, datasource_type='ASCII', datasource_ascii_delimiter_char=',', datasource_data_source_name_for_server='C:\Data\just_a_file.csv', datasource_data_source_name_for_client='C:\Data\just_a_file.csv') # variables p_ascii.add_variable('v_1', 'Numeric') p_ascii.add_variable('v_2', 'Numeric') p_ascii.add_variable('v_3', 'Numeric') p_ascii.add_variable('v_4', 'Numeric') # parameters p_ascii.add_parameter(name='CompanyCode', prompt='', value='DE04') # create process on Server tm1.create_process(p_ascii) # update existing Process: p_new = tm1.get_process(p_ascii.name)