Пример #1
0
class TestFieldApi(unittest.TestCase):
    def setUp(self):
        url = 'ws://localhost:4848/app'
        self.conn = EngineCommunicator(url)
        self.ega = EngineGlobalApi(self.conn)
        self.eaa = EngineAppApi(self.conn)
        self.egoa = EngineGenericObjectApi(self.conn)
        self.efa = EngineFieldApi(self.conn)
        self.struct = Structs()
        self.app = self.ega.create_app("TestApp")["qAppId"]
        opened_app = self.ega.open_doc(self.app)
        self.app_handle = self.ega.get_handle(opened_app['qReturn'])
        with open('./test/test_data/ctrl00_script.qvs') as f:
            script = f.read()
        self.eaa.set_script(self.app_handle, script)
        self.eaa.do_reload_ex(self.app_handle)
        nx_page_initial = Structs.nx_page(0, 0, 26, 1)
        self.lb_def = Structs.list_object_def("$", "", ["Alpha"], None, None,
                                              [nx_page_initial])
        self.lb_param = {
            "qInfo": {
                "qId": "SLB01",
                "qType": "ListObject"
            },
            "qListObjectDef": self.lb_def
        }
        self.lb_sobject = self.eaa.create_session_object(
            self.app_handle, self.lb_param)
        self.lb_handle = self.ega.get_handle(self.lb_sobject["qReturn"])
        self.egoa.get_layout(self.lb_handle)
        self.lb_field = self.eaa.get_field(self.app_handle, "Alpha")
        self.fld_handle = self.ega.get_handle(self.lb_field["qReturn"])

    def test_select_values(self):
        values_to_select = [{'qText': 'A'}, {'qText': 'B'}, {'qText': 'C'}]
        sel_res = self.efa.select_values(self.fld_handle, values_to_select)
        self.assertTrue(sel_res["qReturn"] is True,
                        "Failed to perform selection")
        val_mtrx = self.egoa.get_layout(
            self.lb_handle
        )["qLayout"]["qListObject"]["qDataPages"][0]["qMatrix"]
        self.assertEqual(val_mtrx[0][0]["qState"], "S",
                         "Failed to select first value")
        self.assertEqual(val_mtrx[4][0]["qState"], "X",
                         "Failed to exclude fifth value")
        self.eaa.clear_all(self.app_handle)
        val_mtrx = self.egoa.get_layout(
            self.lb_handle
        )["qLayout"]["qListObject"]["qDataPages"][0]["qMatrix"]
        self.assertEqual(val_mtrx[0][0]["qState"], "O",
                         "Failed to clear selection")
        self.assertEqual(val_mtrx[4][0]["qState"], "O",
                         "Failed to clear selection")

    def tearDown(self):
        self.ega.delete_app(self.app)
        self.conn.close_qvengine_connection(self.conn)
Пример #2
0
class TestAppApi(unittest.TestCase):

    # Constructor to prepare everything before running the tests.
    def setUp(self):
        url = 'ws://localhost:4848/app'
        self.conn = EngineCommunicator(url)
        self.ega = EngineGlobalApi(self.conn)
        self.eaa = EngineAppApi(self.conn)
        self.egoa = EngineGenericObjectApi(self.conn)
        self.efa = EngineFieldApi(self.conn)
        self.struct = Structs()
        self.app = self.ega.create_app("TestApp")
        opened_app = self.ega.open_doc(self.app)
        self.app_handle = self.ega.get_handle(opened_app)

    def test_add_alternate_state(self):
        response = self.eaa.add_alternate_state(self.app_handle, "MyState")
        self.assertEqual(response, {}, "Failed to add alternate state")

    def test_create_hypercube_object(self):
        script = file('./test/test_data/ctrl00_script.qvs').read()
        self.eaa.set_script(self.app_handle, script)
        self.eaa.do_reload_ex(self.app_handle)
        hc_inline_dim = Structs.nx_inline_dimension_def(["Alpha"])
        hc_mes_sort = Structs.nx_sort_by()
        hc_inline_mes = Structs.nx_inline_measure_def("=Sum(Num)")
        hc_dim = Structs.nx_hypercube_dimensions(hc_inline_dim)
        hc_mes = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes)
        nx_page = Structs.nx_page(0, 0, 26, 2)
        hc_def = Structs.hypercube_def("$", [hc_dim], [hc_mes], [nx_page])
        hc_response = self.eaa.create_object(self.app_handle, "CH01", "Chart",
                                             "qHyperCubeDef", hc_def)
        hc_handle = self.ega.get_handle(hc_response)
        self.egoa.get_layout(hc_handle)
        hc_data = self.egoa.get_hypercube_data(hc_handle, "/qHyperCubeDef",
                                               [nx_page])
        self.assertTrue(type(hc_data is {}),
                        "Unexpected type of hypercube data")
        first_element_number = hc_data["qDataPages"][0]["qMatrix"][0][0][
            "qElemNumber"]
        first_element_text = hc_data["qDataPages"][0]["qMatrix"][0][0]["qText"]
        self.assertTrue(first_element_number == 0,
                        "Incorrect value in first element number")
        self.assertTrue(first_element_text == 'A',
                        "Incorrect value in first element text")

    def tearDown(self):
        self.ega.delete_app(self.app)
        self.conn.close_qvengine_connection(self.conn)
