Пример #1
0
 def test_access_roles_setter(self):
     from gcloud.bigquery.dataset import AccessGrant
     client = _Client(self.PROJECT)
     dataset = self._makeOne(self.DS_NAME, client)
     phred = AccessGrant('OWNER', 'userByEmail', '*****@*****.**')
     bharney = AccessGrant('OWNER', 'userByEmail', '*****@*****.**')
     dataset.access_grants = [phred, bharney]
     self.assertEqual(dataset.access_grants, [phred, bharney])
Пример #2
0
    def test_create_w_alternate_client(self):
        from gcloud.bigquery.dataset import AccessGrant
        PATH = 'projects/%s/datasets' % self.PROJECT
        USER_EMAIL = '*****@*****.**'
        GROUP_EMAIL = '*****@*****.**'
        DESCRIPTION = 'DESCRIPTION'
        TITLE = 'TITLE'
        RESOURCE = self._makeResource()
        RESOURCE['description'] = DESCRIPTION
        RESOURCE['friendlyName'] = TITLE
        conn1 = _Connection()
        CLIENT1 = _Client(project=self.PROJECT, connection=conn1)
        conn2 = _Connection(RESOURCE)
        CLIENT2 = _Client(project=self.PROJECT, connection=conn2)
        dataset = self._makeOne(self.DS_NAME, client=CLIENT1)
        dataset.friendly_name = TITLE
        dataset.description = DESCRIPTION
        dataset.access_grants = [
            AccessGrant('OWNER', 'userByEmail', USER_EMAIL),
            AccessGrant('OWNER', 'groupByEmail', GROUP_EMAIL),
            AccessGrant('READER', 'specialGroup', 'projectReaders'),
            AccessGrant('WRITER', 'specialGroup', 'projectWriters')
        ]

        dataset.create(client=CLIENT2)

        self.assertEqual(len(conn1._requested), 0)
        self.assertEqual(len(conn2._requested), 1)
        req = conn2._requested[0]
        self.assertEqual(req['method'], 'POST')
        self.assertEqual(req['path'], '/%s' % PATH)
        SENT = {
            'datasetReference': {
                'projectId': self.PROJECT,
                'datasetId': self.DS_NAME
            },
            'description':
            DESCRIPTION,
            'friendlyName':
            TITLE,
            'access': [{
                'role': 'OWNER',
                'userByEmail': USER_EMAIL
            }, {
                'role': 'OWNER',
                'groupByEmail': GROUP_EMAIL
            }, {
                'role': 'READER',
                'specialGroup': 'projectReaders'
            }, {
                'role': 'WRITER',
                'specialGroup': 'projectWriters'
            }],
        }
        self.assertEqual(req['data'], SENT)
        self._verifyResourceProperties(dataset, RESOURCE)
Пример #3
0
 def test_access_roles_setter_invalid_field(self):
     from gcloud.bigquery.dataset import AccessGrant
     client = _Client(self.PROJECT)
     dataset = self._makeOne(self.DS_NAME, client)
     phred = AccessGrant('OWNER', 'userByEmail', '*****@*****.**')
     with self.assertRaises(ValueError):
         dataset.access_grants = [phred, object()]
Пример #4
0
    def _init_bigquery_dataset(self):
        from gcloud import bigquery
        from gcloud.bigquery.dataset import AccessGrant
        DATASET_URI = 'bigquery.googleapis.com/projects/%s/datasets/%s' % (
            Config.CLIENT.project,
            DATASET_NAME,
        )

        # Create the destination dataset, and set up the ACL to allow
        # Stackdriver Logging to write into it.
        bigquery_client = bigquery.Client()
        dataset = bigquery_client.dataset(DATASET_NAME)
        dataset.create()
        self.to_delete.append(dataset)
        dataset.reload()
        grants = dataset.access_grants
        grants.append(
            AccessGrant('WRITER', 'groupByEmail', '*****@*****.**'))
        dataset.access_grants = grants
        dataset.update()
        return DATASET_URI