def test_country_is_exported_as_dict(self): # Given country = Country(db_country1) # When country_dict = country.to_dict() # Then assert isinstance(country_dict, dict) assert country_dict == db_country1
def test_country_is_exported_as_series(self): # Given country = Country(db_country1) # When country_series = country.to_series() # Then assert isinstance(country_series, pd.Series) assert country_series['id'] == country.id
def test_country_properties(self): # Given country = Country(db_country1) # When country_id = country.id # Then assert country_id == db_country1['id']
def test_country_is_printed_with_classname(self): # Given country = Country(db_country1) # When country_str = str(country) # Then assert country_str == 'Country({dict_str})'.format( dict_str=str(db_country1))
def test_country_is_represented_with_classname_and_id(self): # Given country = Country(db_country1) # When country_repr = repr(country) # Then assert country_repr == "<Country.get('{id}')>".format( id=db_country1['id'])
def test_get_country_by_id(self, mocked_repo): # Given mocked_repo.return_value = test_country1 # When country = Country.get('esp') # Then assert isinstance(country, object) assert isinstance(country, Country) assert country == test_country1
def test_get_all_countries(self, mocked_repo): # Given mocked_repo.return_value = test_countries # When countries = Country.get_all() # Then assert isinstance(countries, list) assert isinstance(countries, CatalogList) assert countries == test_countries
def test_missing_fields_are_mapped_as_None(self, mocked_repo): # Given mocked_repo.return_value = [{}] repo = CountryRepository() expected_countries = CatalogList([Country({'id': None, 'name': None})]) # When countries = repo.get_all() # Then assert countries == expected_countries
from cartoframes.data.observatory.catalog.variable import Variable from cartoframes.data.observatory.catalog.dataset import Dataset from cartoframes.data.observatory.catalog.category import Category from cartoframes.data.observatory.catalog.geography import Geography from cartoframes.data.observatory.catalog.country import Country from cartoframes.data.observatory.catalog.provider import Provider from cartoframes.data.observatory.catalog.variable_group import VariableGroup from cartoframes.data.observatory.catalog.entity import CatalogList db_country1 = {'id': 'esp'} db_country2 = {'id': 'usa'} test_country1 = Country(db_country1) test_country2 = Country(db_country2) test_countries = CatalogList([test_country1, test_country2]) db_category1 = {'id': 'cat1', 'name': 'Financial'} db_category2 = {'id': 'cat2', 'name': 'Demographics'} test_category1 = Category(db_category1) test_category2 = Category(db_category2) test_categories = CatalogList([test_category1, test_category2]) db_geography1 = { 'id': 'carto-do-public.tiger.geography_esp_census_2019', 'slug': 'esp_census_2019_4567890d', 'name': 'ESP - Census', 'description': 'Geography data for Spanish census', 'provider_id': 'bbva', 'provider_name': 'bbva', 'country_id': 'esp', 'lang': 'esp', 'geom_coverage': '',