__author__ = 'Marius'

from TM1py import TM1Queries, Process
import uuid
import unittest


class TestAnnotationMethods(unittest.TestCase):
    q = TM1Queries(ip='', port=8008, user='admin', password='apple', ssl=True)
    random_string = str(uuid.uuid4()).replace('-', '_')
    p_none = Process(name='unittest_none_' + random_string, datasource_type='None')
    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')
    p_view = Process(name='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')
    p_odbc = Process(name='unittest_odbc_' + random_string, datasource_type='ODBC')

    # create Process
    def test1_create_process(self):
        self.q.create_process(self.p_none)
        self.q.create_process(self.p_ascii)
        self.q.create_process(self.p_view)
        self.q.create_process(self.p_odbc)

    # get Process
    def test2_get_process(self):
        p1 = self.q.get_process(self.p_ascii.name)
        self.assertEqual(p1.body, self.p_ascii.body)
        p2 = self.q.get_process(self.p_none.name)
        self.assertEqual(p2.body, self.p_none.body)
        p3 = self.q.get_process(self.p_view.name)
        self.assertEqual(p3.body, self.p_view.body)
        p4 = self.q.get_process(self.p_odbc.name)
        x = p4.datasource_password = None
        y = self.p_odbc.datasource_password = None
        self.assertEqual(x, y)

    # update process
    def test3_update_process(self):
        # get
        p = self.q.get_process(self.p_ascii.name)
        # modify
        p.set_data_procedure(Process.auto_generated_string() + "x = 'Hi this is a test';")
        # update on Server
        self.q.update_process(p)
        # get again
        p_ascii_updated = self.q.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.q.delete_process(self.p_none.name)
        self.q.delete_process(self.p_ascii.name)
        self.q.delete_process(self.p_view.name)
        self.q.delete_process(self.p_odbc.name)

    def test_5_logout(self):
        self.q.logout()


if __name__ == '__main__':
    unittest.main()

@@ -1,27 +1,4 @@
-__author__ = 'Marius'%0A%0A
 from
@@ -47,78 +47,37 @@
 uid%0A
-import unittest%0A%0A%0Aclass TestAnnotationMethods(unittest.TestCase):%0A    
+%0A%0A# connection to TM1 Server%0A
 q = 
@@ -91,31 +91,18 @@
 ies(
-ip=
 '', 
-port=
 8008, 
-user=
 'adm
@@ -110,17 +110,8 @@
 n', 
-password=
 'app
@@ -119,22 +119,37 @@
 e', 
-ssl=
 True)%0A
-    
+# just a random string%0A
 rand
@@ -200,96 +200,32 @@
 _')%0A
-    p_none = Process(name='unittest_none_' + random_string, datasource_type='None')%0A    
+%0A%0A%0A# create new Process%0A
 p_as
@@ -313,36 +313,32 @@
                 
-  
-  
 datasource_ascii
@@ -358,20 +358,16 @@
 ar=',',%0A
-    
         
@@ -451,36 +451,32 @@
                 
- 
-   
 datasource_data_
@@ -524,20 +524,16 @@
 v.csv')%0A
-    
 # variab
@@ -536,20 +536,16 @@
 riables%0A
-    
 p_ascii.
@@ -567,36 +567,32 @@
 _1', 'Numeric')%0A
-    
 p_ascii.add_vari
@@ -606,36 +606,32 @@
 _2', 'Numeric')%0A
-    
 p_ascii.add_vari
@@ -653,20 +653,16 @@
 meric')%0A
-    
 p_ascii.
@@ -692,20 +692,16 @@
 meric')%0A
-    
 # parame
@@ -705,20 +705,16 @@
 ameters%0A
-    
 p_ascii.
@@ -758,1220 +758,99 @@
 6')%0A
-    p_view = Process(name='unittest_view_' + random_string, datasource_type='TM1CubeView', datasource_view='view1',%0A                     datasource_data_source_name_for_client='Plan_BudgetPlan',%0A                     datasource_data_source_name_for_server='Plan_BudgetPlan')%0A    p_odbc = Process(name='unittest_odbc_' + random_string, datasource_type='ODBC')%0A%0A    # create Process%0A    def test1_create_process(self):%0A        self.q.create_process(self.p_none)%0A        self.q.create_process(self.p_ascii)%0A        self.q.create_process(self.p_view)%0A        self.q.create_process(self.p_odbc)%0A%0A    # get Process%0A    def test2_get_process(self):%0A        p1 = self.q.get_process(self.p_ascii.name)%0A        self.assertEqual(p1.body, self.p_ascii.body)%0A        p2 = self.q.get_process(self.p_none.name)%0A        self.assertEqual(p2.body, self.p_none.body)%0A        p3 = self.q.get_process(self.p_view.name)%0A        self.assertEqual(p3.body, self.p_view.body)%0A        p4 = self.q.get_process(self.p_odbc.name)%0A        x = p4.datasource_password = None%0A        y = self.p_odbc.datasource_password = None%0A        self.assertEqual(x, y)%0A%0A    # update process%0A    def test3_update_process(self):%0A        # get%0A        p = self.
+# create process on Server%0Aq.create_process(p_ascii)%0A%0A%0A%0A# update existing Process:%0Ap_new = 
 q.ge
@@ -851,37 +851,32 @@
 = q.get_process(
-self.
 p_ascii.name)%0A  
@@ -873,24 +873,16 @@
 i.name)%0A
-        
 # modify
@@ -882,25 +882,21 @@
  modify%0A
-        p
+p_new
 .set_dat
@@ -969,24 +969,16 @@
 est';%22)%0A
-        
 # update
@@ -988,29 +988,16 @@
  Server%0A
-        self.
 q.update
@@ -1010,194 +1010,17 @@
 ss(p
-)%0A        # get again%0A        p_ascii_updated = self.q.get_process(p.name)%0A        # assert%0A        self.assertNotEqual(p_ascii_updated.data_procedure, self.p_ascii.data_procedure)%0A%0A    
+_new)%0A%0A%0A%0A
 # de
@@ -1028,344 +1028,76 @@
 ete 
-p
+P
 rocess
-%0A    def test4_delete_process(self):%0A        self.q.delete_process(self.p_none.name)%0A        self.q.delete_process(self.p_ascii.name)%0A        self.q.delete_process(self.p_view.name)%0A        self.q.delete_process(self.p_odbc.name)%0A%0A    def test_5_logout(self):%0A        self.q.logout()%0A%0A%0Aif __name__ == '__main__':%0A    unittest.main
+ from Server%0Aq.delete_process(p_new.name)%0A%0A%0A%0A# logout%0Aq.logout
 ()%0A

Update Process.py