Example #1
0
    def test_load_burst_only(self):
        zip_path = path.join(path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip')
        connectivity = TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path, "John")

        op = TestFactory.create_operation(test_user=self.test_user, test_project=self.test_project)
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.fk_simulation = op.id
        burst_config.simulator_gid = self.session_stored_simulator.gid.hex
        burst_config.name = 'Test_Burst'
        burst_config = dao.store_entity(burst_config)

        self.sess_mock['burst_id'] = str(burst_config.id)
        self.sess_mock['connectivity'] = connectivity.gid
        self.sess_mock['conduction_speed'] = "3.0"
        self.sess_mock['coupling'] = "Sigmoidal"

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_SIMULATOR_CONFIG, self.session_stored_simulator)
            self.simulator_controller.set_connectivity(**self.sess_mock._data)
            self.simulator_controller.set_stimulus(**self.sess_mock._data)

        storage_path = FilesHelper().get_project_folder(self.test_project, str(op.id))
        SimulatorSerializer().serialize_simulator(self.session_stored_simulator, None, storage_path)

        with patch('cherrypy.session', self.sess_mock, create=True):
            self.simulator_controller.load_burst_read_only(str(burst_config.id))
            is_simulator_load = common.get_from_session(KEY_IS_SIMULATOR_LOAD)
            is_simulator_copy = common.get_from_session(KEY_IS_SIMULATOR_COPY)
            last_loaded_form_url = common.get_from_session(KEY_LAST_LOADED_FORM_URL)

        assert is_simulator_load, "Simulator Load Flag should be True!"
        assert not is_simulator_copy, "Simulator Copy Flag should be False!"
        assert last_loaded_form_url == '/burst/setup_pse', "Incorrect last form URL!"
Example #2
0
    def test_export_simulator_configuration(self, operation_factory,
                                            connectivity_index_factory):
        """
        Test export of a simulator configuration
        """
        conn_gid = uuid.UUID(connectivity_index_factory().gid)
        operation = operation_factory(is_simulation=True,
                                      store_vm=True,
                                      test_project=self.test_project,
                                      conn_gid=conn_gid)

        burst_configuration = BurstConfiguration(self.test_project.id)
        burst_configuration.fk_simulation = operation.id
        burst_configuration.simulator_gid = operation.view_model_gid
        burst_configuration.name = "Test_burst"
        burst_configuration = dao.store_entity(burst_configuration)

        op_folder = StorageInterface().get_project_folder(
            self.test_project.name, str(operation.id))
        BurstService().store_burst_configuration(burst_configuration,
                                                 op_folder)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"
Example #3
0
    def build(project):
        range_1 = ["row1", [1, 2, 10]]
        range_2 = ["row2", [0.1, 0.3, 0.5]]

        group = OperationGroup(
            project.id, ranges=[json.dumps(range_1),
                                json.dumps(range_2)])
        group = dao.store_entity(group)
        group_ms = OperationGroup(
            project.id, ranges=[json.dumps(range_1),
                                json.dumps(range_2)])
        group_ms = dao.store_entity(group_ms)

        datatype_group = DataTypeGroup(group)
        datatype_group.no_of_ranges = 2
        datatype_group.count_results = 10
        dao.store_entity(datatype_group)

        dt_group_ms = DataTypeGroup(group_ms)
        dao.store_entity(dt_group_ms)

        burst = BurstConfiguration(project.id, name='test_burst')
        burst.simulator_gid = uuid.uuid4().hex
        burst.fk_operation_group = group.id
        burst.fk_metric_operation_group = group_ms.id
        burst = dao.store_entity(burst)
        return burst
Example #4
0
    def test_export_simulator_configuration(self, operation_factory,
                                            connectivity_factory):
        """
        Test export of a simulator configuration
        """
        operation = operation_factory()
        simulator = SimulatorAdapterModel()
        simulator.connectivity = connectivity_factory(4).gid

        burst_configuration = BurstConfiguration(self.test_project.id)
        burst_configuration.fk_simulation_id = operation.id
        burst_configuration.simulator_gid = simulator.gid.hex
        burst_configuration = dao.store_entity(burst_configuration)

        storage_path = FilesHelper().get_project_folder(
            self.test_project, str(operation.id))
        h5_path = h5.path_for(storage_path, SimulatorH5, simulator.gid)
        with SimulatorH5(h5_path) as h5_file:
            h5_file.store(simulator)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"
Example #5
0
    def test_export(self):
        op = TestFactory.create_operation(test_user=self.test_user,
                                          test_project=self.test_project)
        burst_config = BurstConfiguration(self.test_project.id)
        burst_config.fk_simulation = op.id
        burst_config.simulator_gid = self.session_stored_simulator.gid.hex
        burst_config = dao.store_entity(burst_config)

        storage_path = FilesHelper().get_project_folder(
            self.test_project, str(op.id))
        h5_path = h5.path_for(storage_path, SimulatorH5,
                              self.session_stored_simulator.gid)
        with SimulatorH5(h5_path) as h5_file:
            h5_file.store(self.session_stored_simulator)

        burst = dao.get_bursts_for_project(self.test_project.id)
        self.sess_mock['burst_id'] = str(burst[0].id)

        with patch('cherrypy.session', self.sess_mock, create=True):
            common.add2session(common.KEY_BURST_CONFIG,
                               self.session_stored_simulator)
            common.add2session(common.KEY_BURST_CONFIG, burst_config)
            result = self.simulator_controller.export(str(burst[0].id))

        assert path.exists(result.input.name), "Simulation was not exported!"
Example #6
0
 def store_burst(project_id, operation=None):
     """
     Build and persist BurstConfiguration entity.
     """
     burst = BurstConfiguration(project_id)
     if operation is not None:
         burst.name = 'dummy_burst'
         burst.status = BurstConfiguration.BURST_FINISHED
         burst.start_time = datetime.now()
         burst.range1 = '["conduction_speed", {"lo": 50, "step": 1.0, "hi": 100.0}]'
         burst.range2 = '["connectivity", null]'
         burst.fk_simulation = operation.id
         burst.simulator_gid = uuid.uuid4().hex
         BurstService().store_burst_configuration(burst)
     return dao.store_entity(burst)
Example #7
0
    def test_export_simulator_configuration(self, operation_factory):
        """
        Test export of a simulator configuration
        """
        operation = operation_factory(is_simulation=True, store_vm=True)

        burst_configuration = BurstConfiguration(self.test_project.id)
        burst_configuration.fk_simulation = operation.id
        burst_configuration.simulator_gid = operation.view_model_gid
        burst_configuration = dao.store_entity(burst_configuration)

        export_file = self.export_manager.export_simulator_configuration(
            burst_configuration.id)

        assert export_file is not None, "Export process should return path to export file"
        assert os.path.exists(
            export_file
        ), "Could not find export file: %s on disk." % export_file
        assert zipfile.is_zipfile(
            export_file), "Generated file is not a valid ZIP file"