def test_run(self): """Test whether the Task could be run""" config = Config(CONF_FILE) cfg = config.get_conf() # We need to load the projects TaskProjects(config).execute() backend_section = GIT_BACKEND_SECTION task = TaskEnrich(config, backend_section=backend_section) self.assertEqual(task.execute(), None) # Check that the enrichment went well es_collection = cfg['es_collection']['url'] es_enrichment = cfg['es_enrichment']['url'] raw_index = es_collection + "/" + cfg[GIT_BACKEND_SECTION]['raw_index'] enrich_index = es_enrichment + "/" + cfg[GIT_BACKEND_SECTION][ 'enriched_index'] r = requests.get(raw_index + "/_search?size=0") raw_items = r.json()['hits']['total'] r = requests.get(enrich_index + "/_search?size=0") enriched_items = r.json()['hits']['total'] # the number of raw items is bigger since the enriched items are generated based on: # https://github.com/VizGrimoire/GrimoireLib # --filters-raw-prefix data.files.file:grimoirelib_alch data.files.file:README.md # see [git] section in tests/test-projects.json self.assertGreater(raw_items, enriched_items)
def test_studies(self): """Test whether the studies configuration works """ config = Config(CONF_FILE) cfg = config.get_conf() # We need to load the projects TaskProjects(config).execute() backend_section = GIT_BACKEND_SECTION task = TaskEnrich(config, backend_section=backend_section) self.assertEqual(task.execute(), None) # Configure a wrong study cfg['git']['studies'] = ['bad_study'] with self.assertRaises(RuntimeError): self.assertEqual(task.execute(), None) # Configure no studies cfg['git']['studies'] = None self.assertEqual(task.execute(), None) # Configure several studies cfg['git']['studies'] = ["enrich_demography", "enrich_areas_of_code"] self.assertEqual(task.execute(), None) # Configure several studies, one wrong cfg['git']['studies'] = ["enrich_demography", "enrich_areas_of_code1"] with self.assertRaises(RuntimeError): self.assertEqual(task.execute(), None)
def test_initialization(self): """Test whether attributes are initializated""" config = Config(CONF_FILE) cfg = config.get_conf() 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 setUp(self): config = Config(CONF_FILE) sh = config.get_conf()['sortinghat'] self.sh_kwargs = {'user': sh['user'], 'password': sh['password'], 'database': sh['database'], 'host': sh['host'], 'port': None} # Clean the database to start an empty state Database.drop(**self.sh_kwargs) # Create command Database.create(**self.sh_kwargs) self.sh_db = Database(**self.sh_kwargs)
def test_autogender(self): """Test whether autogender SH command is executed""" config = Config(CONF_FILE) # Test default value self.assertEqual(config.get_conf()['sortinghat']['gender'], False) config.get_conf()['sortinghat']['gender'] = True # Load some identities task = TaskIdentitiesLoad(config) task.execute() # Check the number of identities loaded from local and remote files uids = api.unique_identities(self.sh_db) task = TaskIdentitiesMerge(config) self.assertEqual(task.do_autogender(), None) uids = api.unique_identities(self.sh_db) found_genders = [uid.profile.gender for uid in uids] expected_genders = ['male', 'female', 'male', 'male'] self.assertEqual(found_genders, expected_genders)