Ejemplo n.º 1
0
def load_dataset(conf):
    from bqdm.model.dataset import BigQueryDataset

    echo('Load dataset config: {0}'.format(conf))
    with codecs.open(conf, 'rb', 'utf-8') as f:
        return BigQueryDataset.from_dict(yaml.load(f))
    def test_from_dict(self):
        expected_dataset1 = BigQueryDataset(dataset_id='test',
                                            friendly_name='test_friendly_name',
                                            description='test_description',
                                            default_table_expiration_ms=24 *
                                            60 * 60 * 1000,
                                            location='US')
        actual_dataset1_1 = BigQueryDataset.from_dict({
            'dataset_id':
            'test',
            'friendly_name':
            'test_friendly_name',
            'description':
            'test_description',
            'default_table_expiration_ms':
            24 * 60 * 60 * 1000,
            'location':
            'US',
            'labels':
            None,
            'access_entries':
            None
        })
        self.assertEqual(expected_dataset1, actual_dataset1_1)
        actual_dataset1_2 = BigQueryDataset.from_dict({
            'dataset_id':
            'test',
            'friendly_name':
            'foo_bar',
            'description':
            'fizz_buzz',
            'default_table_expiration_ms':
            60 * 60 * 1000,
            'location':
            'EU',
            'labels':
            None,
            'access_entries':
            None
        })
        self.assertNotEqual(expected_dataset1, actual_dataset1_2)

        expected_dataset2 = BigQueryDataset(
            dataset_id='test',
            friendly_name='test_friendly_name',
            description='test_description',
            default_table_expiration_ms=24 * 60 * 60 * 1000,
            location='US',
            access_entries=(BigQueryAccessEntry('OWNER', 'specialGroup',
                                                'projectOwners'), ))
        actual_dataset2_1 = BigQueryDataset.from_dict({
            'dataset_id':
            'test',
            'friendly_name':
            'test_friendly_name',
            'description':
            'test_description',
            'default_table_expiration_ms':
            24 * 60 * 60 * 1000,
            'location':
            'US',
            'labels':
            None,
            'access_entries': [
                {
                    'role': 'OWNER',
                    'entity_type': 'specialGroup',
                    'entity_id': 'projectOwners'
                },
            ]
        })
        self.assertEqual(expected_dataset2, actual_dataset2_1)
        actual_dataset2_2 = BigQueryDataset.from_dict({
            'dataset_id':
            'test',
            'friendly_name':
            'test_friendly_name',
            'description':
            'test_description',
            'default_table_expiration_ms':
            24 * 60 * 60 * 1000,
            'location':
            'US',
            'labels':
            None,
            'access_entries': [
                {
                    'role': None,
                    'entity_type': 'view',
                    'entity_id': {
                        'datasetId': 'test',
                        'projectId': 'test-project',
                        'tableId': 'test_table'
                    }
                },
            ]
        })
        self.assertNotEqual(expected_dataset2, actual_dataset2_2)

        expected_dataset3 = BigQueryDataset(dataset_id='test',
                                            friendly_name='test_friendly_name',
                                            description='test_description',
                                            default_table_expiration_ms=24 *
                                            60 * 60 * 1000,
                                            location='US',
                                            labels={'foo': 'bar'})
        actual_dataset3_1 = BigQueryDataset.from_dict({
            'dataset_id':
            'test',
            'friendly_name':
            'test_friendly_name',
            'description':
            'test_description',
            'default_table_expiration_ms':
            24 * 60 * 60 * 1000,
            'location':
            'US',
            'labels': {
                'foo': 'bar'
            },
            'access_entries':
            None
        })
        self.assertEqual(expected_dataset3, actual_dataset3_1)
        actual_dataset3_2 = BigQueryDataset.from_dict({
            'dataset_id':
            'test',
            'friendly_name':
            'test_friendly_name',
            'description':
            'test_description',
            'default_table_expiration_ms':
            24 * 60 * 60 * 1000,
            'location':
            'US',
            'labels': {
                'foo': 'bar',
                'fizz': 'buzz'
            },
            'access_entries':
            None
        })
        self.assertNotEqual(expected_dataset3, actual_dataset3_2)