How to use the cartoframes.data.observatory.catalog.geography.Geography function in cartoframes

To help you get started, we’ve selected a few cartoframes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_subscription_info_wrong_credentials(self):
        # Given
        wrong_credentials = 1234
        geography = Geography(db_geography1)

        # When
        with pytest.raises(ValueError) as e:
            geography.subscription_info(wrong_credentials)

        # Then
        assert str(e.value) == '`credentials` must be a Credentials class instance'
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_subscription_info_without_do_enabled(self, mock_fetch):
        # Given
        def raise_exception(a, b, c):
            raise ServerErrorException(['The user does not have Data Observatory enabled'])
        mock_fetch.side_effect = raise_exception
        geography = Geography(db_geography1)
        credentials = Credentials('fake_user', '1234')

        # When
        with pytest.raises(Exception) as e:
            geography.subscription_info(credentials)

        # Then
        assert str(e.value) == (
            'We are sorry, the Data Observatory is not enabled for your account yet. '
            'Please contact your customer success manager or send an email to '
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_is_available_in(self):
        geography_in_bq = Geography(db_geography1)
        geography_not_in_bq = Geography(db_geography2)

        assert geography_in_bq._is_available_in('bq')
        assert not geography_not_in_bq._is_available_in('bq')
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_get_geography_by_id(self, mocked_repo):
        # Given
        mocked_repo.return_value = test_geography1

        # When
        geography = Geography.get(test_geography1.id)

        # Then
        assert isinstance(geography, object)
        assert isinstance(geography, Geography)
        assert geography == test_geography1
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_properties(self):
        # Given
        geography = Geography(db_geography1)

        # When
        geography_id = geography.id
        slug = geography.slug
        name = geography.name
        description = geography.description
        country = geography.country
        language = geography.language
        provider = geography.provider
        geom_coverage = geography.geom_coverage
        update_frequency = geography.update_frequency
        version = geography.version
        is_public_data = geography.is_public_data
        summary = geography.summary

        # Then
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_subscribe_default_credentials(
      self, mocked_credentials, mock_display_form, mock_subscription_ids):
        # Given
        expected_credentials = Credentials('fake_user', '1234')
        mocked_credentials.return_value = expected_credentials
        geography = Geography(db_geography1)

        # When
        geography.subscribe()

        # Then
        mock_subscription_ids.assert_called_once_with(expected_credentials)
        mock_display_form.assert_called_once_with(db_geography1['id'], 'geography', expected_credentials)
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
    @patch.object(GeographyRepository, 'get_by_id')
    def test_get_geography_by_id(self, mocked_repo):
        # Given
        mocked_repo.return_value = test_geography1

        # When
        geography = Geography.get(test_geography1.id)

        # Then
        assert isinstance(geography, object)
        assert isinstance(geography, Geography)
        assert geography == test_geography1
github CartoDB / cartoframes / cartoframes / data / observatory / catalog / geography.py View on Github external
def _is_subscribed(self, credentials):
        if self.is_public_data:
            return True

        geographies = Geography.get_all({}, credentials)

        return geographies is not None and self in geographies
github CartoDB / cartoframes / cartoframes / data / observatory / catalog / catalog.py View on Github external
Args:
            credentials (:py:class:`Credentials `, optional):
                credentials of CARTO user account. If not provided,
                a default credentials (if set with :py:meth:`set_default_credentials
                `) will be used.

        Returns:
            :py:class:`Subscriptions `
        """

        _no_filters = {}
        _credentials = get_credentials(credentials)

        return Subscriptions(
            Dataset.get_all(_no_filters, _credentials),
            Geography.get_all(_no_filters, _credentials)
        )
github CartoDB / cartoframes / cartoframes / data / observatory / enrichment / enrichment_service.py View on Github external
def _validate_bq_operations(variables, credentials):
    dataset_ids = list(set([variable.dataset for variable in variables]))

    for dataset_id in dataset_ids:
        dataset = Dataset.get(dataset_id)
        geography = Geography.get(dataset.geography)

        _is_subscribed(dataset, geography, credentials)
        _is_available_in_bq(dataset, geography)