How to use carto - 10 common examples

To help you get started, we’ve selected a few carto 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 / viz / helpers / test_cluster_size_layer.py View on Github external
def test_valid_operation(self):
        """cluster_size_layer should raise an error if the operation is invalid"""

        msg = '"invalid" is not a valid operation. Valid operations are count, avg, min, max, sum'
        with pytest.raises(CartoException) as e:
            helpers.cluster_size_layer(
                source=self.source,
                value='name',
                operation='invalid'
            )
        assert str(e.value) == msg
github CartoDB / cartoframes / tests / unit / viz / test_map.py View on Github external
def test_default_legend(self):
        """Map should raise an error if default_legend is True but there is no title"""

        msg = 'The default legend needs a map title to be displayed'
        with pytest.raises(CartoException) as e:
            Map(default_legend=True)
        assert str(e.value) == msg
github CartoDB / cartoframes / tests / unit / viz / test_layout.py View on Github external
def test__init_maps_valid(self):
        """Layout should raise an error if any element in the map list is not a Map"""

        msg = 'All the elements in the Layout should be an instance of Map'
        with pytest.raises(CartoException) as e:
            Layout([Layer(Source(SOURCE))])
        assert str(e.value) == msg
github CartoDB / cartoframes / test / viz / test_map.py View on Github external
def test_map_publish_unsync_fails(self):
        query = "SELECT 1"
        dataset = DatasetMock.from_query(query=query, context=self.context)
        dataset._is_saved_in_carto = False
        map = MapMock(Layer(Source(dataset)))

        msg = 'The map layers are not synchronized with CARTO. Please, use the `sync_data` before publishing the map'
        with self.assertRaises(CartoException, msg=msg):
            map.publish('test', context=self.context)
github CartoDB / cartoframes / test / test_context.py View on Github external
warnings.warn("Skipping CartoContext tests. To test it, "
                              "create a `secret.json` file in test/ by "
                              "renaming `secret.json.sample` to `secret.json` "
                              "and updating the credentials to match your "
                              "environment.")
                self.apikey = None
                self.username = None
        else:
            self.apikey = os.environ['APIKEY']
            self.username = os.environ['USERNAME']

        self.user_url = self.user_url()

        if self.username and self.apikey:
            self.baseurl = self.user_url.format(username=self.username)
            self.auth_client = APIKeyAuthClient(base_url=self.baseurl,
                                                api_key=self.apikey)
            self.sql_client = SQLClient(self.auth_client)

        # sets skip value
        WILL_SKIP = self.apikey is None or self.username is None  # noqa: F841

        # table naming info
        has_mpl = 'mpl' if os.environ.get('MPLBACKEND') else 'nonmpl'
        has_gpd = 'gpd' if os.environ.get('USE_GEOPANDAS') else 'nongpd'
        pyver = sys.version[0:3].replace('.', '_')
        buildnum = os.environ.get('TRAVIS_BUILD_NUMBER')

        test_slug = '{ver}_{num}_{mpl}_{gpd}'.format(
            ver=pyver, num=buildnum, mpl=has_mpl, gpd=has_gpd
        )
github CartoDB / cartoframes / test / test_batch.py View on Github external
'create a `secret.json` file in test/ by '
                              'renaming `secret.json.sample` to `secret.json` '
                              'and updating the credentials to match your '
                              'environment.')
                self.apikey = None
                self.username = None
        else:
            self.apikey = os.environ['APIKEY']
            self.username = os.environ['USERNAME']

        self.user_url = self.user_url()

        if self.username and self.apikey:
            self.baseurl = self.user_url.format(
                username=self.username)
            self.auth_client = APIKeyAuthClient(base_url=self.baseurl,
                                                api_key=self.apikey)
            self.sql_client = SQLClient(self.auth_client)

        # sets skip value
        WILL_SKIP = self.apikey is None or self.username is None  # noqa: F841
        has_mpl = 'mpl' if os.environ.get('MPLBACKEND') else 'nonmpl'
        has_gpd = 'gpd' if os.environ.get('HAS_GEOPANDAS') else 'nongpd'
        buildnum = os.environ.get('TRAVIS_BUILD_NUMBER')
        pyver = sys.version[0:3].replace('.', '_')

        # for writing to carto
        self.test_write_lnglat_table = (
            'cf_test_write_lnglat_table_{ver}_{num}_{mpl}_{gpd}'.format(
                ver=pyver,
                num=buildnum,
                gpd=has_gpd,
github CartoDB / carto-python / tests / test_sql.py View on Github external
def test_sql(api_key_auth_client_usr, mock_requests, do_post=True):
    with mock_requests.mocker:
        sql = SQLClient(api_key_auth_client_usr)
        data = sql.send('select * from ' + EXISTING_POINT_DATASET,
                        do_post=do_post)

    assert data is not None
    assert 'rows' in data
    assert 'total_rows' in data
    assert 'time' in data
    assert len(data['rows']) > 0
github CartoDB / carto-python / tests / test_sql.py View on Github external
def test_sql_unverified_fails_with_auth_client(wrong_onprem_auth_client):
    if wrong_onprem_auth_client is None:
        assert True is True
        return

    sql = SQLClient(wrong_onprem_auth_client)
    with pytest.raises(CartoException):
        data = sql.send('select version()')
github CartoDB / cartoframes / test / test_context.py View on Github external
"renaming `secret.json.sample` to `secret.json` "
                              "and updating the credentials to match your "
                              "environment.")
                self.apikey = None
                self.username = None
        else:
            self.apikey = os.environ['APIKEY']
            self.username = os.environ['USERNAME']

        self.user_url = self.user_url()

        if self.username and self.apikey:
            self.baseurl = self.user_url.format(username=self.username)
            self.auth_client = APIKeyAuthClient(base_url=self.baseurl,
                                                api_key=self.apikey)
            self.sql_client = SQLClient(self.auth_client)

        # sets skip value
        WILL_SKIP = self.apikey is None or self.username is None  # noqa: F841

        # table naming info
        has_mpl = 'mpl' if os.environ.get('MPLBACKEND') else 'nonmpl'
        has_gpd = 'gpd' if os.environ.get('USE_GEOPANDAS') else 'nongpd'
        pyver = sys.version[0:3].replace('.', '_')
        buildnum = os.environ.get('TRAVIS_BUILD_NUMBER')

        test_slug = '{ver}_{num}_{mpl}_{gpd}'.format(
            ver=pyver, num=buildnum, mpl=has_mpl, gpd=has_gpd
        )

        # test tables
        self.test_read_table = 'cb_2013_us_csa_500k'
github CartoDB / carto-python / tests / test_sql.py View on Github external
def test_no_auth_sql_error_get(no_auth_client):
    sql = SQLClient(no_auth_client)

    with pytest.raises(CartoException):
        sql.send('select * from non_existing_dataset', {'do_post': False})