示例#1
0
class TestAnnotationMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)

    random_string = str(uuid.uuid4())
    subset_name_static = 'TM1py_unittest_static_subset_' + random_string
    subset_name_dynamic = 'TM1py_unittest_dynamic_subset_' + random_string

    # 1. create subset
    def test_1create_subset(self):
        s = Subset(dimension_name='plan_business_unit',
                   subset_name=self.subset_name_static,
                   alias='BusinessUnit',
                   elements=['10110', '10300', '10210', '10000'])
        self.tm1.create_subset(s)

        s = Subset(dimension_name='plan_business_unit',
                   subset_name=self.subset_name_dynamic,
                   alias='BusinessUnit',
                   expression=
                   '{ HIERARCHIZE( {TM1SUBSETALL( [plan_business_unit] )} ) }')
        self.tm1.create_subset(s)

    # 2. get subset
    def test_2get_subset(self):
        s = self.tm1.get_subset(dimension_name='plan_business_unit',
                                subset_name=self.subset_name_static)
        self.assertIsInstance(s, Subset)

        s = self.tm1.get_subset(dimension_name='plan_business_unit',
                                subset_name=self.subset_name_dynamic)
        self.assertIsInstance(s, Subset)

    # 3. update subset
    def test_3update_subset(self):
        s = self.tm1.get_subset(dimension_name='plan_business_unit',
                                subset_name=self.subset_name_static)
        s.add_elements(['10110'])
        self.tm1.update_subset(s)

        s = self.tm1.get_subset(dimension_name='plan_business_unit',
                                subset_name=self.subset_name_dynamic)
        s.set_expression(
            '{ HIERARCHIZE( {TM1SUBSETALL( [plan_business_unit] )} ) }')
        self.tm1.update_subset(s)

    # 4. delete subset
    def test_4delete_subset(self):
        self.tm1.delete_subset(dimension_name='plan_business_unit',
                               subset_name=self.subset_name_static)
        self.tm1.delete_subset(dimension_name='plan_business_unit',
                               subset_name=self.subset_name_dynamic)

    def test_5logout(self):
        self.tm1.logout()
示例#2
0
async def main():
    loop = asyncio.get_event_loop()
    tm1 = TM1('', 8001, TM1pyLogin.native('admin', 'apple'), ssl=False)
    future1 = loop.run_in_executor(None, get_product_version, tm1)
    future2 = loop.run_in_executor(None, get_server_name, tm1)
    future3 = loop.run_in_executor(None, read_pnl, tm1)
    future4 = loop.run_in_executor(None, get_all_dimension_names, tm1)
    future5 = loop.run_in_executor(None, get_all_process_names, tm1)
    response1, response, response3, response4, response5 = \
        await future1, await future2, await future3, await future4, await future5
    tm1.logout()
示例#3
0
class TestUserMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)

    user_name = str(uuid.uuid4())

    def test1_create_user(self):
        all_users_before = self.tm1.get_all_users()
        u = User(name=self.user_name, groups=[], password='******')
        self.tm1.create_user(u)
        all_users_after = self.tm1.get_all_users()
        # test it!
        self.assertEqual(len(all_users_before) + 1, len(all_users_after))

    def test2_get_user(self):
        u = self.tm1.get_user(self.user_name)
        # test it !
        self.assertIsInstance(u, User)

    def test3_update_user(self):
        # get user
        u = self.tm1.get_user(self.user_name)
        # update user. Add Group
        u.add_group('10110')
        self.tm1.update_user(u)
        # test it !
        groups = self.tm1.get_groups_from_user(u.name)
        self.assertIn('10110', groups)
        # update user. Remove Group
        u.remove_group('10110')
        self.tm1.update_user(u)
        # test it !
        groups = self.tm1.get_groups_from_user(u.name)
        self.assertNotIn('10110', groups)


    def test4_delete_user(self):
        users_before = self.tm1.get_all_users()
        self.tm1.delete_user(self.user_name)
        users_after = self.tm1.get_all_users()

        # test it !
        self.assertEqual(len(users_before) - 1, len(users_after))


    def test5_logout(self):
        self.tm1.logout()
