How to use cartoframes - 10 common examples

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 / io / test_carto.py View on Github external
def test_read_carto_limit(mocker):
    # Given
    mocker.patch.object(CartoDataFrame, 'set_geometry')
    cm_mock = mocker.patch.object(ContextManager, 'copy_to')

    # When
    read_carto('__source__', CREDENTIALS, limit=1)

    # Then
    cm_mock.assert_called_once_with('__source__', None, 1, 3)
github CartoDB / cartoframes / tests / unit / auth / test_credentials.py View on Github external
def test_credentials_constructor(self):
        credentials = Credentials(self.username, self.api_key)

        assert credentials.api_key == self.api_key
        assert credentials.username == self.username
        assert credentials.base_url == self.base_url.strip('/')
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_download(self, mocked_bq_client, get_by_id_mock, get_all_mock):
        # Given
        get_by_id_mock.return_value = test_geography1
        geography = Geography.get(test_geography1.id)
        get_all_mock.return_value = [geography]
        mocked_bq_client.return_value = BigQueryClientMock()
        credentials = Credentials('fake_user', '1234')

        # Then
        geography.download('fake_path', credentials)
github CartoDB / cartoframes / test / data / observatory / test_dataset.py View on Github external
def test_dataset_download_raises_with_nonpurchased(self, mocked_bq_client, mocked_repo):
        # mock dataset
        mocked_repo.return_value = test_dataset1

        # mock big query client
        mocked_bq_client.return_value = BigQueryClientMock(NotFound('Fake error'))

        # test
        username = 'fake_user'
        credentials = Credentials(username, '1234')

        dataset = Dataset.get(test_dataset1.id)
        with self.assertRaises(CartoException):
            dataset.download(credentials)
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_catalog.py View on Github external
def test_subscriptions_default_credentials(self, mocked_credentials, mocked_geographies, mocked_datasets):
        # Given
        expected_datasets = [test_dataset1, test_dataset2]
        expected_geographies = [test_geography1, test_geography2]
        expected_credentials = Credentials('user', '1234')
        mocked_datasets.return_value = expected_datasets
        mocked_geographies.return_value = expected_geographies
        mocked_credentials.return_value = expected_credentials
        catalog = Catalog()

        # When
        subscriptions = catalog.subscriptions()

        # Then
        mocked_datasets.assert_called_once_with({}, expected_credentials)
        mocked_geographies.assert_called_once_with({}, expected_credentials)
        assert isinstance(subscriptions, Subscriptions)
        assert subscriptions.datasets == expected_datasets
        assert subscriptions.geographies == expected_geographies
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_get_all_geographies_credentials_without_do_enabled(self, mocked_repo):
        # Given
        def raise_exception(a, b):
            raise ServerErrorException(['The user does not have Data Observatory enabled'])
        mocked_repo.side_effect = raise_exception
        credentials = Credentials('fake_user', '1234')

        # When
        with pytest.raises(Exception) as e:
            Geography.get_all(credentials=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 / viz / test_source.py View on Github external
def test_source_get_credentials_username(self, mocker):
        """Source should return the correct credentials when username is provided"""
        setup_mocks(mocker)
        source = Source('faketable', credentials=Credentials(
            username='fakeuser', api_key='1234'))

        credentials = source.get_credentials()

        assert credentials['username'] == 'fakeuser'
        assert credentials['api_key'] == '1234'
        assert credentials['base_url'] == 'https://fakeuser.carto.com'
github CartoDB / cartoframes / tests / unit / data / observatory / enrichment / test_polygon_enrichment.py View on Github external
def setup_method(self):
        self.original_bigquery_Client = bigquery.Client
        bigquery.Client = Mock(return_value=True)
        self.original_storage_Client = storage.Client
        storage.Client = Mock(return_value=True)
        self.original_get_do_credentials = Credentials.get_do_credentials
        Credentials.get_do_credentials = Mock(return_value=DoCredentials(_PUBLIC_PROJECT, _WORKING_PROJECT))
        self.username = 'username'
        self.apikey = 'apikey'
        self.credentials = Credentials(self.username, self.apikey)
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_geography.py View on Github external
def test_geography_download_without_do_enabled(self, mocked_bq_client, get_by_id_mock, get_all_mock):
        # Given
        get_by_id_mock.return_value = test_geography1
        geography = Geography.get(test_geography1.id)
        get_all_mock.return_value = []
        mocked_bq_client.return_value = BigQueryClientMock(
            ServerErrorException(['The user does not have Data Observatory enabled'])
        )
        credentials = Credentials('fake_user', '1234')

        # When
        with pytest.raises(Exception) as e:
            geography.download('fake_path', 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 / auth / test_credentials.py View on Github external
def test_credentials_baseurl_without_https(self):
        with pytest.raises(ValueError):
            Credentials(api_key=self.api_key, base_url=self.base_url.replace('https', 'http'))