コード例 #1
0
 def test_load_burst(self):
     """ 
     Test that the load burst works properly. NOTE: this method is also tested
     in the actual burst launch tests. This is just basic test to verify that the simulator
     interface is loaded properly.
     """
     burst_config = TestFactory.store_burst(self.test_project.id)
     loaded_burst = self.burst_service.load_burst(burst_config.id)[0]
     self.assertEqual(loaded_burst.simulator_configuration, {}, "No simulator configuration should have been loaded")
     self.assertEqual(burst_config.fk_project, loaded_burst.fk_project, "Loaded burst different from original one.")
     burst_config = TestFactory.store_burst(self.test_project.id, simulator_config={"test": "test"})
     loaded_burst, _ = self.burst_service.load_burst(burst_config.id)
     self.assertEqual(loaded_burst.simulator_configuration, {"test": "test"}, "different burst loaded")
     self.assertEqual(burst_config.fk_project, loaded_burst.fk_project, "Loaded burst different from original one.")
コード例 #2
0
    def __create_complex_workflow(self, workflow_step_list):
        """
        Creates a burst with a complex workflow with a given list of workflow steps.
        :param workflow_step_list: a list of workflow steps that will be used in the
            creation of a new workflow for a new burst
        """
        burst_config = TestFactory.store_burst(self.test_project.id)

        stored_dt = datatypes_factory.DatatypesFactory()._store_datatype(Datatype1())

        first_step_algorithm = self.flow_service.get_algorithm_by_module_and_class("tvb.tests.framework.adapters.testadapter1",
                                                                                   "TestAdapterDatatypeInput")
        metadata = {DataTypeMetaData.KEY_BURST: burst_config.id}
        kwargs = {"test_dt_input": stored_dt.gid, 'test_non_dt_input': '0'}
        operations, group = self.operation_service.prepare_operations(self.test_user.id, self.test_project.id,
                                                                      first_step_algorithm,
                                                                      first_step_algorithm.algorithm_category,
                                                                      metadata, **kwargs)

        workflows = self.workflow_service.create_and_store_workflow(project_id=self.test_project.id,
                                                                    burst_id=burst_config.id,
                                                                    simulator_index=0,
                                                                    simulator_id=first_step_algorithm.id,
                                                                    operations=operations)
        self.operation_service.prepare_operations_for_workflowsteps(workflow_step_list, workflows, self.test_user.id,
                                                                    burst_config.id, self.test_project.id, group,
                                                                    operations)
        #fire the first op
        if len(operations) > 0:
            self.operation_service.launch_operation(operations[0].id, False)
        return burst_config.id
コード例 #3
0
 def test_rename_burst(self):
     """
     Test that renaming of a burst functions properly.
     """
     burst_config = TestFactory.store_burst(self.test_project.id)
     self.burst_service.rename_burst(burst_config.id, "new_burst_name")
     loaded_burst = dao.get_burst_by_id(burst_config.id)
     self.assertEqual(loaded_burst.name, "new_burst_name", "Burst was not renamed properly.")
コード例 #4
0
 def test_rename_burst(self):
     """
     Test that renaming of a burst functions properly.
     """
     burst_config = TestFactory.store_burst(self.test_project.id)
     self.burst_service.rename_burst(burst_config.id, "new_burst_name")
     loaded_burst = dao.get_burst_by_id(burst_config.id)
     self.assertEqual(loaded_burst.name, "new_burst_name", "Burst was not renamed properly.")
コード例 #5
0
 def test_store_burst_config(self):
     """
     Test that a burst entity is properly stored in db.
     """
     burst_config = TestFactory.store_burst(self.test_project.id)
     self.assertTrue(burst_config.id is not None, 'Burst was not stored properly.')
     stored_entity = dao.get_burst_by_id(burst_config.id)
     self.assertTrue(stored_entity is not None, 'Burst was not stored properly.')
     self._compare_bursts(burst_config, stored_entity)
コード例 #6
0
 def test_load_burst(self):
     """ 
     Test that the load burst works properly. NOTE: this method is also tested
     in the actual burst launch tests. This is just basic test to verify that the simulator
     interface is loaded properly.
     """
     burst_config = TestFactory.store_burst(self.test_project.id)
     loaded_burst = self.burst_service.load_burst(burst_config.id)[0]
     self.assertEqual(loaded_burst.simulator_configuration, {},
                      "No simulator configuration should have been loaded")
     self.assertEqual(burst_config.fk_project, loaded_burst.fk_project,
                      "Loaded burst different from original one.")
     burst_config = TestFactory.store_burst(
         self.test_project.id, simulator_config={"test": "test"})
     loaded_burst, _ = self.burst_service.load_burst(burst_config.id)
     self.assertEqual(loaded_burst.simulator_configuration,
                      {"test": "test"}, "different burst loaded")
     self.assertEqual(burst_config.fk_project, loaded_burst.fk_project,
                      "Loaded burst different from original one.")
コード例 #7
0
 def test_get_available_bursts_happy(self):
     """
     Test that all the correct burst are returned for the given project.
     """
     project = model.Project("second_test_proj", self.test_user.id, "description")
     second_project = dao.store_entity(project)
     test_project_bursts = [TestFactory.store_burst(self.test_project.id).id for _ in range(4)]
     second_project_bursts = [TestFactory.store_burst(second_project.id).id for _ in range(3)]
     returned_test_project_bursts = [burst.id for burst in
                                     self.burst_service.get_available_bursts(self.test_project.id)]
     returned_second_project_bursts = [burst.id for burst in
                                       self.burst_service.get_available_bursts(second_project.id)]
     self.assertEqual(len(test_project_bursts), len(returned_test_project_bursts),
                      "Incorrect bursts retrieved for project %s." % self.test_project)
     self.assertEqual(len(second_project_bursts), len(returned_second_project_bursts),
                      "Incorrect bursts retrieved for project %s." % second_project)
     self.assertEqual(set(second_project_bursts), set(returned_second_project_bursts),
                      "Incorrect bursts retrieved for project %s." % second_project)
     self.assertEqual(set(test_project_bursts), set(returned_test_project_bursts),
                      "Incorrect bursts retrieved for project %s." % self.test_project)