示例#4
0
文件: Cube.py 项目: jischebeck/TM1py
class TestCubeMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)

    cube_name = 'TM1py_unittest_cube_{}'.format(str(uuid.uuid4()))

    def test1_create_cube(self):
        all_cubes_before = self.tm1.get_all_cube_names()
        c = Cube(self.cube_name,
                 dimensions=['plan_version', 'plan_business_unit'],
                 rules=Rules(''))
        self.tm1.create_cube(c)
        all_cubes_after = self.tm1.get_all_cube_names()
        self.assertEqual(len(all_cubes_before) + 1, len(all_cubes_after))

    def test2_get_cube(self):
        c = self.tm1.get_cube(self.cube_name)
        self.assertIsInstance(c, Cube)

        cubes = self.tm1.get_all_cubes()
        control_cubes = self.tm1.get_control_cubes()
        model_cubes = self.tm1.get_model_cubes()
        self.assertEqual(len(cubes), len(control_cubes + model_cubes))

    def test3_update_cube(self):
        c = self.tm1.get_cube(self.cube_name)
        c.rules = Rules("SKIPCHECK;\nFEEDERS;")
        self.tm1.update_cube(c)
        # test if rule was actually updated
        c = self.tm1.get_cube(self.cube_name)
        self.assertTrue(c.skipcheck)

    def test4_delete_cube(self):
        all_cubes_before = self.tm1.get_all_cube_names()
        self.tm1.delete_cube(self.cube_name)
        all_cubes_after = self.tm1.get_all_cube_names()
        self.assertEqual(len(all_cubes_before) - 1, len(all_cubes_after))

    def test5_logout(self):
        self.tm1.logout()
示例#5
0
from TM1py import TM1pyQueries as TM1, TM1pyLogin
from pandas import pandas as pd

login = TM1pyLogin.native('admin', 'apple')

# connect to TM1
with TM1(ip='', port=8001, login=login, ssl=False) as tm1:
    # get data from P&L cube
    pnl_data = tm1.get_view_content(cube_name='Plan_BudgetPlan',
                                    view_name='High Level Profit And Loss',
                                    cell_properties=['Ordinal', 'Value'],
                                    private=False)

    # restructure data
    pnl_data_clean = {}
    for item in pnl_data:
        coordinates = []
        for entry in item:
            coordinates.append(entry[entry.find('].[') + 3:-1])
        pnl_data_clean[tuple(coordinates)] = pnl_data[item]['Value']

    # create index
    names = tm1.get_dimension_order('Plan_BudgetPlan')
    keylist = list(pnl_data_clean.keys())
    multiindex = pd.MultiIndex.from_tuples(keylist, names=names)

    # create DataFrame
    values = list(pnl_data_clean.values())
    df = pd.DataFrame(values, index=multiindex)

    # print DataFrame
示例#6
0
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)

# delete Process:
p = tm1.delete_process('TM1py process')

# logout
p.logout()

示例#7
0
from TM1py import TM1pyQueries as TM1, TM1pyLogin

# connect to TM1 source instance
tm1_source = TM1(ip='',
                 port=8001,
                 login=TM1pyLogin.native('admin', 'apple'),
                 ssl=False)

# connect to TM1 target instance
tm1_target = TM1(ip='',
                 port=8002,
                 login=TM1pyLogin.native('admin', 'apple'),
                 ssl=False)

# read process from source
p = tm1_source.get_process('import_actuals')

# create process on target instance
tm1_target.create_process(p)

