Skip to content

Commit

Permalink
Merge pull request #1658 from tseaver/logging-system_tests-sink_creat…
Browse files Browse the repository at this point in the history
…e_bigquery_dataset

Add system test for 'Sink.create' using a Bigquery dataset.
  • Loading branch information
tseaver committed Mar 28, 2016
2 parents 8666e63 + 1f1ecad commit 1b822fe
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions system_tests/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
DEFAULT_FILTER = 'logName:syslog AND severity>=INFO'
DEFAULT_DESCRIPTION = 'System testing'
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
DATASET_NAME = 'system_testing_dataset_%d' % (_MILLIS,)


class Config(object):
Expand Down Expand Up @@ -148,3 +149,29 @@ def test_create_sink_storage_bucket(self):
sink.create()
self.to_delete.append(sink)
self.assertTrue(sink.exists())

def test_create_sink_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
# Cloud 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', 'cloud-logs@google.com'))
dataset.access_grants = grants
dataset.update()

sink = Config.CLIENT.sink(
DEFAULT_SINK_NAME, DEFAULT_FILTER, DATASET_URI)
self.assertFalse(sink.exists())
sink.create()
self.to_delete.append(sink)
self.assertTrue(sink.exists())

0 comments on commit 1b822fe

Please sign in to comment.