def setUp(self): """ Reset the database before each test. """ self.clean_database() initialize_storage() self.test_user = TestFactory.create_user() self.test_project = TestFactory.create_project(self.test_user) self.operation_service = OperationService() self.backup_hdd_size = TVBSettings.MAX_DISK_SPACE
def initialize(introspected_modules, load_xml_events=True): """ Initialize when Application is starting. Check for new algorithms or new DataTypes. """ SettingsService().check_db_url(cfg.DB_URL) ## Initialize DB is_db_empty = initialize_startup() ## Create Projects storage root in case it does not exist. initialize_storage() ## Populate DB algorithms, by introspection event_folders = [] start_introspection_time = datetime.datetime.now() for module in introspected_modules: introspector = Introspector(module) # Introspection is always done, even if DB was not empty. introspector.introspect(True) event_path = introspector.get_events_path() if event_path: event_folders.append(event_path) # Now remove any unverified Algo-Groups, categories or Portlets invalid_stored_entities = dao.get_non_validated_entities( start_introspection_time) for entity in invalid_stored_entities: dao.remove_entity(entity.__class__, entity.id) ## Populate events if load_xml_events: eventhandler.read_events(event_folders) ## Make sure DB events are linked. db_events.attach_db_events() ## Create default users. if is_db_empty: dao.store_entity( model.User(cfg.SYSTEM_USER_NAME, None, None, True, None)) UserService().create_user(username=cfg.ADMINISTRATOR_NAME, password=cfg.ADMINISTRATOR_PASSWORD, email=cfg.ADMINISTRATOR_EMAIL, role=ROLE_ADMINISTRATOR) ## In case actions related to latest code-changes are needed, make sure they are executed. CodeUpdateManager().update_all()
def setUp(self): """ Reset the database before each test. """ initialize_storage() user = model.User("test_user", "test_pass", "*****@*****.**", True, "user") self.test_user = dao.store_entity(user) data = dict(name='test_proj', description='desc', users=[]) self.test_project = ProjectService().store_project(self.test_user, True, None, **data) meta = {DataTypeMetaData.KEY_SUBJECT: "John Doe", DataTypeMetaData.KEY_STATE: "RAW"} algo_group = dao.find_group(SIMULATOR_MODULE, SIMULATOR_CLASS) self.simulator_adapter = FlowService().build_adapter_instance(algo_group) self.operation = model.Operation(self.test_user.id, self.test_project.id, algo_group.id, json.dumps(SIMULATOR_PARAMETERS), meta=json.dumps(meta), status=model.STATUS_STARTED, method_name=ABCAdapter.LAUNCH_METHOD) self.operation = dao.store_entity(self.operation) SIMULATOR_PARAMETERS['connectivity'] = self._create_connectivity(self.CONNECTIVITY_NODES)
def test_xml_introspection(self): """ Check the XML introspection. The folders which are introspected are defined in the variable __xml_folders__ from tvb_test/adapters/_init.py """ self.introspector.introspect(True) initialize_storage() init_parameter = os.path.join("core", "adapters", "test_group.xml") group = dao.find_group("tvb_test.adapters.testgroupadapter", "TestGroupAdapter", init_parameter) self.assertTrue(group is not None, "The group was not found") self.assertEqual(group.init_parameter, init_parameter, "Wrong init_parameter:" + str(group.init_parameter)) self.assertEqual(group.displayname, "Simple Python Analyzers", "The display-name of the group is not valid") self.assertEqual(group.algorithm_param_name, "simple", "The algorithm_param_name of the group is not valid") self.assertEqual(group.classname, "TestGroupAdapter", "The class-name of the group is not valid") self.assertEqual(group.module, "tvb_test.adapters.testgroupadapter", "Group Module invalid")
def test_introspect(self): """ Test the actual introspect module on a test structure created in: tvb_test.dummy_adapters and tvb_test.dummy_datatypes """ self.introspector.introspect(True) initialize_storage() all_categories = dao.get_algorithm_categories() category_ids = [ cat.id for cat in all_categories if cat.displayname == "AdaptersTest" ] groups = dao.get_groups_by_categories(category_ids) self.assertEqual(len(groups), 11, "Introspection failed!") nr_adapters_mod2 = 0 for algorithm in groups: self.assertTrue( algorithm.module in [ 'tvb_test.adapters.testadapter1', 'tvb_test.adapters.testadapter2', 'tvb_test.adapters.testadapter3', 'tvb_test.adapters.ndimensionarrayadapter', "tvb.adapters.analyzers.group_python_adapter", "tvb_test.adapters.testgroupadapter" ], "Unknown Adapter:" + str(algorithm.module)) self.assertTrue( algorithm.classname in [ "TestAdapter1", "TestAdapterDatatypeInput", "TestAdapter2", "TestAdapter22", "TestAdapter3", "NDimensionArrayAdapter", "PythonAdapter", "TestAdapterHDDRequired", "TestAdapterHugeMemoryRequired", "TestAdapterNoMemoryImplemented", "TestGroupAdapter" ], "Unknown Adapter Class:" + str(algorithm.classname)) if algorithm.module == 'tvb_test.adapters.testadapter2': nr_adapters_mod2 = nr_adapters_mod2 + 1 self.assertEqual( nr_adapters_mod2, 2, "Two adapters should have been loaded from module tvb_test.adapters2!" )