# explicit logout, since HTTPSessionTimeoutMinutes doesnt work
tm1_source.logout()
tm1_target.logout()
示例#8
0
文件: Process.py 项目: zPat/TM1py
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()
示例#9
0
class TestDimensionMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)

    dimension_name = 'TM1py_unittest_dimension_{}'.format(int(uuid.uuid4()))
    hierarchy_name = dimension_name

    def test1_create_dimension(self):
        root_element = Element(name='Root', element_type='Consolidated')
        elements = [root_element]
        edges = []
        for i in range(1000):
            element_name = str(uuid.uuid4())
            elements.append(Element(name=element_name, element_type='Numeric'))
            edges.append(
                Edge(parent_name='Root', component_name=element_name,
                     weight=i))
        h = Hierarchy(name=self.dimension_name,
                      dimension_name=self.dimension_name,
                      elements=elements,
                      edges=edges)
        d = Dimension(name=self.dimension_name, hierarchies=[h])
        # create it
        self.tm1.create_dimension(d)

        # Test
        dimensions = self.tm1.get_all_dimension_names()
        self.assertIn(self.dimension_name, dimensions)

    def test2_get_dimension(self):
        # get it
        d = self.tm1.get_dimension(dimension_name=self.dimension_name)

        # Test
        self.assertEqual(len(d.hierarchies[0].elements), 1001)

    def test3_update_dimension(self):
        # get dimension from tm1
        d = self.tm1.get_dimension(dimension_name=self.dimension_name)
        # create element objects
        elements = [
            Element(name='e1', element_type='Consolidated'),
            Element(name='e2', element_type='Numeric'),
            Element(name='e3', element_type='Numeric'),
            Element(name='e4', element_type='Numeric')
        ]
        # create edge objects
        edges = [
            Edge(parent_name='e1', component_name='e2', weight=1),
            Edge(parent_name='e1', component_name='e3', weight=1),
            Edge(parent_name='e1', component_name='e4', weight=1)
        ]
        # create the element_attributes objects
        element_attributes = [
            ElementAttribute(name='Name Long', attribute_type='Alias'),
            ElementAttribute(name='Name Short', attribute_type='Alias'),
            ElementAttribute(name='Currency', attribute_type='String')
        ]
        # create hierarchy object
        hierarchy = Hierarchy(name=self.dimension_name,
                              dimension_name=self.dimension_name,
                              elements=elements,
                              element_attributes=element_attributes,
                              edges=edges)

        # replace existing hierarchy with new hierarchy
        d.remove_hierarchy(self.dimension_name)
        d.add_hierarchy(hierarchy)

        # update dimension in TM1
        self.tm1.update_dimension(d)

        # Test
        dimension = self.tm1.get_dimension(self.dimension_name)
        self.assertEqual(len(dimension.hierarchies[0].elements), len(elements))

    def test4_delete_dimension(self):
        dimensions_before = self.tm1.get_all_dimension_names()
        self.tm1.delete_dimension(self.dimension_name)
        dimensions_after = self.tm1.get_all_dimension_names()

        # Test
        self.assertIn(self.dimension_name, dimensions_before)
        self.assertNotIn(self.dimension_name, dimensions_after)
示例#10
0
文件: Chore.py 项目: vicmora/TM1py
class TestChoreMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)

    # chore properties
    chore_name = 'TM1py_unittest_chore_' + str(uuid.uuid4())
    start_time = datetime.now()
    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))

    tasks = [ChoreTask(0, 'import_actuals', parameters=[{'Name': 'region', 'Value': 'UK'}]),
             ChoreTask(1, 'import_actuals', parameters=[{'Name': 'region', 'Value': 'FR'}]),
             ChoreTask(2, 'import_actuals', parameters=[{'Name': 'region', 'Value': 'CH'}])]

    # 1. create chore
    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)

    # 2. get chore
    def test_2get_chore(self):
        c = self.tm1.get_chore(self.chore_name)
        # check all properties
        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, True)
        self.assertEqual(c._execution_mode, 'MultipleCommit')
        self.assertEqual(c._frequency._days, str(self.frequency_days))
        self.assertEqual(c._frequency._hours, str(self.frequency_hours).zfill(2))
        self.assertEqual(c._frequency._minutes, str(self.frequency_minutes).zfill(2))
        self.assertEqual(c._frequency._seconds, str(self.frequency_seconds).zfill(2))
        for task1, task2 in zip(self.tasks, c._tasks):
            self.assertEqual(task1, task2)

    # 3. update chore
    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)

    # 4. delete chore
    def test_4delete_chore(self):
        self.tm1.delete_chore(self.chore_name)

    # logout
    def test_5logout(self):
        pass
        self.tm1.logout()
