Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

Commit 3752102

Browse files
author
Takashi Matsuo
authored
[iot] testing: re-raise the exception [(#3425)](GoogleCloudPlatform/python-docs-samples#3425)
fixes #3424
1 parent 393be3e commit 3752102

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

samples/api-client/manager/manager.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def delete_registry(
247247
return 'Registry deleted'
248248
except HttpError:
249249
print('Error, registry not deleted')
250-
return 'Registry not deleted'
250+
raise
251251
# [END iot_delete_registry]
252252

253253

@@ -391,10 +391,10 @@ def create_registry(
391391
return response
392392
except HttpError:
393393
print('Error, registry not created')
394-
return ""
394+
raise
395395
except AlreadyExists:
396396
print('Error, registry already exists')
397-
return ""
397+
raise
398398
# [END iot_create_registry]
399399

400400

@@ -422,12 +422,12 @@ def open_registry(
422422
# registry_id = 'your-registry-id'
423423
print('Creating registry')
424424

425-
response = create_registry(
426-
service_account_json, project_id, cloud_region,
427-
pubsub_topic, registry_id)
428-
429-
if response == '':
430-
# Device registry already exists
425+
try:
426+
response = create_registry(
427+
service_account_json, project_id, cloud_region,
428+
pubsub_topic, registry_id)
429+
except AlreadyExists:
430+
# Device registry already exists. We just re-use the existing one.
431431
print(
432432
'Registry {} already exists - looking it up instead.'.format(
433433
registry_id))

samples/api-client/manager/manager_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
3939

4040
pubsub_topic = 'projects/{}/topics/{}'.format(project_id, topic_id)
41+
42+
# This format is used in the `clean_up_registries()` below.
4143
registry_id = 'test-registry-{}-{}'.format(uuid.uuid1(), int(time.time()))
4244

4345

0 commit comments

Comments
 (0)