Пример #3
0
class TestGlobalApi(unittest.TestCase):
    # Constructor to prepare everything before running the tests.
    def setUp(self):
        url = 'ws://localhost:4848/app'
        self.conn = EngineCommunicator(url)
        self.ega = EngineGlobalApi(self.conn)
        self.eaa = EngineAppApi(self.conn)
        self.egoa = EngineGenericObjectApi(self.conn)
        self.efa = EngineFieldApi(self.conn)
        self.struct = Structs()

    def test_get_doclist(self):
        response = self.ega.get_doc_list()
        self.assertTrue(len(response) > 0)

    def test_app_methods(self):
        response_create = self.ega.create_app("test_app")
        self.assertTrue(response_create.endswith(".qvf"), "Failed to create app. Response did not end with .qvf")
        #response_copy = self.ega.copy_app("test_app_copy", response_create)
        #print response_copy
        response_open = self.ega.open_doc("test_app")
        self.assertEqual(response_open["qHandle"],1,"Failed to retrive a proper document handle with open_doc method")
        self.assertTrue(response_open["qGenericId"].endswith(".qvf"),
                        'Generic id does not contain any app file extension using open_doc method')
        self.assertEqual(response_open["qType"],"Doc",'Unknown doc type returned using open_doc method')
        response_get_active_doc = self.ega.get_active_doc()
        self.assertEqual(response_get_active_doc["qHandle"], 1, "Failed to retrive a proper document handle with "
                                                                "get_active_doc method")
        self.assertTrue(response_get_active_doc["qGenericId"].endswith(".qvf"),
                        'Generic id does not contain any app file extension  using get_active_doc method')
        self.assertEqual(response_get_active_doc["qType"], "Doc", 'Unknown doc type returned using get_active_doc '
                                                                  'method')
        response_delete = self.ega.delete_app(response_create)
        #self.ega.delete_app(response_copy)
        self.assertTrue(response_delete, "Failed to delete app")

    # May be a meaningless test since there are no commands to abort??
    def test_abort_all(self):
        response = self.ega.abort_all()
        self.assertEqual(response,{},'abort_all method returned unexpected object')

    # May be a meaningless test since there is no request with id 1?
    def test_abort_request(self):
        response = self.ega.abort_request(1)
        self.assertEqual(response, {}, 'abort_request method returned unexpected object')

    def test_configure_reload(self):
        response_pos = self.ega.configure_reload(True, True, True)
        self.assertEqual(response_pos, {}, 'configure_reload method returned unexpected object')
        response_neg = self.ega.configure_reload('dummy',True,True)
        self.assertEqual(response_neg,"Error code: -32602, Error Msg: Invalid method parameter(s)","Unknown error "
                                                                                                   "message for "
                                                                                                   "configure_reload "
                                                                                                   "method")

    def test_create_session_app(self):
        response = self.ega.create_session_app()
        self.assertTrue(response.startswith("SessionApp_"),"Failed to create session app")

    def test_create_session_app_from_app(self):
        response_create = self.ega.create_app("test_app")
        response = self.ega.create_session_app_from_app(response_create)
        self.ega.delete_app(response_create)
        self.assertTrue(response.startswith("SessionApp_"),"Failed to create session app")

    def test_export_app(self):
        tmp_folder = tempfile.gettempdir()
        response_create = self.ega.create_app("test_app")
        response = self.ega.export_app(tmp_folder,response_create)
        self.ega.delete_app(response_create)
        print "BUG returns method not found. Reported"

    def test_replace_app_from_id(self):
        response_create = self.ega.create_app("test_app")
        tmp_folder = tempfile.gettempdir()
        response = self.ega.replace_app_from_id(tmp_folder, response_create)
        print "Same bug as CopyApp and ExportApp"
        self.ega.delete_app(response_create)

    def test_get_auth_user(self):
        response = self.ega.get_auth_user()
        self.assertTrue(type(response) is dict, "Failed to retrieve authenticated user")

    def test_is_desktop_mode(self):
        response = self.ega.is_desktop_mode(0)
        self.assertTrue(type(response) is bool,'Failed to check destop mode')

    # Clean up after the tests have been run
    def tearDown(self):
        self.conn.close_qvengine_connection(self.conn)
