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_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.assertDictEqual( params, {'url': "https://stackoverflow.com/questions/tagged/example"}) params = task._compose_p2o_params( "mediawiki", "https://wiki-archive.opendaylight.org " "https://wiki-archive.opendaylight.org/view") self.assertDictEqual( params, { 'url': "https://wiki-archive.opendaylight.org " "https://wiki-archive.opendaylight.org/view" }) params = task._compose_p2o_params( "mediawiki", "https://wiki-archive.opendaylight.org " "https://wiki-archive.opendaylight.org/view " "--filter-no-collection=true") self.assertDictEqual( params, { 'url': "https://wiki-archive.opendaylight.org " "https://wiki-archive.opendaylight.org/view", "filter-no-collection": "true" })
def test_get_collection_url(self): """Test whether the collection url could be overwritten in a backend""" config = Config(CONF_FILE) task = Task(config) task.backend_section = "stackexchange" self.assertEqual(task._get_collection_url(), COLLECTION_URL_STACKEXCHANGE)
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 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 test_extract_repo_tags(self): """Test the extraction of tags in repositories""" config = Config(CONF_FILE) task = Task(config) url, tags = task._extract_repo_tags("git", "https://github.com/zhquan_example/repo --labels=[ENG, SUPP]") self.assertEqual(url, "https://github.com/zhquan_example/repo") self.assertListEqual(tags, ["ENG", "SUPP"]) # By default it extracts '--labels' url, tags = task._extract_repo_tags("confluence", "https://example.com --spaces=[HOME]") self.assertEqual(url, "https://example.com --spaces=[HOME]") self.assertListEqual(tags, []) # To extracts '--spaces' add tag_type='spaces' url, tags = task._extract_repo_tags("confluence", "https://example.com --spaces=[HOME]", tag_type="spaces") self.assertEqual(url, "https://example.com") self.assertListEqual(tags, ["HOME"])
def test_run(self): """Test whether the Task could be run""" config = Config(CONF_FILE) task = Task(config) self.assertEqual(task.execute(), None)