Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b822fe

Browse files
committed
Merge pull request #1658 from tseaver/logging-system_tests-sink_create_bigquery_dataset
Add system test for 'Sink.create' using a Bigquery dataset.
2 parents 8666e63 + 1f1ecad commit 1b822fe

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

system_tests/logging_.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
DEFAULT_FILTER = 'logName:syslog AND severity>=INFO'
2929
DEFAULT_DESCRIPTION = 'System testing'
3030
BUCKET_NAME = 'gcloud-python-system-testing-%d' % (_MILLIS,)
31+
DATASET_NAME = 'system_testing_dataset_%d' % (_MILLIS,)
3132

3233

3334
class Config(object):
@@ -148,3 +149,29 @@ def test_create_sink_storage_bucket(self):
148149
sink.create()
149150
self.to_delete.append(sink)
150151
self.assertTrue(sink.exists())
152+
153+
def test_create_sink_bigquery_dataset(self):
154+
from gcloud import bigquery
155+
from gcloud.bigquery.dataset import AccessGrant
156+
DATASET_URI = 'bigquery.googleapis.com/projects/%s/datasets/%s' % (
157+
Config.CLIENT.project, DATASET_NAME,)
158+
159+
# Create the destination dataset, and set up the ACL to allow
160+
# Cloud Logging to write into it.
161+
bigquery_client = bigquery.Client()
162+
dataset = bigquery_client.dataset(DATASET_NAME)
163+
dataset.create()
164+
self.to_delete.append(dataset)
165+
dataset.reload()
166+
grants = dataset.access_grants
167+
grants.append(AccessGrant(
168+
'WRITER', 'groupByEmail', '[email protected]'))
169+
dataset.access_grants = grants
170+
dataset.update()
171+
172+
sink = Config.CLIENT.sink(
173+
DEFAULT_SINK_NAME, DEFAULT_FILTER, DATASET_URI)
174+
self.assertFalse(sink.exists())
175+
sink.create()
176+
self.to_delete.append(sink)
177+
self.assertTrue(sink.exists())

0 commit comments

Comments
 (0)