コード例 #8
0
 def test_clone_burst_configuration(self):
     """
     Test that all the major attributes are the same after a clone burst but the
     id of the cloned one is None.
     """
     first_burst = TestFactory.store_burst(self.test_project.id)
     cloned_burst = first_burst.clone()
     self._compare_bursts(first_burst, cloned_burst)
     self.assertEqual(first_burst.selected_tab, cloned_burst.selected_tab, "Selected tabs not equal for bursts.")
     self.assertEqual(len(first_burst.tabs), len(cloned_burst.tabs), "Tabs not equal for bursts.")
     self.assertTrue(cloned_burst.id is None, 'id should be none for cloned entry.')
コード例 #9
0
    def _prepare_and_launch_sync_burst(self):
        """
        Private method to launch a dummy burst. Return the burst loaded after the launch finished
        as well as the workflow steps that initially formed the burst.
        NOTE: the burst launched by this method is a `dummy` one, meaning we do not use an actual
        simulation, but instead test adapters.
        """
        burst_config = TestFactory.store_burst(self.test_project.id)

        workflow_step_list = []
        test_portlet = dao.get_portlet_by_identifier(self.PORTLET_ID)

        stored_dt = datatypes_factory.DatatypesFactory()._store_datatype(
            Datatype1())
        first_step_algorithm = self.flow_service.get_algorithm_by_module_and_class(
            "tvb.tests.framework.adapters.testadapter1",
            "TestAdapterDatatypeInput")
        metadata = {DataTypeMetaData.KEY_BURST: burst_config.id}
        kwargs = {"test_dt_input": stored_dt.gid, 'test_non_dt_input': '0'}
        operations, group = self.operation_service.prepare_operations(
            self.test_user.id, self.test_project.id, first_step_algorithm,
            first_step_algorithm.algorithm_category, metadata, **kwargs)
        view_step = TestFactory.create_workflow_step(
            "tvb.tests.framework.adapters.testadapter2",
            "TestAdapter2", {"test2": 2}, {},
            0,
            0,
            0,
            0,
            is_view_step=True)
        view_step.fk_portlet = test_portlet.id
        workflow_step_list.append(view_step)

        workflows = self.workflow_service.create_and_store_workflow(
            self.test_project.id, burst_config.id, 0, first_step_algorithm.id,
            operations)
        self.operation_service.prepare_operations_for_workflowsteps(
            workflow_step_list, workflows, self.test_user.id, burst_config.id,
            self.test_project.id, group, operations)
        ### Now fire the workflow and also update and store the burst configuration ##
        self.operation_service.launch_operation(operations[0].id, False)
        loaded_burst, _ = self.burst_service.load_burst(burst_config.id)
        import_operation = dao.get_operation_by_id(stored_dt.fk_from_operation)
        dao.remove_entity(import_operation.__class__, import_operation.id)
        dao.remove_datatype(stored_dt.gid)
        return loaded_burst, workflow_step_list
コード例 #10
0
    def _prepare_and_launch_sync_burst(self):
        """
        Private method to launch a dummy burst. Return the burst loaded after the launch finished
        as well as the workflow steps that initially formed the burst.
        NOTE: the burst launched by this method is a `dummy` one, meaning we do not use an actual
        simulation, but instead test adapters.
        """
        burst_config = TestFactory.store_burst(self.test_project.id)

        workflow_step_list = []
        test_portlet = dao.get_portlet_by_identifier(self.PORTLET_ID)

        stored_dt = datatypes_factory.DatatypesFactory()._store_datatype(Datatype1())
        first_step_algorithm = self.flow_service.get_algorithm_by_module_and_class(
            "tvb.tests.framework.adapters.testadapter1", "TestAdapterDatatypeInput")
        metadata = {DataTypeMetaData.KEY_BURST: burst_config.id}
        kwargs = {"test_dt_input": stored_dt.gid, 'test_non_dt_input': '0'}
        operations, group = self.operation_service.prepare_operations(self.test_user.id, self.test_project.id,
                                                                      first_step_algorithm,
                                                                      first_step_algorithm.algorithm_category,
                                                                      metadata, **kwargs)
        view_step = TestFactory.create_workflow_step("tvb.tests.framework.adapters.testadapter2", "TestAdapter2",
                                                     {"test2": 2}, {}, 0, 0, 0, 0, is_view_step=True)
        view_step.fk_portlet = test_portlet.id
        workflow_step_list.append(view_step)

        workflows = self.workflow_service.create_and_store_workflow(self.test_project.id, burst_config.id, 0,
                                                                    first_step_algorithm.id, operations)
        self.operation_service.prepare_operations_for_workflowsteps(workflow_step_list, workflows, self.test_user.id,
                                                                    burst_config.id, self.test_project.id, group,
                                                                    operations)
        ### Now fire the workflow and also update and store the burst configuration ##
        self.operation_service.launch_operation(operations[0].id, False)
        loaded_burst, _ = self.burst_service.load_burst(burst_config.id)
        import_operation = dao.get_operation_by_id(stored_dt.fk_from_operation)
        dao.remove_entity(import_operation.__class__, import_operation.id)
        dao.remove_datatype(stored_dt.gid)
        return loaded_burst, workflow_step_list