Ejemplo n.º 1
0
    def test_get_by_id_unknown_fails(self, mocked_repo):
        # Given
        mocked_repo.return_value = []
        requested_iso_code = 'fra'
        repo = CountryRepository()

        # Then
        with pytest.raises(CatalogError):
            repo.get_by_id(requested_iso_code)
Ejemplo n.º 2
0
    def test_get_all_when_empty(self, mocked_repo):
        # Given
        mocked_repo.return_value = []
        repo = CountryRepository()

        # When
        countries = repo.get_all()

        # Then
        assert countries == []
Ejemplo n.º 3
0
    def test_get_all(self, mocked_repo):
        # Given
        mocked_repo.return_value = [db_country1, db_country2]
        repo = CountryRepository()

        # When
        countries = repo.get_all()

        # Then
        mocked_repo.assert_called_once_with(None)
        assert isinstance(countries, CatalogList)
        assert countries == test_countries
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def test_get_by_id_list(self, mocked_repo):
        # Given
        mocked_repo.return_value = [db_country1, db_country2]
        repo = CountryRepository()

        # When
        countries = repo.get_by_id_list([db_country1['id'], db_country2['id']])

        # Then
        mocked_repo.assert_called_once_with({'id': [db_country1['id'], db_country2['id']]})
        assert isinstance(countries, CatalogList)
        assert countries == test_countries
Ejemplo n.º 6
0
    def test_get_by_id(self, mocked_repo):
        # Given
        mocked_repo.return_value = [db_country1, db_country2]
        requested_iso_code = db_country1['id']
        repo = CountryRepository()

        # When
        country = repo.get_by_id(requested_iso_code)

        # Then
        mocked_repo.assert_called_once_with({'id': [requested_iso_code]})
        assert isinstance(country, Country)
        assert country == test_country1
    def test_get_all_only_uses_allowed_filters(self, mocked_repo):
        # Given
        mocked_repo.return_value = [db_country1, db_country2]
        repo = CountryRepository()
        filters = {
            'dataset_id': 'carto-do.project.census2011',
            'category_id': 'demographics',
            'variable_id': 'population',
            'geography_id': 'census-geo',
            'variable_group_id': 'var-group',
            'provider_id': 'open_data',
            'fake_field_id': 'fake_value'
        }

        # When
        countries = repo.get_all(filters)

        # Then
        mocked_repo.assert_called_once_with({'category_id': 'demographics'})
        assert countries == test_countries
Ejemplo n.º 8
0
    def test_get_all_only_uses_allowed_filters(self, mocked_repo):
        # Given
        mocked_repo.return_value = [db_country1, db_country2]
        repo = CountryRepository()
        filters = {
            DATASET_FILTER: 'carto-do.project.census2011',
            CATEGORY_FILTER: 'demographics',
            VARIABLE_FILTER: 'population',
            GEOGRAPHY_FILTER: 'census-geo',
            VARIABLE_GROUP_FILTER: 'var-group',
            PROVIDER_FILTER: 'open_data',
            'fake_field_id': 'fake_value'
        }

        # When
        countries = repo.get_all(filters)

        # Then
        mocked_repo.assert_called_once_with({
            CATEGORY_FILTER: 'demographics',
            PROVIDER_FILTER: 'open_data'
        })
        assert countries == test_countries