Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

docs(samples): add resources for interactive tutorials #145

Merged
merged 13 commits into from
Feb 8, 2022
Prev Previous commit
Next Next commit
adjust filepaths samples testing
parthea authored and tkarasyova committed Feb 2, 2022
commit b1b4fbba981b0a76d44fc7adedf55b2291ec6615
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
def test_import_products_bq():
output = str(
subprocess.check_output(
"python product/import_products_big_query_table.py", shell=True
"python import_products_big_query_table.py", shell=True
)
)

4 changes: 2 additions & 2 deletions samples/interactive-tutorials/product/import_products_gcs.py
Original file line number Diff line number Diff line change
@@ -34,14 +34,14 @@
# Read the project number from the environment variable
project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
bucket_name = os.environ["BUCKET_NAME"]

# You can change the branch here. The "default_branch" is set to point to the branch "0"
default_catalog = "projects/{0}/locations/global/catalogs/default_catalog/branches/default_branch".format(
project_number
)

# Read bucket name from the environment variable
gcs_bucket = "gs://{}".format(os.getenv("BUCKET_NAME"))
gcs_bucket = "gs://{}".format(bucket_name)
gcs_errors_bucket = "{}/error".format(gcs_bucket)
gcs_products_object = "products.json"

Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

def test_import_products_gcs():
output = str(
subprocess.check_output("python product/import_products_gcs.py", shell=True)
subprocess.check_output("python import_products_gcs.py", shell=True)
)

assert re.match(".*import products from google cloud source request.*", output)
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
def test_import_products_gcs():
output = str(
subprocess.check_output(
"python product/import_products_inline_source.py", shell=True
"python import_products_inline_source.py", shell=True
)
)

4 changes: 3 additions & 1 deletion samples/interactive-tutorials/product/noxfile_config.py
Original file line number Diff line number Diff line change
@@ -28,5 +28,7 @@
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
# A dictionary you want to inject into your test. Don't put any
# secrets here. These values will override predefined values.
"envs": {"BUCKET_NAME": "retail-interactive-tutorials",},
"envs": {
"BUCKET_NAME": "retail-interactive-tutorials",
},
}
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
def test_create_bigquery_table():
output = str(
subprocess.check_output(
'python product/setup/products_create_bigquery_table.py',
'python setup/products_create_bigquery_table.py',
shell=True))
assert re.match(
'.*Creating dataset products.*', output)
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
def test_create_gcs_bucket():
output = str(
subprocess.check_output(
'python product/setup/products_create_gcs_bucket.py',
'python setup/products_create_gcs_bucket.py',
shell=True))

bucket_name = re.search('The gcs bucket (.+?) was created', output).group(1)
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@

def delete_bucket_by_name(name: str):
if name is None:
bucket_name = os.getenv("BUCKET_NAME")
bucket_name = os.environ["BUCKET_NAME"]
delete_bucket(bucket_name)
else:
delete_bucket(name)
2 changes: 1 addition & 1 deletion samples/snippets/create_test_resources.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
from google.cloud.retail_v2 import ProductServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
bucket_name = os.getenv('BUCKET_NAME')
bucket_name = os.environ['BUCKET_NAME']
storage_client = storage.Client()
resource_file = "resources/products.json"
object_name = re.search('resources/(.*?)$', resource_file).group(1)
2 changes: 1 addition & 1 deletion samples/snippets/remove_test_resources.py
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
ProductServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
bucket_name = os.getenv('BUCKET_NAME')
bucket_name = os.environ['BUCKET_NAME']

default_catalog = "projects/{0}/locations/global/catalogs/default_catalog/branches/default_branch".format(
project_number)