コード例 #1
0
    def test_missing_fields_are_mapped_as_None(self, mocked_repo):
        # Given
        mocked_repo.return_value = [{'id': 'variable1'}]
        repo = VariableRepository()

        expected_variables = CatalogList([
            Variable({
                'id': 'variable1',
                'slug': None,
                'name': None,
                'description': None,
                'column_name': None,
                'db_type': None,
                'dataset_id': None,
                'agg_method': None,
                'variable_group_id': None,
                'summary_json': None
            })
        ])

        # When
        variables = repo.get_all()

        # Then
        assert variables == expected_variables
コード例 #2
0
    def test_missing_fields_are_mapped_as_None(self, mocked_repo):
        # Given
        mocked_repo.return_value = [{'id': 'geography1'}]
        repo = GeographyRepository()

        expected_geographies = CatalogList([Geography({
            'id': 'geography1',
            'slug': None,
            'name': None,
            'description': None,
            'provider_id': None,
            'provider_name': None,
            'country_id': None,
            'lang': None,
            'geom_coverage': None,
            'geom_type': None,
            'update_frequency': None,
            'version': None,
            'is_public_data': None,
            'summary_json': None
        })])

        # When
        geographies = repo.get_all()

        # Then
        assert geographies == expected_geographies
コード例 #3
0
    def test_missing_fields_are_mapped_as_None(self, mocked_repo):
        # Given
        mocked_repo.return_value = [{'id': 'dataset1'}]
        repo = DatasetRepository()

        expected_datasets = CatalogList([
            Dataset({
                'id': 'dataset1',
                'slug': None,
                'name': None,
                'description': None,
                'provider_id': None,
                'provider_name': None,
                'category_id': None,
                'category_name': None,
                'data_source_id': None,
                'country_id': None,
                'lang': None,
                'geography_id': None,
                'geography_name': None,
                'geography_description': None,
                'temporal_aggregation': None,
                'time_coverage': None,
                'update_frequency': None,
                'version': None,
                'is_public_data': None,
                'summary_json': None
            })
        ])

        # When
        datasets = repo.get_all()

        # Then
        assert datasets == expected_datasets
コード例 #4
0
    def test_geography_list_is_represented_with_classname_and_slugs(self):
        # Given
        geographies = CatalogList([test_geography1, test_geography2])

        # When
        categories_repr = repr(geographies)

        # Then
        assert categories_repr == "[<Geography.get('{id1}')>, <Geography.get('{id2}')>]"\
                                  .format(id1=db_geography1['slug'], id2=db_geography2['slug'])
コード例 #5
0
ファイル: test_dataset.py プロジェクト: bonomali/cartoframes
    def test_dataset_list_is_represented_with_classname_and_slugs(self):
        # Given
        datasets = CatalogList([test_dataset1, test_dataset2])

        # When
        datasets_repr = repr(datasets)

        # Then
        assert datasets_repr == "[<Dataset.get('{id1}')>, <Dataset.get('{id2}')>]"\
                                .format(id1=db_dataset1['slug'], id2=db_dataset2['slug'])
コード例 #6
0
    def test_category_list_is_represented_with_classname_and_ids(self):
        # Given
        categories = CatalogList([test_category1, test_category2])

        # When
        categories_repr = repr(categories)

        # Then
        assert categories_repr == "[<Category.get('{id1}')>, <Category.get('{id2}')>]"\
                                  .format(id1=db_category1['id'], id2=db_category2['id'])
コード例 #7
0
    def test_country_list_is_printed_with_classname_and_ids(self):
        # Given
        countries = CatalogList([test_country1, test_country2])

        # When
        countries_str = str(countries)

        # Then
        assert countries_str == "[<Country.get('{id1}')>, <Country.get('{id2}')>]" \
                                .format(id1=db_country1['id'], id2=db_country2['id'])
コード例 #8
0
    def test_provider_list_is_represented_with_classname_and_ids(self):
        # Given
        providers = CatalogList([test_provider1, test_provider2])

        # When
        providers_repr = repr(providers)

        # Then
        assert providers_repr == "[<Provider.get('{id1}')>, <Provider.get('{id2}')>]"\
                                 .format(id1=db_provider1['id'], id2=db_provider2['id'])
コード例 #9
0
    def test_variable_group_list_is_represented_with_classname_and_slug(self):
        # Given
        variables_groups = CatalogList(
            [test_variable_group1, test_variable_group2])

        # When
        variables_groups_repr = repr(variables_groups)

        # Then
        assert variables_groups_repr == "[<VariableGroup.get('{id1}')>, <VariableGroup.get('{id2}')>]"\
                                        .format(id1=db_variable_group1['slug'], id2=db_variable_group2['slug'])
コード例 #10
0
    def test_country_list_is_represented_with_classname_and_ids(self):
        # Given
        countries = CatalogList([test_country1, test_country2])

        # When
        countries_repr = repr(countries)

        # Then
        assert countries_repr == "[<Country.get('{id1}')> #'{descr1}', <Country.get('{id2}')> #'{descr2}']" \
                                 .format(id1=db_country1['id'], descr1=db_country1['name'],
                                         id2=db_country2['id'], descr2=db_country2['name'])
コード例 #11
0
    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
コード例 #12
0
    def test_variable_list_is_represented_correctly(self):
        # Given
        variables = CatalogList([test_variable1, test_variable2])
        shorten_description = test_variable2.description[0:50] + '...'

        # When
        variables_repr = repr(variables)

        # Then
        assert variables_repr == "[<Variable.get('{id1}')> #'{descr1}', <Variable.get('{id2}')> #'{descr2}']" \
                                 .format(id1=db_variable1['slug'], descr1=db_variable1['description'],
                                         id2=db_variable2['slug'], descr2=shorten_description)
コード例 #13
0
    def test_missing_fields_are_mapped_as_None(self, mocked_repo):
        # Given
        mocked_repo.return_value = [{'id': 'provider1'}]
        repo = ProviderRepository()

        expected_providers = CatalogList(
            [Provider({
                'id': 'provider1',
                'name': None
            })])

        # When
        providers = repo.get_all()

        # Then
        assert providers == expected_providers
コード例 #14
0
    def test_missing_fields_are_mapped_as_None(self, mocked_repo):
        # Given
        mocked_repo.return_value = [{'id': 'variable_group1'}]
        repo = VariableGroupRepository()

        expected_variables_groups = CatalogList([
            VariableGroup({
                'id': 'variable_group1',
                'slug': None,
                'name': None,
                'dataset_id': None
            })
        ])

        # When
        variables_groups = repo.get_all()

        # Then
        assert variables_groups == expected_variables_groups
コード例 #15
0
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': '',