Beispiel #1
0
    def test_export(self):
        op = TestFactory.create_operation()
        simulator_index = SimulatorIndex()
        simulator_index.fill_from_has_traits(self.session_stored_simulator)

        burst_config = BurstConfiguration(self.test_project.id,
                                          simulator_index.id)
        burst_config = dao.store_entity(burst_config)

        simulator_index.fk_from_operation = op.id
        simulator_index = dao.store_entity(simulator_index)
        simulator_index.fk_parent_burst = burst_config.id
        simulator_index = dao.store_entity(simulator_index)

        simulator_h5 = h5.path_for_stored_index(simulator_index)
        with SimulatorH5(simulator_h5) 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!"
    def test_export_simulator_configuration(self, operation_factory):
        """
        Test export of a simulator configuration
        """
        operation = operation_factory()
        simulator = Simulator()
        simulator_index = SimulatorIndex()
        simulator_index.fill_from_has_traits(simulator)
        simulator_index.fk_from_operation = operation.id
        simulator_index = dao.store_entity(simulator_index)

        burst_configuration = BurstConfiguration(self.test_project.id,
                                                 simulator_index.id)
        burst_configuration = dao.store_entity(burst_configuration)
        simulator_index.fk_parent_burst = burst_configuration.id
        simulator_index = dao.store_entity(simulator_index)

        simulator_h5 = h5.path_for_stored_index(simulator_index)
        with SimulatorH5(simulator_h5) 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"
Beispiel #3
0
    def test_load_burst_only(self):
        zip_path = path.join(path.dirname(tvb_data.__file__), 'connectivity',
                             'connectivity_66.zip')
        TestFactory.import_zip_connectivity(self.test_user, self.test_project,
                                            zip_path, "John")
        connectivity = TestFactory.get_entity(self.test_project,
                                              ConnectivityIndex)

        simulator_index = SimulatorIndex()
        simulator_index.fill_from_has_traits(self.session_stored_simulator)

        burst_config = BurstConfiguration(self.test_project.id,
                                          simulator_index.id)
        burst_config = dao.store_entity(burst_config)

        simulator_index.fk_from_operation = burst_config.id
        simulator_index = dao.store_entity(simulator_index)
        simulator_index.fk_parent_burst = burst_config.id
        simulator_index = dao.store_entity(simulator_index)

        burst = dao.get_bursts_for_project(self.test_project.id)

        self.sess_mock['burst_id'] = str(burst[0].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(simulator_index.fk_from_operation))
        simulator_service = SimulatorService()
        SimulatorSerializer().serialize_simulator(
            self.session_stored_simulator, simulator_index.gid, None,
            storage_path)

        with patch('cherrypy.session', self.sess_mock, create=True):
            self.simulator_controller.load_burst_read_only(str(burst[0].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)

        database_simulator = dao.get_generic_entity(SimulatorIndex,
                                                    burst_config.id,
                                                    'fk_parent_burst')[0]

        assert simulator_index.gid == database_simulator.gid, "Simulator was not added correctly!"
        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!"