From 375210291676037913e7a5b0a9c5e45cf01b4c40 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Fri, 17 Apr 2020 14:02:38 -0700 Subject: [PATCH] [iot] testing: re-raise the exception [(#3425)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3425) fixes #3424 --- samples/api-client/manager/manager.py | 18 +++++++++--------- samples/api-client/manager/manager_test.py | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/samples/api-client/manager/manager.py b/samples/api-client/manager/manager.py index d20a3de7..27e1fa07 100644 --- a/samples/api-client/manager/manager.py +++ b/samples/api-client/manager/manager.py @@ -247,7 +247,7 @@ def delete_registry( return 'Registry deleted' except HttpError: print('Error, registry not deleted') - return 'Registry not deleted' + raise # [END iot_delete_registry] @@ -391,10 +391,10 @@ def create_registry( return response except HttpError: print('Error, registry not created') - return "" + raise except AlreadyExists: print('Error, registry already exists') - return "" + raise # [END iot_create_registry] @@ -422,12 +422,12 @@ def open_registry( # registry_id = 'your-registry-id' print('Creating registry') - response = create_registry( - service_account_json, project_id, cloud_region, - pubsub_topic, registry_id) - - if response == '': - # Device registry already exists + try: + response = create_registry( + service_account_json, project_id, cloud_region, + pubsub_topic, registry_id) + except AlreadyExists: + # Device registry already exists. We just re-use the existing one. print( 'Registry {} already exists - looking it up instead.'.format( registry_id)) diff --git a/samples/api-client/manager/manager_test.py b/samples/api-client/manager/manager_test.py index cdd86139..175f0475 100644 --- a/samples/api-client/manager/manager_test.py +++ b/samples/api-client/manager/manager_test.py @@ -38,6 +38,8 @@ service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS'] pubsub_topic = 'projects/{}/topics/{}'.format(project_id, topic_id) + +# This format is used in the `clean_up_registries()` below. registry_id = 'test-registry-{}-{}'.format(uuid.uuid1(), int(time.time()))