How to use the cartoframes.data.observatory.catalog.dataset.Dataset 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_dataset.py View on Github external
def test_dataset_is_available_in_with_empty_field(self):
        # Given
        db_dataset = dict(db_dataset1)
        db_dataset['available_in'] = None
        dataset_null = Dataset(db_dataset)

        # Then
        assert not dataset_null._is_available_in('bq')
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_dataset_subscription_info_default_credentials(self, mocked_credentials, mock_fetch):
        # Given
        expected_credentials = Credentials('fake_user', '1234')
        mocked_credentials.return_value = expected_credentials
        dataset = Dataset(db_dataset1)

        # When
        dataset.subscription_info()

        # Then
        mock_fetch.assert_called_once_with(db_dataset1['id'], 'dataset', expected_credentials)
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_dataset_is_printed_with_classname(self):
        # Given
        dataset = Dataset(db_dataset1)

        # When
        dataset_str = str(dataset)

        # Then
        assert dataset_str == "".format(id=db_dataset1['slug'])
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_dataset_subscribe_wrong_credentials(self):
        # Given
        wrong_credentials = 1234
        dataset = Dataset(db_dataset1)

        # When
        with pytest.raises(AttributeError) as e:
            dataset.subscribe(wrong_credentials)

        # Then
        assert str(e.value) == ('Credentials attribute is required. '
                                'Please pass a `Credentials` instance '
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_summary_values(self):
        # Given
        dataset = Dataset(db_dataset2)

        # When
        summary = dataset.summary

        # Then

        assert summary == dataset.data['summary_json']
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_dataset_subscribe(self, mock_display_message, mock_display_form, mock_subscription_ids):
        # Given
        expected_id = db_dataset1['id']
        expected_subscribed_ids = []
        mock_subscription_ids.return_value = expected_subscribed_ids
        credentials = Credentials('fake_user', '1234')
        dataset = Dataset(db_dataset1)

        # When
        dataset.subscribe(credentials)

        # Then
        mock_subscription_ids.assert_called_once_with(credentials)
        mock_display_form.assert_called_once_with(expected_id, 'dataset', credentials)
        assert not mock_display_message.called
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_dataset_is_exported_as_dict(self):
        # Given
        dataset = Dataset(db_dataset1)
        excluded_fields = ['summary_json', 'available_in']
        expected_dict = {key: value for key, value in db_dataset1.items() if key not in excluded_fields}

        # When
        dataset_dict = dataset.to_dict()

        # Then
        assert isinstance(dataset_dict, dict)
        assert dataset_dict == expected_dict
github CartoDB / cartoframes / tests / unit / data / observatory / catalog / test_dataset.py View on Github external
def test_dataset_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
        dataset = Dataset(db_dataset1)
        credentials = Credentials('fake_user', '1234')

        # When
        with pytest.raises(Exception) as e:
            dataset.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 / 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)
github CartoDB / cartoframes / cartoframes / data / observatory / catalog / dataset.py View on Github external
def _is_subscribed(self, credentials):
        if self.is_public_data:
            return True

        datasets = Dataset.get_all({}, credentials)

        return datasets is not None and self in datasets