Пример #4
0
class TestAppApi(unittest.TestCase):

    # Constructor to prepare everything before running the tests.
    def setUp(self):
        url = 'ws://localhost:4848/app'
        self.conn = EngineCommunicator(url)
        self.ega = EngineGlobalApi(self.conn)
        self.eaa = EngineAppApi(self.conn)
        self.egoa = EngineGenericObjectApi(self.conn)
        self.efa = EngineFieldApi(self.conn)
        self.struct = Structs()
        self.app = self.ega.create_app("TestApp")['qAppId']
        opened_app = self.ega.open_doc(self.app)
        self.app_handle = self.ega.get_handle(opened_app['qReturn'])

    def test_add_alternate_state(self):
        response = self.eaa.add_alternate_state(self.app_handle, "MyState")
        self.assertEqual(response, {}, "Failed to add alternate state")

    def test_create_hypercube_object(self):
        with open('./test/test_data/ctrl00_script.qvs') as f:
            script = f.read()
        self.eaa.set_script(self.app_handle, script)
        self.eaa.do_reload_ex(self.app_handle)

        #Create the inline dimension structures
        hc_inline_dim1 = Structs.nx_inline_dimension_def(["Alpha"])
        hc_inline_dim2 = Structs.nx_inline_dimension_def(["Num"])

        #Create a sort structure
        hc_mes_sort = Structs.nx_sort_by()

        #Create the measure structures
        hc_inline_mes1 = Structs.nx_inline_measure_def("=Sum(Num)")
        hc_inline_mes2 = Structs.nx_inline_measure_def("=Avg(Num)")

        #Create hypercube dimensions from the inline dimension structures
        hc_dim1 = Structs.nx_hypercube_dimensions(hc_inline_dim1)
        hc_dim2 = Structs.nx_hypercube_dimensions(hc_inline_dim2)

        # Create hypercube measures from the inline measure structures
        hc_mes1 = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes1)
        hc_mes2 = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes2)

        # Create the paging model/structure (26 rows and 4 columns)
        nx_page = Structs.nx_page(0, 0, 26, 4)

        # Create a hypercube definition with arrays of hc dims, measures and nxpages
        hc_def = Structs.hypercube_def("$", [hc_dim1, hc_dim2],
                                       [hc_mes1, hc_mes2], [nx_page])

        # Create a Chart object with the hypercube definitions as parameter
        hc_response = self.eaa.create_object(self.app_handle, "CH01", "Chart",
                                             "qHyperCubeDef", hc_def)

        #Get the handle to the chart object (this may be different in my local repo. I have made some changes to this
        # for future versions)
        hc_handle = self.ega.get_handle(hc_response['qReturn'])

        # Validate the chart object by calling get_layout
        self.egoa.get_layout(hc_handle)

        # Call the get_hypercube_data to get the resulting json object, using the handle and nx page as paramters
        hc_data = self.egoa.get_hypercube_data(hc_handle, "/qHyperCubeDef",
                                               [nx_page])

        self.assertTrue(type(hc_data is {}),
                        "Unexpected type of hypercube data")
        first_element_number = hc_data["qDataPages"][0]["qMatrix"][0][0][
            "qElemNumber"]
        first_element_text = hc_data["qDataPages"][0]["qMatrix"][0][0]["qText"]
        self.assertTrue(first_element_number == 0,
                        "Incorrect value in first element number")
        self.assertTrue(first_element_text == 'A',
                        "Incorrect value in first element text")

    def tearDown(self):
        self.ega.delete_app(self.app)
        self.conn.close_qvengine_connection(self.conn)