예제 #1
0
    def test_category_is_exported_as_dict(self):
        # Given
        category = Category(db_category1)

        # When
        category_dict = category.to_dict()

        # Then
        assert isinstance(category_dict, dict)
        assert category_dict == db_category1
예제 #2
0
    def test_category_is_exported_as_series(self):
        # Given
        category = Category(db_category1)

        # When
        category_series = category.to_series()

        # Then
        assert isinstance(category_series, pd.Series)
        assert category_series['id'] == category.id
예제 #3
0
    def test_category_is_represented_with_classname_and_id(self):
        # Given
        category = Category(db_category1)

        # When
        category_repr = repr(category)

        # Then
        assert category_repr == "<Category.get('{id}')>".format(
            id=db_category1['id'])
예제 #4
0
    def test_category_is_printed_with_classname(self):
        # Given
        category = Category(db_category1)

        # When
        category_str = str(category)

        # Then
        assert category_str == "Category({dict_str})".format(
            dict_str=str(db_category1))
예제 #5
0
    def test_category_properties(self):
        # Given
        category = Category(db_category1)

        # When
        cat_id = category.id
        name = category.name

        # Then
        assert cat_id == db_category1['id']
        assert name == db_category1['name']
예제 #6
0
    def test_get_category_by_id(self, mocked_repo):
        # Given
        mocked_repo.return_value = test_category1

        # When
        category = Category.get('cat1')

        # Then
        assert isinstance(category, object)
        assert isinstance(category, Category)
        assert category == test_category1
예제 #7
0
    def test_get_all(self, mocked_repo):
        # Given
        mocked_repo.return_value = test_categories

        # When
        categories = Category.get_all()

        # Then
        assert isinstance(categories, list)
        assert isinstance(categories, CatalogList)
        assert categories == test_categories
예제 #8
0
    def test_missing_fields_are_mapped_as_None(self, mocked_repo):
        # Given
        mocked_repo.return_value = [{'id': 'cat1'}]
        repo = CategoryRepository()

        expected_categories = CatalogList([Category({
            'id': 'cat1',
            'name': None
        })])

        # When
        categories = repo.get_all()

        # Then
        assert categories == expected_categories
예제 #9
0
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': '',
    'geom_type': '',
    'update_frequency': 'monthly',