示例#11
0
文件: View.py 项目: jischebeck/TM1py
class TestViewMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)
    random_string = str(uuid.uuid4())
    random_boolean = bool(random.getrandbits(1))

    native_view_name = 'TM1py_unittest_native_view_' + random_string
    mdx_view_name = 'TM1py_unittest_mdx_view_' + random_string

    def test0_get_all_views(self):
        views = self.tm1.get_all_views('Plan_BudgetPlan')
        self.assertGreater(len(views), 0)

    def test1_create_view(self):
        # create instance of native View
        native_view = NativeView(cube_name='Plan_BudgetPlan',
                                 view_name=self.native_view_name)

        # set up native view - put subsets on Rows, Columns and Titles
        subset = self.tm1.get_subset(dimension_name='plan_version',
                                     subset_name='FY 2004 Budget',
                                     private=False)
        native_view.add_row(dimension_name='plan_version', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_business_unit',
                                     subset_name='n level business unit',
                                     private=False)
        native_view.add_row(dimension_name='plan_business_unit', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_department',
                                     subset_name='n level departments',
                                     private=False)
        native_view.add_row(dimension_name='plan_department', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_chart_of_accounts',
                                     subset_name='Consolidations',
                                     private=False)
        native_view.add_row(dimension_name='plan_chart_of_accounts',
                            subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_exchange_rates',
                                     subset_name='local',
                                     private=False)
        native_view.add_title(dimension_name='plan_exchange_rates',
                              subset=subset,
                              selection='local')

        subset = self.tm1.get_subset(dimension_name='plan_time',
                                     subset_name='2004 Total Year',
                                     private=False)
        native_view.add_column(dimension_name='plan_time', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_source',
                                     subset_name='budget',
                                     private=False)
        native_view.add_column(dimension_name='plan_source', subset=subset)

        # create native view on Server
        self.tm1.create_view(view=native_view, private=self.random_boolean)

        # create instance of MDXView
        nv_view = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                           view_name=self.native_view_name,
                                           private=self.random_boolean)
        mdx = nv_view.as_MDX
        mdx_view = MDXView(cube_name='Plan_BudgetPlan',
                           view_name=self.mdx_view_name,
                           MDX=mdx)
        # create mdx view on Server
        self.tm1.create_view(view=mdx_view, private=self.random_boolean)

    def test2_get_view(self):
        # get native view
        native_view = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                               view_name=self.native_view_name,
                                               private=self.random_boolean)
        # check if instance
        self.assertIsInstance(native_view, NativeView)

        # get mdx view
        mdx_view = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                         view_name=self.mdx_view_name,
                                         private=self.random_boolean)
        # check if instance
        self.assertIsInstance(mdx_view, MDXView)

    def test3_compare_data(self):
        data_nv = self.tm1.get_view_content('Plan_BudgetPlan',
                                            self.native_view_name,
                                            private=self.random_boolean)
        data_mdx = self.tm1.get_view_content('Plan_BudgetPlan',
                                             self.mdx_view_name,
                                             private=self.random_boolean)

        # Sum up all the values from the views
        sum_nv = sum(
            [value['Value'] for value in data_nv.values() if value['Value']])
        sum_mdx = sum(
            [value['Value'] for value in data_mdx.values() if value['Value']])
        self.assertEqual(sum_nv, sum_mdx)

    # fails sometimes because PrivateMDXViews cant be updated in FP < 5.
    def test4_update_nativeview(self):
        # get native view
        native_view_original = self.tm1.get_native_view(
            cube_name='Plan_BudgetPlan',
            view_name=self.native_view_name,
            private=self.random_boolean)

        # Sum up all the values from the views
        data_original = self.tm1.get_view_content('Plan_BudgetPlan',
                                                  self.native_view_name,
                                                  private=self.random_boolean)
        sum_original = sum([
            value['Value'] for value in data_original.values()
            if value['Value']
        ])

        # modify it
        native_view_original.remove_row(dimension_name='plan_version')
        subset = self.tm1.get_subset(dimension_name='plan_version',
                                     subset_name='All Versions',
                                     private=False)
        native_view_original.add_column(dimension_name='plan_version',
                                        subset=subset)

        # update it on Server
        self.tm1.update_view(native_view_original, private=self.random_boolean)

        #get it and check if its different
        native_view_updated = self.tm1.get_native_view(
            cube_name='Plan_BudgetPlan',
            view_name=self.native_view_name,
            private=self.random_boolean)
        data_updated = self.tm1.get_view_content('Plan_BudgetPlan',
                                                 self.native_view_name,
                                                 private=self.random_boolean)
        sum_updated = sum([
            value['Value'] for value in data_updated.values() if value['Value']
        ])
        self.assertNotEqual(sum_original, sum_updated)

    def test5_update_mdxview(self):
        # get mdx view
        mdx_view_original = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                                  view_name=self.mdx_view_name,
                                                  private=self.random_boolean)

        # get data from original view
        data_mdx_original = self.tm1.get_view_content(
            'Plan_BudgetPlan',
            mdx_view_original.name,
            private=self.random_boolean)

        mdx = "SELECT {([plan_version].[FY 2004 Budget], [plan_department].[105], [plan_chart_of_accounts].[61030], " \
        "[plan_exchange_rates].[local], [plan_source].[goal] , [plan_time].[Jan-2004]) } on COLUMNS," \
        "{[plan_business_unit].[10110]} on ROWS FROM [plan_BudgetPlan]"
        mdx_view_original.MDX = mdx
        # update it on Server
        self.tm1.update_view(mdx_view_original, private=self.random_boolean)
        # get it and check if its different
        mdx_view_updated = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                                 view_name=self.mdx_view_name,
                                                 private=self.random_boolean)

        data_mdx_updated = self.tm1.get_view_content(
            'Plan_BudgetPlan',
            mdx_view_updated.name,
            private=self.random_boolean)

        # Sum up all the values from the views
        sum_mdx_original = sum([
            value['Value'] for value in data_mdx_original.values()
            if value['Value']
        ])
        sum_mdx_updated = sum([
            value['Value'] for value in data_mdx_updated.values()
            if value['Value']
        ])
        self.assertNotEqual(sum_mdx_original, sum_mdx_updated)

    def test6_delete_view(self):
        self.tm1.delete_view(cube_name='Plan_BudgetPlan',
                             view_name=self.native_view_name,
                             private=self.random_boolean)
        self.tm1.delete_view(cube_name='Plan_BudgetPlan',
                             view_name=self.mdx_view_name,
                             private=self.random_boolean)
