def test_compose_p2o_params(self): """Test whether p2o params are built correctly for a backend and a repository""" config = Config(CONF_FILE) task = Task(config) params = task._compose_p2o_params(BACKEND_NAME, REPO_NAME) self.assertEqual(params, {'url': REPO_NAME})
def test_get_collection_url(self): """Test whether the collection url could be overried in a backend""" config = Config(CONF_FILE) task = Task(config) task.backend_section = BACKEND_NAME self.assertEqual(task.conf['es_collection']['url'], COLLECTION_URL) self.assertEqual(task._get_collection_url(), COLLECTION_URL_STACKEXCHANGE)
def test_compose_p2o_params(self): """Test whether p2o params are built correctly for a backend and a repository""" config = Config(CONF_FILE) task = Task(config) params = task._compose_p2o_params( "stackexchange", "https://stackoverflow.com/questions/tagged/example") self.assertEqual( params, {'url': "https://stackoverflow.com/questions/tagged/example"})
def test_compose_perceval_params(self): """Test whether perceval params are built correctly for a backend and a repository""" config = Config(CONF_FILE) task = Task(config) params = [ '--site', 'stackoverflow.com', '--tagged', 'ovirt', '--tag', 'https://stackoverflow.com/questions/tagged/ovirt', '--api-token', 'token', '--fetch-cache' ] perceval_params = task._compose_perceval_params( BACKEND_NAME, REPO_NAME) self.assertEqual(params.sort(), perceval_params.sort())
def test_compose_perceval_params(self): """Test whether perceval params are built correctly for a backend and a repository""" expected_repo_params = json.loads( read_file('data/task-params-expected')) config = Config(CONF_FILE) task = Task(config) for backend in expected_repo_params.keys(): repo = expected_repo_params.get(backend)['repo'] perceval_params = task._compose_perceval_params(backend, repo) expected_params = expected_repo_params.get(backend)['params'] self.assertEqual(expected_params.sort(), perceval_params.sort())
def _get_repos_by_backend(self): # # return dict with backend and list of repositories # output = {} projects = TaskProjects.get_projects() for backend_section in Config.get_backend_sections(): for pro in projects: backend = Task.get_backend(backend_section) if backend in projects[pro]: if backend_section not in output: output[backend_section] = projects[pro][backend] else: output[backend_section] += projects[pro][backend] # backend could be in project/repo file but not enabled in # mordred conf file enabled = {} for k in output: if k in self.conf: enabled[k] = output[k] # logger.debug('repos to be retrieved: %s ', enabled) return enabled
def test_initialization(self): """Test whether attributes are initializated""" config = Config(CONF_FILE) task = Task(config) self.assertEqual(task.config, config) self.assertEqual(task.db_sh, task.conf['sortinghat']['database']) self.assertEqual(task.db_user, task.conf['sortinghat']['user']) self.assertEqual(task.db_password, task.conf['sortinghat']['password']) self.assertEqual(task.db_host, task.conf['sortinghat']['host'])
def get_repos_by_backend_section(cls, backend_section): """ return list with the repositories for a backend_section """ repos = [] backend = Task.get_backend(backend_section) projects = TaskProjects.get_projects() for pro in projects: if backend in projects[pro]: if (backend in Config.get_global_data_sources() and cls.GLOBAL_PROJECT in projects and pro != cls.GLOBAL_PROJECT): logger.debug("Skip global data source %s for project %s", backend, pro) else: repos += projects[pro][backend] logger.debug("List of repos for %s: %s", backend_section, repos) return repos
def test_run(self): """Test whether the Task could be run""" config = Config(CONF_FILE) task = Task(config) self.assertEqual(task.execute(), None)