From 413da95a4bfb89a0bf3e740feda289d8aa2995df Mon Sep 17 00:00:00 2001 From: t-karasova <91195610+t-karasova@users.noreply.github.com> Date: Thu, 10 Mar 2022 16:06:41 +0100 Subject: [PATCH] test: create bq table fixed (#184) Co-authored-by: tetiana-karasova Co-authored-by: Anthonios Partheniou --- .../events/setup_events/setup_cleanup.py | 18 ++++++++++-------- .../product/add_fulfillment_places.py | 8 ++------ .../product/remove_fulfillment_places.py | 8 ++------ .../product/set_inventory.py | 8 +++----- .../product/setup_product/setup_cleanup.py | 18 ++++++++++-------- .../product/update_product.py | 4 ---- 6 files changed, 27 insertions(+), 37 deletions(-) diff --git a/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py b/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py index 53dd775cb692..d1d0fe3507e5 100644 --- a/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py +++ b/generated_samples/interactive-tutorials/events/setup_events/setup_cleanup.py @@ -171,17 +171,19 @@ def create_bq_table(dataset, table_name, schema_file_path): """Create a BigQuery table""" full_table_id = f"{project_id}.{dataset}.{table_name}" bq = bigquery.Client() - print(f"Creating BigQuery table {full_table_id}") + print(f"Check if BQ table {full_table_id} exists") try: bq.get_table(full_table_id) - print(f"table {full_table_id} already exists") + print(f"table {full_table_id} exists and will be deleted") + delete_bq_table(dataset, table_name) except NotFound: - # Construct a Table object to send to the API. - with open(schema_file_path, "rb") as schema: - schema_dict = json.load(schema) - table = bigquery.Table(full_table_id, schema=schema_dict) - bq.create_table(table) - print("table is created") + print(f"table {full_table_id} does not exist") + # Construct a Table object to send to the API. + with open(schema_file_path, "rb") as schema: + schema_dict = json.load(schema) + table = bigquery.Table(full_table_id, schema=schema_dict) + bq.create_table(table) + print(f"table {full_table_id} is created") def delete_bq_table(dataset, table_name): diff --git a/generated_samples/interactive-tutorials/product/add_fulfillment_places.py b/generated_samples/interactive-tutorials/product/add_fulfillment_places.py index e062701d5e06..1a791c6ff5fb 100644 --- a/generated_samples/interactive-tutorials/product/add_fulfillment_places.py +++ b/generated_samples/interactive-tutorials/product/add_fulfillment_places.py @@ -34,7 +34,6 @@ # The request timestamp current_date = datetime.datetime.now() -outdated_date = datetime.datetime.now() - datetime.timedelta(days=1) # add fulfillment request @@ -63,8 +62,8 @@ def add_fulfillment_places(product_name: str, timestamp, place_id): # This is a long running operation and its result is not immediately present with get operations, # thus we simulate wait with sleep method. - print("---add fulfillment places, wait 40 seconds :---") - time.sleep(40) + print("---add fulfillment places, wait 90 seconds :---") + time.sleep(90) # [END retail_add_fulfillment_places] @@ -74,7 +73,4 @@ def add_fulfillment_places(product_name: str, timestamp, place_id): print("------add fulfilment places with current date: {}-----".format(current_date)) add_fulfillment_places(product_name, current_date, "store2") get_product(product_name) -print("------add outdated fulfilment places: {}-----".format(outdated_date)) -add_fulfillment_places(product_name, outdated_date, "store3") -get_product(product_name) delete_product(product_name) diff --git a/generated_samples/interactive-tutorials/product/remove_fulfillment_places.py b/generated_samples/interactive-tutorials/product/remove_fulfillment_places.py index 8a12452162d9..654daffcd58c 100644 --- a/generated_samples/interactive-tutorials/product/remove_fulfillment_places.py +++ b/generated_samples/interactive-tutorials/product/remove_fulfillment_places.py @@ -34,7 +34,6 @@ # The request timestamp current_date = datetime.datetime.now() -outdated_date = datetime.datetime.now() - datetime.timedelta(days=1) # remove fulfillment request @@ -63,8 +62,8 @@ def remove_fulfillment_places(product_name: str, timestamp, store_id): # This is a long running operation and its result is not immediately present with get operations, # thus we simulate wait with sleep method. - print("---remove fulfillment places, wait 40 seconds:---") - time.sleep(40) + print("---remove fulfillment places, wait 90 seconds:---") + time.sleep(90) # [END retail_remove_fulfillment_places] @@ -74,7 +73,4 @@ def remove_fulfillment_places(product_name: str, timestamp, store_id): print("------remove fulfilment places with current date: {}-----".format(current_date)) remove_fulfillment_places(product_name, current_date, "store0") get_product(product_name) -print("------remove outdated fulfilment places: {}-----".format(outdated_date)) -remove_fulfillment_places(product_name, outdated_date, "store1") -get_product(product_name) delete_product(product_name) diff --git a/generated_samples/interactive-tutorials/product/set_inventory.py b/generated_samples/interactive-tutorials/product/set_inventory.py index 4a51f9874bf7..58dc83506152 100644 --- a/generated_samples/interactive-tutorials/product/set_inventory.py +++ b/generated_samples/interactive-tutorials/product/set_inventory.py @@ -44,7 +44,7 @@ def get_product_with_inventory_info(product_name: str) -> Product: price_info = PriceInfo() price_info.price = 15.0 - price_info.original_price = 20.0 + price_info.original_price = 60.0 price_info.cost = 8.0 price_info.currency_code = "USD" @@ -65,8 +65,6 @@ def get_product_with_inventory_info(product_name: str) -> Product: def get_set_inventory_request(product_name: str) -> SetInventoryRequest: # The request timestamp request_time = datetime.datetime.now() - # The out-of-order request timestamp - # request_time = datetime.datetime.now() - datetime.timedelta(days=1) set_mask = FieldMask( paths=["price_info", "availability", "fulfillment_info", "available_quantity"] ) @@ -90,8 +88,8 @@ def set_inventory(product_name: str): # This is a long running operation and its result is not immediately present with get operations, # thus we simulate wait with sleep method. - print("---set inventory, wait 60 seconds:---") - time.sleep(60) + print("---set inventory, wait 90 seconds:---") + time.sleep(90) create_product(product_id) diff --git a/generated_samples/interactive-tutorials/product/setup_product/setup_cleanup.py b/generated_samples/interactive-tutorials/product/setup_product/setup_cleanup.py index c0232c7421f3..686163b96618 100644 --- a/generated_samples/interactive-tutorials/product/setup_product/setup_cleanup.py +++ b/generated_samples/interactive-tutorials/product/setup_product/setup_cleanup.py @@ -180,17 +180,19 @@ def create_bq_table(dataset, table_name, schema_file_path): """Create a BigQuery table""" full_table_id = f"{project_id}.{dataset}.{table_name}" bq = bigquery.Client() - print(f"Creating BigQuery table {full_table_id}") + print(f"Check if BQ table {full_table_id} exists") try: bq.get_table(full_table_id) - print(f"table {full_table_id} already exists") + print(f"table {full_table_id} exists and will be deleted") + delete_bq_table(dataset, table_name) except NotFound: - # Construct a Table object to send to the API. - with open(schema_file_path, "rb") as schema: - schema_dict = json.load(schema) - table = bigquery.Table(full_table_id, schema=schema_dict) - bq.create_table(table) - print("table is created") + print(f"table {full_table_id} does not exist") + # Construct a Table object to send to the API. + with open(schema_file_path, "rb") as schema: + schema_dict = json.load(schema) + table = bigquery.Table(full_table_id, schema=schema_dict) + bq.create_table(table) + print(f"table {full_table_id} is created") def delete_bq_table(dataset, table_name): diff --git a/generated_samples/interactive-tutorials/product/update_product.py b/generated_samples/interactive-tutorials/product/update_product.py index 9a10153afc21..e3abef981423 100644 --- a/generated_samples/interactive-tutorials/product/update_product.py +++ b/generated_samples/interactive-tutorials/product/update_product.py @@ -30,10 +30,6 @@ from setup_product.setup_cleanup import create_product, delete_product -# from google.protobuf.field_mask_pb2 import FieldMask -# from google.protobuf.field_mask_pb2 import FieldMask - - project_id = google.auth.default()[1] default_branch_name = ( "projects/"