def test_get_multiple_cities(self): with patch.dict(os.environ, {"QUERIDO_DIARIO_DATABASE_CSV": self.database_file}): database = CSVDatabase() cities = database.get_cities("taquarinha") expected_cities = [ City( "Taquarinha Do Norte", "1235", "RN", OpennessLevel("1"), ["https://somewebsite.org", "https://anotherwebsite.org"], ), City( "Taquarinha Do Sul", "1236", "RS", OpennessLevel("3"), ["https://somewebsite.org", "https://anotherwebsite.org"], ), ] self.assertCountEqual(expected_cities, cities)
def get_city(self, territory_id: str = None): with open(self.database_file) as database: reader = csv.DictReader(database) for row in reader: if territory_id == row["ibge_id"]: city = City( row["city_name"], row["ibge_id"], row["uf"], OpennessLevel(row["openness_level"]), self._split_urls(row["gazettes_urls"]), ) return city
def test_get_one_city_by_name(self): with patch.dict(os.environ, {"QUERIDO_DIARIO_DATABASE_CSV": self.database_file}): database = CSVDatabase() city = database.get_cities("pira") expected_city = City( "Piraporinha", "1234", "SC", OpennessLevel("2"), ["https://somewebsite.org"], ) self.assertCountEqual([expected_city], city)
def get_cities(self, city_name: str = None): results = [] with open(self.database_file) as database: reader = csv.DictReader(database) for row in reader: if city_name.lower() in row["city_name"].lower(): city = City( row["city_name"], row["ibge_id"], row["uf"], OpennessLevel(row["openness_level"]), self._split_urls(row["gazettes_urls"]), ) results.append(city) return results
def setUp(self): self.return_value = [ Gazette( "4205902", date.today(), "https://queridodiario.ok.org.br/", "so'jsdogjeogjsdogjheogdfsdf", "My city", "My state", "highlight" "123,456", False, ), Gazette( "4205902", (date.today() - timedelta(days=1)), "https://queridodiario.ok.org.br/", "a;oijaeofdjewofijrogho490jhfeasd", "My city", "My state", "highlight" "123,456", False, ), Gazette( "4205902", (date.today() + timedelta(days=1)), "https://queridodiario.ok.org.br/", "eolgpijdsfesuhrgfiuhsad", "My city", "My state", "highlight" "123,456", False, ), Gazette( "4202909", date.today(), "https://queridodiario.ok.org.br/", "ew;oigfdfsdjn;dajnorgf", "My city", "My state", "highlight" "123,456", False, ), Gazette( "4202909", (date.today() - timedelta(days=1)), "https://queridodiario.ok.org.br/", "sdosauiydhbfeicneqiudnewf", "My city", "My state", "highlight" "123,456", False, ), Gazette( "4202909", (date.today() + timedelta(days=1)), "https://queridodiario.ok.org.br/", "sdo;ifjwefonsdiasndiswabdisbfnidf", "My city", "My state", "highlight" "123,456", False, ), ] self.mock_data_gateway = MagicMock() self.mock_data_gateway.get_gazettes = MagicMock( return_value=(len(self.return_value), self.return_value) ) self.database_data = [ City( "Taquarinha Do Norte", "1235", "RN", OpennessLevel("1"), ["https://somewebsite.org", "https://anotherwebsite.org"], ), City( "Taquarinha Do Sul", "1236", "RS", OpennessLevel("3"), ["https://somewebsite.org", "https://anotherwebsite.org"], ), ] self.mock_database_gateway = MagicMock() self.mock_database_gateway.get_cities = MagicMock( return_value=self.database_data ) self.mock_database_gateway.get_city = MagicMock( return_value=self.database_data[0] ) self.gazette_access = GazetteAccess( self.mock_data_gateway, self.mock_database_gateway )