def test_filters_on_categories(self, mocked_categories): # Given mocked_categories.return_value = test_categories catalog = Catalog() # When categories = catalog.country('usa').categories # Then mocked_categories.assert_called_once_with({COUNTRY_FILTER: 'usa'}) assert categories == test_categories
def test_filters_on_countries(self, mocked_countries): # Given mocked_countries.return_value = test_countries catalog = Catalog() # When countries = catalog.category('demographics').countries # Then mocked_countries.called_once_with({'category_id': 'demographics'}) assert countries == test_countries
def test_filters_private_geographies(self, mocked_geographies): # Given expected_geographies = [test_geography1, test_geography2] mocked_geographies.return_value = expected_geographies catalog = Catalog() # When geographies = catalog.public(False).geographies # Then mocked_geographies.assert_called_once_with({PUBLIC_FILTER: 'false'}) assert geographies == expected_geographies
def test_filters_private_datasets(self, mocked_datasets): # Given expected_datasets = [test_dataset1, test_dataset2] mocked_datasets.return_value = expected_datasets catalog = Catalog() # When datasets = catalog.public(False).datasets # Then mocked_datasets.assert_called_once_with({PUBLIC_FILTER: 'false'}) assert datasets == expected_datasets
def test_filters_on_datasets(self, mocked_datasets): # Given mocked_datasets.return_value = test_datasets catalog = Catalog() # When datasets = catalog.country('usa').category('demographics').datasets # Then mocked_datasets.assert_called_once_with({ COUNTRY_FILTER: 'usa', CATEGORY_FILTER: 'demographics' }) assert datasets == test_datasets
def test_filters_on_datasets(self, mocked_datasets): # Given mocked_datasets.return_value = test_datasets catalog = Catalog() # When datasets = catalog.country('usa').category('demographics').datasets # Then mocked_datasets.called_once_with({ 'country_id': 'usa', 'category_id': 'demographics' }) assert datasets == test_datasets
def test_subscriptions_wrong_credentials(self, mocked_geographies, mocked_datasets): # Given wrong_credentials = 1234 catalog = Catalog() # When with pytest.raises(ValueError) as e: catalog.subscriptions(wrong_credentials) # Then assert str( e.value) == ('Credentials attribute is required. ' 'Please pass a `Credentials` instance ' 'or use the `set_default_credentials` function.')
def test_geography_filter_by_slug(self, mocked_repo, mocked_datasets): # Given mocked_repo.return_value = test_geography1 mocked_datasets.return_value = test_datasets slug = 'esp_census_2019_4567890d' catalog = Catalog() # When datasets = catalog.geography(slug).datasets # Then mocked_repo.assert_called_once_with(slug) mocked_datasets.assert_called_once_with( {GEOGRAPHY_FILTER: test_geography1.id}) assert datasets == test_datasets
def test_subscriptions(self, mocked_geographies, mocked_datasets): # Given expected_datasets = [test_dataset1, test_dataset2] expected_geographies = [test_geography1, test_geography2] mocked_datasets.return_value = expected_datasets mocked_geographies.return_value = expected_geographies credentials = Credentials('user', '1234') catalog = Catalog() # When subscriptions = catalog.subscriptions(credentials) # Then mocked_datasets.assert_called_once_with({}, credentials) mocked_geographies.assert_called_once_with({}, credentials) assert isinstance(subscriptions, Subscriptions) assert subscriptions.datasets == expected_datasets assert subscriptions.geographies == expected_geographies
def test_datasets(self, mocked_datasets): # Given expected_datasets = [test_dataset1, test_dataset2] mocked_datasets.return_value = expected_datasets catalog = Catalog() # When datasets = catalog.datasets # Then assert datasets == expected_datasets
def test_providers(self, mocked_providers): # Given expected_providers = [test_provider1, test_provider2] mocked_providers.return_value = expected_providers catalog = Catalog() # When providers = catalog.providers # Then assert providers == expected_providers
def test_categories(self, mocked_categories): # Given expected_categories = [test_category1, test_category2] mocked_categories.return_value = expected_categories catalog = Catalog() # When categories = catalog.categories # Then assert categories == expected_categories
def test_all_filters(self, mocked_datasets): # Given mocked_datasets.return_value = test_datasets catalog = Catalog() # When datasets = catalog.country('usa').category('demographics') \ .geography('carto-do-public-data.tiger.geography_esp_census_2019').datasets # Then mocked_datasets.called_once_with({ 'country_id': 'usa', 'category_id': 'demographics', 'geography_id': 'carto-do-public-data.tiger.geography_esp_census_2019' }) assert datasets == test_datasets
def test_all_filters(self, mocked_datasets): # Given mocked_datasets.return_value = test_datasets catalog = Catalog() # When datasets = catalog.country('usa').category('demographics').public() \ .geography('carto-do-public-data.tiger.geography_esp_census_2019').datasets # Then mocked_datasets.assert_called_once_with({ COUNTRY_FILTER: 'usa', CATEGORY_FILTER: 'demographics', PUBLIC_FILTER: 'true', GEOGRAPHY_FILTER: 'carto-do-public-data.tiger.geography_esp_census_2019' }) assert datasets == test_datasets