示例#12
0
文件: View.py 项目: zPat/TM1py
class TestViewMethods(unittest.TestCase):
    login = TM1pyLogin.native('admin', 'apple')
    tm1 = TM1(ip='', port=8001, login=login, ssl=False)
    random_string = str(uuid.uuid4())
    random_boolean = bool(random.getrandbits(1))

    native_view_name = 'TM1py_unittest_native_view_' + random_string
    mdx_view_name = 'TM1py_unittest_mdx_view_' + random_string

    def test1_create_view(self):
        # create instance of native View
        native_view = NativeView(name_cube='Plan_BudgetPlan',
                                 name_view=self.native_view_name)

        # set up native view - put subsets on Rows, Columns and Titles
        subset = self.tm1.get_subset(dimension_name='plan_version', subset_name='FY 2004 Budget')
        native_view.add_row(dimension_name='plan_version', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_business_unit', subset_name='n level business unit')
        native_view.add_row(dimension_name='plan_business_unit', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_department', subset_name='n level departments')
        native_view.add_row(dimension_name='plan_department', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_chart_of_accounts', subset_name='Consolidations')
        native_view.add_row(dimension_name='plan_chart_of_accounts', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_source', subset_name='budget')
        native_view.add_row(dimension_name='plan_source', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_exchange_rates', subset_name='actual')
        native_view.add_title(dimension_name='plan_exchange_rates', subset=subset, selection='actual')

        subset = self.tm1.get_subset(dimension_name='plan_time', subset_name='2003 Total Year')
        native_view.add_column(dimension_name='plan_time', subset=subset)

        # create native view on Server
        self.tm1.create_view(view=native_view, private=self.random_boolean)

        # create instance of MDXView
        mdx = "SELECT {([plan_version].[FY 2003 Budget], [plan_department].[105], [plan_chart_of_accounts].[61030], " \
              "[plan_exchange_rates].[local], [plan_source].[goal] , [plan_time].[Jan-2004]) } on COLUMNS," \
              "{[plan_business_unit].[10110]} on ROWS FROM [plan_BudgetPlan]"
        mdx_view = MDXView(cube_name='Plan_BudgetPlan',
                           view_name=self.mdx_view_name,
                           MDX=mdx)
        # create mdx view on Server
        self.tm1.create_view(view=mdx_view, private=self.random_boolean)

    def test2_get_view(self):
        # get native view
        native_view = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                               view_name=self.native_view_name,
                                               private=self.random_boolean)
        # check if instance
        self.assertIsInstance(native_view, NativeView)

        # get mdx view
        mdx_view = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                         view_name=self.mdx_view_name,
                                         private=self.random_boolean)
        # check if instance
        self.assertIsInstance(mdx_view, MDXView)

    def test3_update_view(self):
        # get native view
        native_view_original = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                                        view_name=self.native_view_name,
                                                        private=self.random_boolean)
        # modify it
        native_view = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                               view_name=self.native_view_name,
                                               private=self.random_boolean)

        native_view.remove_row(dimension_name='plan_version')
        subset = self.tm1.get_subset(dimension_name='plan_version', subset_name='All Versions')
        native_view.add_column(dimension_name='plan_version',  subset=subset)
        # update it on Server
        self.tm1.update_view(native_view, private=self.random_boolean)
        #get it and check if its different
        native_view_updated = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                                       view_name=self.native_view_name,
                                                       private=self.random_boolean)
        self.assertNotEqual(native_view_original.body, native_view_updated.body)

        # get mdx view
        mdx_view_original = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                                  view_name=self.mdx_view_name,
                                                  private=self.random_boolean)
        # modify it
        mdx_view = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                         view_name=self.mdx_view_name,
                                         private=self.random_boolean)
        mdx = "SELECT {([plan_version].[FY 2004 Budget], [plan_department].[105], [plan_chart_of_accounts].[61030], " \
        "[plan_exchange_rates].[local], [plan_source].[goal] , [plan_time].[Jan-2004]) } on COLUMNS," \
        "{[plan_business_unit].[10110]} on ROWS FROM [plan_BudgetPlan]"
        mdx_view.set_MDX(mdx)
        # update it on Server
        self.tm1.update_view(mdx_view)
        # get it and check if its different
        mdx_view_updated = self.tm1.get_mdx_view(cube_name='Plan_BudgetPlan',
                                                 view_name=self.mdx_view_name,
                                                 private=self.random_boolean)
        self.assertNotEqual(mdx_view_original.body, mdx_view_updated.body)

    def test4_delete_view(self):
        self.tm1.delete_view(cube_name='Plan_BudgetPlan', view_name=self.native_view_name, private=self.random_boolean)
        self.tm1.delete_view(cube_name='Plan_BudgetPlan', view_name=self.mdx_view_name, private=self.random_boolean)

    def test5_logout(self):
        self.tm1.logout()