From c72ec2fd770714f194102951c71d9c90a7b66eae Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 5 Aug 2025 12:57:29 +0000 Subject: [PATCH 1/2] feat: add products API client libraries for v1 PiperOrigin-RevId: 791134255 Source-Link: https://github.com/googleapis/googleapis/commit/e14e0bf384fdb087cf38d60252fb5c87b949ffaf Source-Link: https://github.com/googleapis/googleapis-gen/commit/458b657623643c2aaf93ddd9a95ac6d7b8a17db4 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLW1lcmNoYW50LXByb2R1Y3RzLy5Pd2xCb3QueWFtbCIsImgiOiI0NThiNjU3NjIzNjQzYzJhYWY5M2RkZDlhOTVhYzZkN2I4YTE3ZGI0In0= --- .../v1/.coveragerc | 13 + .../v1/.flake8 | 34 + .../v1/LICENSE | 202 + .../v1/MANIFEST.in | 20 + .../v1/README.rst | 143 + .../v1/docs/_static/custom.css | 20 + .../v1/docs/_templates/layout.html | 50 + .../v1/docs/conf.py | 385 ++ .../v1/docs/index.rst | 10 + .../product_inputs_service.rst | 6 + .../merchant_products_v1/products_service.rst | 10 + .../docs/merchant_products_v1/services_.rst | 7 + .../v1/docs/merchant_products_v1/types_.rst | 6 + .../v1/docs/multiprocessing.rst | 7 + .../shopping/merchant_products/__init__.py | 119 + .../merchant_products/gapic_version.py | 16 + .../shopping/merchant_products/py.typed | 2 + .../shopping/merchant_products_v1/__init__.py | 120 + .../merchant_products_v1/gapic_metadata.json | 122 + .../merchant_products_v1/gapic_version.py | 16 + .../shopping/merchant_products_v1/py.typed | 2 + .../merchant_products_v1/services/__init__.py | 15 + .../product_inputs_service/__init__.py | 22 + .../product_inputs_service/async_client.py | 689 ++++ .../services/product_inputs_service/client.py | 1057 +++++ .../transports/README.rst | 9 + .../transports/__init__.py | 38 + .../product_inputs_service/transports/base.py | 188 + .../product_inputs_service/transports/grpc.py | 420 ++ .../transports/grpc_asyncio.py | 451 +++ .../product_inputs_service/transports/rest.py | 710 ++++ .../transports/rest_base.py | 223 + .../services/products_service/__init__.py | 22 + .../services/products_service/async_client.py | 527 +++ .../services/products_service/client.py | 886 ++++ .../services/products_service/pagers.py | 166 + .../products_service/transports/README.rst | 9 + .../products_service/transports/__init__.py | 38 + .../products_service/transports/base.py | 173 + .../products_service/transports/grpc.py | 383 ++ .../transports/grpc_asyncio.py | 409 ++ .../products_service/transports/rest.py | 542 +++ .../products_service/transports/rest_base.py | 165 + .../merchant_products_v1/types/__init__.py | 112 + .../types/productinputs.py | 313 ++ .../merchant_products_v1/types/products.py | 272 ++ .../types/products_common.py | 2449 +++++++++++ .../v1/mypy.ini | 3 + .../v1/noxfile.py | 591 +++ ...puts_service_delete_product_input_async.py | 51 + ...nputs_service_delete_product_input_sync.py | 51 + ...puts_service_insert_product_input_async.py | 59 + ...nputs_service_insert_product_input_sync.py | 59 + ...puts_service_update_product_input_async.py | 58 + ...nputs_service_update_product_input_sync.py | 58 + ...ated_products_service_get_product_async.py | 52 + ...rated_products_service_get_product_sync.py | 52 + ...ed_products_service_list_products_async.py | 53 + ...ted_products_service_list_products_sync.py | 53 + ..._google.shopping.merchant.products.v1.json | 814 ++++ .../fixup_merchant_products_v1_keywords.py | 180 + .../v1/setup.py | 99 + .../v1/testing/constraints-3.10.txt | 7 + .../v1/testing/constraints-3.11.txt | 7 + .../v1/testing/constraints-3.12.txt | 7 + .../v1/testing/constraints-3.13.txt | 12 + .../v1/testing/constraints-3.7.txt | 11 + .../v1/testing/constraints-3.8.txt | 7 + .../v1/testing/constraints-3.9.txt | 7 + .../v1/tests/__init__.py | 16 + .../v1/tests/unit/__init__.py | 16 + .../v1/tests/unit/gapic/__init__.py | 16 + .../gapic/merchant_products_v1/__init__.py | 16 + .../test_product_inputs_service.py | 3573 +++++++++++++++++ .../test_products_service.py | 3099 ++++++++++++++ .../v1beta/.coveragerc | 13 + .../v1beta/.flake8 | 34 + .../v1beta/LICENSE | 202 + .../v1beta/MANIFEST.in | 20 + .../v1beta/README.rst | 143 + .../v1beta/docs/_static/custom.css | 20 + .../v1beta/docs/_templates/layout.html | 50 + .../v1beta/docs/conf.py | 385 ++ .../v1beta/docs/index.rst | 10 + .../product_inputs_service.rst | 6 + .../products_service.rst | 10 + .../merchant_products_v1beta/services_.rst | 7 + .../docs/merchant_products_v1beta/types_.rst | 6 + .../v1beta/docs/multiprocessing.rst | 7 + .../shopping/merchant_products/__init__.py | 93 + .../merchant_products/gapic_version.py | 16 + .../shopping/merchant_products/py.typed | 2 + .../merchant_products_v1beta/__init__.py | 94 + .../gapic_metadata.json | 122 + .../merchant_products_v1beta/gapic_version.py | 16 + .../merchant_products_v1beta/py.typed | 2 + .../services/__init__.py | 15 + .../product_inputs_service/__init__.py | 22 + .../product_inputs_service/async_client.py | 689 ++++ .../services/product_inputs_service/client.py | 1057 +++++ .../transports/README.rst | 9 + .../transports/__init__.py | 38 + .../product_inputs_service/transports/base.py | 188 + .../product_inputs_service/transports/grpc.py | 419 ++ .../transports/grpc_asyncio.py | 450 +++ .../product_inputs_service/transports/rest.py | 711 ++++ .../transports/rest_base.py | 223 + .../services/products_service/__init__.py | 22 + .../services/products_service/async_client.py | 522 +++ .../services/products_service/client.py | 881 ++++ .../services/products_service/pagers.py | 166 + .../products_service/transports/README.rst | 9 + .../products_service/transports/__init__.py | 38 + .../products_service/transports/base.py | 173 + .../products_service/transports/grpc.py | 383 ++ .../transports/grpc_asyncio.py | 409 ++ .../products_service/transports/rest.py | 542 +++ .../products_service/transports/rest_base.py | 165 + .../types/__init__.py | 86 + .../types/productinputs.py | 305 ++ .../types/products.py | 260 ++ .../types/products_common.py | 2109 ++++++++++ .../v1beta/mypy.ini | 3 + .../v1beta/noxfile.py | 591 +++ ...puts_service_delete_product_input_async.py | 51 + ...nputs_service_delete_product_input_sync.py | 51 + ...puts_service_insert_product_input_async.py | 59 + ...nputs_service_insert_product_input_sync.py | 59 + ...puts_service_update_product_input_async.py | 58 + ...nputs_service_update_product_input_sync.py | 58 + ...ated_products_service_get_product_async.py | 52 + ...rated_products_service_get_product_sync.py | 52 + ...ed_products_service_list_products_async.py | 53 + ...ted_products_service_list_products_sync.py | 53 + ...gle.shopping.merchant.products.v1beta.json | 814 ++++ ...fixup_merchant_products_v1beta_keywords.py | 180 + .../v1beta/setup.py | 99 + .../v1beta/testing/constraints-3.10.txt | 7 + .../v1beta/testing/constraints-3.11.txt | 7 + .../v1beta/testing/constraints-3.12.txt | 7 + .../v1beta/testing/constraints-3.13.txt | 12 + .../v1beta/testing/constraints-3.7.txt | 11 + .../v1beta/testing/constraints-3.8.txt | 7 + .../v1beta/testing/constraints-3.9.txt | 7 + .../v1beta/tests/__init__.py | 16 + .../v1beta/tests/unit/__init__.py | 16 + .../v1beta/tests/unit/gapic/__init__.py | 16 + .../merchant_products_v1beta/__init__.py | 16 + .../test_product_inputs_service.py | 3573 +++++++++++++++++ .../test_products_service.py | 3099 ++++++++++++++ 150 files changed, 40801 insertions(+) create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/.flake8 create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/LICENSE create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/README.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/product_inputs_service.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/products_service.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/services_.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/types_.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/gapic_version.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/py.typed create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_metadata.json create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/README.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/scripts/fixup_merchant_products_v1_keywords.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/setup.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py create mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc b/owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc new file mode 100644 index 000000000000..0d94c2da5109 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc @@ -0,0 +1,13 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/shopping/merchant_products/__init__.py + google/shopping/merchant_products/gapic_version.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/.flake8 b/owl-bot-staging/google-shopping-merchant-products/v1/.flake8 new file mode 100644 index 000000000000..90316de21489 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/.flake8 @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +[flake8] +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): +# Resolve flake8 lint issues +ignore = E203, E231, E266, E501, W503 +exclude = + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): + # Ensure that generated code passes flake8 lint + **/gapic/** + **/services/** + **/types/** + # Exclude Protobuf gencode + *_pb2.py + + # Standard linting exemptions. + **/.nox/** + __pycache__, + .git, + *.pyc, + conf.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/LICENSE b/owl-bot-staging/google-shopping-merchant-products/v1/LICENSE new file mode 100644 index 000000000000..d64569567334 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in b/owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in new file mode 100644 index 000000000000..dae249ec8976 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +include README.rst LICENSE +recursive-include google *.py *.pyi *.json *.proto py.typed +recursive-include tests * +global-exclude *.py[co] +global-exclude __pycache__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1/README.rst new file mode 100644 index 000000000000..f80c16dfa082 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/README.rst @@ -0,0 +1,143 @@ +Python Client for Google Shopping Merchant Products API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Shopping Merchant Products API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library + + +Logging +------- + +This library uses the standard Python :code:`logging` functionality to log some RPC events that could be of interest for debugging and monitoring purposes. +Note the following: + +#. Logs may contain sensitive information. Take care to **restrict access to the logs** if they are saved, whether it be on local storage or on Google Cloud Logging. +#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**. +#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below. + + +Simple, environment-based configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To enable logging for this library without any changes in your code, set the :code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to a valid Google +logging scope. This configures handling of logging events (at level :code:`logging.DEBUG` or higher) from this library in a default manner, emitting the logged +messages in a structured format. It does not currently allow customizing the logging levels captured nor the handlers, formatters, etc. used for any logging +event. + +A logging scope is a period-separated namespace that begins with :code:`google`, identifying the Python module or package to log. + +- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc. +- Invalid logging scopes: :code:`foo`, :code:`123`, etc. + +**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers. + + +Examples +^^^^^^^^ + +- Enabling the default handler for all Google-based loggers + +.. code-block:: console + + export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google + +- Enabling the default handler for a specific Google module (for a client library called :code:`library_v1`): + +.. code-block:: console + + export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1 + + +Advanced, code-based configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also configure a valid logging scope using Python's standard `logging` mechanism. + + +Examples +^^^^^^^^ + +- Configuring a handler for all Google-based loggers + +.. code-block:: python + + import logging + + from google.cloud.translate_v3 import translate + + base_logger = logging.getLogger("google") + base_logger.addHandler(logging.StreamHandler()) + base_logger.setLevel(logging.DEBUG) + +- Configuring a handler for a specific Google module (for a client library called :code:`library_v1`): + +.. code-block:: python + + import logging + + from google.cloud.translate_v3 import translate + + base_logger = logging.getLogger("google.cloud.library_v1") + base_logger.addHandler(logging.StreamHandler()) + base_logger.setLevel(logging.DEBUG) + + +Logging details +~~~~~~~~~~~~~~~ + +#. Regardless of which of the mechanisms above you use to configure logging for this library, by default logging events are not propagated up to the root + logger from the `google`-level logger. If you need the events to be propagated to the root logger, you must explicitly set + :code:`logging.getLogger("google").propagate = True` in your code. +#. You can mix the different logging configurations above for different Google modules. For example, you may want use a code-based logging configuration for + one library, but decide you need to also set up environment-based logging configuration for another library. + + #. If you attempt to use both code-based and environment-based configuration for the same module, the environment-based configuration will be ineffectual + if the code -based configuration gets applied first. + +#. The Google-specific logging configurations (default handlers for environment-based configuration; not propagating logging events to the root logger) get + executed the first time *any* client library is instantiated in your application, and only if the affected loggers have not been previously configured. + (This is the reason for 2.i. above.) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css b/owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css new file mode 100644 index 000000000000..b0a295464b23 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css @@ -0,0 +1,20 @@ +div#python2-eol { + border-color: red; + border-width: medium; +} + +/* Ensure minimum width for 'Parameters' / 'Returns' column */ +dl.field-list > dt { + min-width: 100px +} + +/* Insert space between methods for readability */ +dl.method { + padding-top: 10px; + padding-bottom: 10px +} + +/* Insert empty space between classes */ +dl.class { + padding-bottom: 50px +} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html b/owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html new file mode 100644 index 000000000000..95e9c77fcfe1 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html @@ -0,0 +1,50 @@ + +{% extends "!layout.html" %} +{%- block content %} +{%- if theme_fixed_sidebar|lower == 'true' %} +
+ {{ sidebar() }} + {%- block document %} +
+ {%- if render_sidebar %} +
+ {%- endif %} + + {%- block relbar_top %} + {%- if theme_show_relbar_top|tobool %} + + {%- endif %} + {% endblock %} + +
+
+ As of January 1, 2020 this library no longer supports Python 2 on the latest released version. + Library versions released prior to that date will continue to be available. For more information please + visit Python 2 support on Google Cloud. +
+ {% block body %} {% endblock %} +
+ + {%- block relbar_bottom %} + {%- if theme_show_relbar_bottom|tobool %} + + {%- endif %} + {% endblock %} + + {%- if render_sidebar %} +
+ {%- endif %} +
+ {%- endblock %} +
+
+{%- else %} +{{ super() }} +{%- endif %} +{%- endblock %} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py b/owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py new file mode 100644 index 000000000000..302daf996542 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py @@ -0,0 +1,385 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-shopping-merchant-products documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +# For plugins that can not read conf.py. +# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 +sys.path.insert(0, os.path.abspath(".")) + +__version__ = "" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "4.5.0" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", + "recommonmark", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_options = {"members": True} +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The root toctree document. +root_doc = "index" + +# General information about the project. +project = u"google-shopping-merchant-products" +copyright = u"2025, Google, LLC" +author = u"Google APIs" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [ + "_build", + "**/.nox/**/*", + "samples/AUTHORING_GUIDE.md", + "samples/CONTRIBUTING.md", + "samples/snippets/README.rst", +] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Shopping Client Libraries for google-shopping-merchant-products", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-shopping-merchant-products-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + root_doc, + "google-shopping-merchant-products.tex", + u"google-shopping-merchant-products Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + root_doc, + "google-shopping-merchant-products", + "google-shopping-merchant-products Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + root_doc, + "google-shopping-merchant-products", + "google-shopping-merchant-products Documentation", + author, + "google-shopping-merchant-products", + "google-shopping-merchant-products Library", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("https://python.readthedocs.org/en/latest/", None), + "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), + "grpc": ("https://grpc.github.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst new file mode 100644 index 000000000000..a535ebfcdc18 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst @@ -0,0 +1,10 @@ +.. include:: multiprocessing.rst + + +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + merchant_products_v1/services_ + merchant_products_v1/types_ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/product_inputs_service.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/product_inputs_service.rst new file mode 100644 index 000000000000..fd65104ee107 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/product_inputs_service.rst @@ -0,0 +1,6 @@ +ProductInputsService +-------------------------------------- + +.. automodule:: google.shopping.merchant_products_v1.services.product_inputs_service + :members: + :inherited-members: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/products_service.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/products_service.rst new file mode 100644 index 000000000000..56dfa39c9d6b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/products_service.rst @@ -0,0 +1,10 @@ +ProductsService +--------------------------------- + +.. automodule:: google.shopping.merchant_products_v1.services.products_service + :members: + :inherited-members: + +.. automodule:: google.shopping.merchant_products_v1.services.products_service.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/services_.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/services_.rst new file mode 100644 index 000000000000..0085214f3225 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/services_.rst @@ -0,0 +1,7 @@ +Services for Google Shopping Merchant Products v1 API +===================================================== +.. toctree:: + :maxdepth: 2 + + product_inputs_service + products_service diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/types_.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/types_.rst new file mode 100644 index 000000000000..d1d1b9fe8876 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/types_.rst @@ -0,0 +1,6 @@ +Types for Google Shopping Merchant Products v1 API +================================================== + +.. automodule:: google.shopping.merchant_products_v1.types + :members: + :show-inheritance: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst new file mode 100644 index 000000000000..536d17b2ea65 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst @@ -0,0 +1,7 @@ +.. note:: + + Because this client uses :mod:`grpc` library, it is safe to + share instances across threads. In multiprocessing scenarios, the best + practice is to create client instances *after* the invocation of + :func:`os.fork` by :class:`multiprocessing.pool.Pool` or + :class:`multiprocessing.Process`. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py new file mode 100644 index 000000000000..03a5b1c85c91 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py @@ -0,0 +1,119 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.shopping.merchant_products import gapic_version as package_version + +__version__ = package_version.__version__ + + +from google.shopping.merchant_products_v1.services.product_inputs_service.client import ProductInputsServiceClient +from google.shopping.merchant_products_v1.services.product_inputs_service.async_client import ProductInputsServiceAsyncClient +from google.shopping.merchant_products_v1.services.products_service.client import ProductsServiceClient +from google.shopping.merchant_products_v1.services.products_service.async_client import ProductsServiceAsyncClient + +from google.shopping.merchant_products_v1.types.productinputs import DeleteProductInputRequest +from google.shopping.merchant_products_v1.types.productinputs import InsertProductInputRequest +from google.shopping.merchant_products_v1.types.productinputs import ProductInput +from google.shopping.merchant_products_v1.types.productinputs import UpdateProductInputRequest +from google.shopping.merchant_products_v1.types.products import GetProductRequest +from google.shopping.merchant_products_v1.types.products import ListProductsRequest +from google.shopping.merchant_products_v1.types.products import ListProductsResponse +from google.shopping.merchant_products_v1.types.products import Product +from google.shopping.merchant_products_v1.types.products_common import AutomatedDiscounts +from google.shopping.merchant_products_v1.types.products_common import CloudExportAdditionalProperties +from google.shopping.merchant_products_v1.types.products_common import FreeShippingThreshold +from google.shopping.merchant_products_v1.types.products_common import LoyaltyPoints +from google.shopping.merchant_products_v1.types.products_common import LoyaltyProgram +from google.shopping.merchant_products_v1.types.products_common import ProductAttributes +from google.shopping.merchant_products_v1.types.products_common import ProductCertification +from google.shopping.merchant_products_v1.types.products_common import ProductDetail +from google.shopping.merchant_products_v1.types.products_common import ProductDimension +from google.shopping.merchant_products_v1.types.products_common import ProductInstallment +from google.shopping.merchant_products_v1.types.products_common import ProductStatus +from google.shopping.merchant_products_v1.types.products_common import ProductSustainabilityIncentive +from google.shopping.merchant_products_v1.types.products_common import ProductWeight +from google.shopping.merchant_products_v1.types.products_common import Shipping +from google.shopping.merchant_products_v1.types.products_common import ShippingDimension +from google.shopping.merchant_products_v1.types.products_common import ShippingWeight +from google.shopping.merchant_products_v1.types.products_common import StructuredDescription +from google.shopping.merchant_products_v1.types.products_common import StructuredTitle +from google.shopping.merchant_products_v1.types.products_common import SubscriptionCost +from google.shopping.merchant_products_v1.types.products_common import UnitPricingBaseMeasure +from google.shopping.merchant_products_v1.types.products_common import UnitPricingMeasure +from google.shopping.merchant_products_v1.types.products_common import AgeGroup +from google.shopping.merchant_products_v1.types.products_common import Availability +from google.shopping.merchant_products_v1.types.products_common import CertificationAuthority +from google.shopping.merchant_products_v1.types.products_common import CertificationName +from google.shopping.merchant_products_v1.types.products_common import Condition +from google.shopping.merchant_products_v1.types.products_common import CreditType +from google.shopping.merchant_products_v1.types.products_common import DigitalSourceType +from google.shopping.merchant_products_v1.types.products_common import EnergyEfficiencyClass +from google.shopping.merchant_products_v1.types.products_common import Gender +from google.shopping.merchant_products_v1.types.products_common import Pause +from google.shopping.merchant_products_v1.types.products_common import PickupMethod +from google.shopping.merchant_products_v1.types.products_common import PickupSla +from google.shopping.merchant_products_v1.types.products_common import SizeSystem +from google.shopping.merchant_products_v1.types.products_common import SizeType +from google.shopping.merchant_products_v1.types.products_common import SubscriptionPeriod + +__all__ = ('ProductInputsServiceClient', + 'ProductInputsServiceAsyncClient', + 'ProductsServiceClient', + 'ProductsServiceAsyncClient', + 'DeleteProductInputRequest', + 'InsertProductInputRequest', + 'ProductInput', + 'UpdateProductInputRequest', + 'GetProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'Product', + 'AutomatedDiscounts', + 'CloudExportAdditionalProperties', + 'FreeShippingThreshold', + 'LoyaltyPoints', + 'LoyaltyProgram', + 'ProductAttributes', + 'ProductCertification', + 'ProductDetail', + 'ProductDimension', + 'ProductInstallment', + 'ProductStatus', + 'ProductSustainabilityIncentive', + 'ProductWeight', + 'Shipping', + 'ShippingDimension', + 'ShippingWeight', + 'StructuredDescription', + 'StructuredTitle', + 'SubscriptionCost', + 'UnitPricingBaseMeasure', + 'UnitPricingMeasure', + 'AgeGroup', + 'Availability', + 'CertificationAuthority', + 'CertificationName', + 'Condition', + 'CreditType', + 'DigitalSourceType', + 'EnergyEfficiencyClass', + 'Gender', + 'Pause', + 'PickupMethod', + 'PickupSla', + 'SizeSystem', + 'SizeType', + 'SubscriptionPeriod', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/gapic_version.py new file mode 100644 index 000000000000..20a9cd975b02 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/py.typed new file mode 100644 index 000000000000..962817aecdcd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py new file mode 100644 index 000000000000..9731eedadada --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.shopping.merchant_products_v1 import gapic_version as package_version + +__version__ = package_version.__version__ + + +from .services.product_inputs_service import ProductInputsServiceClient +from .services.product_inputs_service import ProductInputsServiceAsyncClient +from .services.products_service import ProductsServiceClient +from .services.products_service import ProductsServiceAsyncClient + +from .types.productinputs import DeleteProductInputRequest +from .types.productinputs import InsertProductInputRequest +from .types.productinputs import ProductInput +from .types.productinputs import UpdateProductInputRequest +from .types.products import GetProductRequest +from .types.products import ListProductsRequest +from .types.products import ListProductsResponse +from .types.products import Product +from .types.products_common import AutomatedDiscounts +from .types.products_common import CloudExportAdditionalProperties +from .types.products_common import FreeShippingThreshold +from .types.products_common import LoyaltyPoints +from .types.products_common import LoyaltyProgram +from .types.products_common import ProductAttributes +from .types.products_common import ProductCertification +from .types.products_common import ProductDetail +from .types.products_common import ProductDimension +from .types.products_common import ProductInstallment +from .types.products_common import ProductStatus +from .types.products_common import ProductSustainabilityIncentive +from .types.products_common import ProductWeight +from .types.products_common import Shipping +from .types.products_common import ShippingDimension +from .types.products_common import ShippingWeight +from .types.products_common import StructuredDescription +from .types.products_common import StructuredTitle +from .types.products_common import SubscriptionCost +from .types.products_common import UnitPricingBaseMeasure +from .types.products_common import UnitPricingMeasure +from .types.products_common import AgeGroup +from .types.products_common import Availability +from .types.products_common import CertificationAuthority +from .types.products_common import CertificationName +from .types.products_common import Condition +from .types.products_common import CreditType +from .types.products_common import DigitalSourceType +from .types.products_common import EnergyEfficiencyClass +from .types.products_common import Gender +from .types.products_common import Pause +from .types.products_common import PickupMethod +from .types.products_common import PickupSla +from .types.products_common import SizeSystem +from .types.products_common import SizeType +from .types.products_common import SubscriptionPeriod + +__all__ = ( + 'ProductInputsServiceAsyncClient', + 'ProductsServiceAsyncClient', +'AgeGroup', +'AutomatedDiscounts', +'Availability', +'CertificationAuthority', +'CertificationName', +'CloudExportAdditionalProperties', +'Condition', +'CreditType', +'DeleteProductInputRequest', +'DigitalSourceType', +'EnergyEfficiencyClass', +'FreeShippingThreshold', +'Gender', +'GetProductRequest', +'InsertProductInputRequest', +'ListProductsRequest', +'ListProductsResponse', +'LoyaltyPoints', +'LoyaltyProgram', +'Pause', +'PickupMethod', +'PickupSla', +'Product', +'ProductAttributes', +'ProductCertification', +'ProductDetail', +'ProductDimension', +'ProductInput', +'ProductInputsServiceClient', +'ProductInstallment', +'ProductStatus', +'ProductSustainabilityIncentive', +'ProductWeight', +'ProductsServiceClient', +'Shipping', +'ShippingDimension', +'ShippingWeight', +'SizeSystem', +'SizeType', +'StructuredDescription', +'StructuredTitle', +'SubscriptionCost', +'SubscriptionPeriod', +'UnitPricingBaseMeasure', +'UnitPricingMeasure', +'UpdateProductInputRequest', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_metadata.json b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_metadata.json new file mode 100644 index 000000000000..7df4ba981da9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_metadata.json @@ -0,0 +1,122 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.shopping.merchant_products_v1", + "protoPackage": "google.shopping.merchant.products.v1", + "schema": "1.0", + "services": { + "ProductInputsService": { + "clients": { + "grpc": { + "libraryClient": "ProductInputsServiceClient", + "rpcs": { + "DeleteProductInput": { + "methods": [ + "delete_product_input" + ] + }, + "InsertProductInput": { + "methods": [ + "insert_product_input" + ] + }, + "UpdateProductInput": { + "methods": [ + "update_product_input" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductInputsServiceAsyncClient", + "rpcs": { + "DeleteProductInput": { + "methods": [ + "delete_product_input" + ] + }, + "InsertProductInput": { + "methods": [ + "insert_product_input" + ] + }, + "UpdateProductInput": { + "methods": [ + "update_product_input" + ] + } + } + }, + "rest": { + "libraryClient": "ProductInputsServiceClient", + "rpcs": { + "DeleteProductInput": { + "methods": [ + "delete_product_input" + ] + }, + "InsertProductInput": { + "methods": [ + "insert_product_input" + ] + }, + "UpdateProductInput": { + "methods": [ + "update_product_input" + ] + } + } + } + } + }, + "ProductsService": { + "clients": { + "grpc": { + "libraryClient": "ProductsServiceClient", + "rpcs": { + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductsServiceAsyncClient", + "rpcs": { + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + } + } + }, + "rest": { + "libraryClient": "ProductsServiceClient", + "rpcs": { + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py new file mode 100644 index 000000000000..20a9cd975b02 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed new file mode 100644 index 000000000000..962817aecdcd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/__init__.py new file mode 100644 index 000000000000..cbf94b283c70 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py new file mode 100644 index 000000000000..570e3b7a9ffd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import ProductInputsServiceClient +from .async_client import ProductInputsServiceAsyncClient + +__all__ = ( + 'ProductInputsServiceClient', + 'ProductInputsServiceAsyncClient', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py new file mode 100644 index 000000000000..71715a222193 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py @@ -0,0 +1,689 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging as std_logging +from collections import OrderedDict +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union + +from google.shopping.merchant_products_v1 import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + + +try: + OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore + +from google.protobuf import field_mask_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport +from .client import ProductInputsServiceClient + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +class ProductInputsServiceAsyncClient: + """Service to use ProductInput resource.""" + + _client: ProductInputsServiceClient + + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = ProductInputsServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ProductInputsServiceClient._DEFAULT_UNIVERSE + + product_path = staticmethod(ProductInputsServiceClient.product_path) + parse_product_path = staticmethod(ProductInputsServiceClient.parse_product_path) + product_input_path = staticmethod(ProductInputsServiceClient.product_input_path) + parse_product_input_path = staticmethod(ProductInputsServiceClient.parse_product_input_path) + common_billing_account_path = staticmethod(ProductInputsServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductInputsServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductInputsServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductInputsServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductInputsServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductInputsServiceClient.parse_common_organization_path) + common_project_path = staticmethod(ProductInputsServiceClient.common_project_path) + parse_common_project_path = staticmethod(ProductInputsServiceClient.parse_common_project_path) + common_location_path = staticmethod(ProductInputsServiceClient.common_location_path) + parse_common_location_path = staticmethod(ProductInputsServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceAsyncClient: The constructed client. + """ + return ProductInputsServiceClient.from_service_account_info.__func__(ProductInputsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceAsyncClient: The constructed client. + """ + return ProductInputsServiceClient.from_service_account_file.__func__(ProductInputsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ProductInputsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> ProductInputsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductInputsServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._client._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used + by the client instance. + """ + return self._client._universe_domain + + get_transport_class = ProductInputsServiceClient.get_transport_class + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product inputs service async client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductInputsServiceTransport,Callable[..., ProductInputsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductInputsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = ProductInputsServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1.ProductInputsServiceAsyncClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._client._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "credentialsType": None, + } + ) + + async def insert_product_input(self, + request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""`Uploads a product input to your Merchant Center + account `__. + You must have a products `data + source `__ to be + able to insert a product. The unique identifier of the data + source is passed as a query parameter in the request URL. + + If a product input with the same contentLanguage, offerId, and + dataSource already exists, then the product input inserted by + this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + async def sample_insert_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.insert_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1.types.InsertProductInputRequest, dict]]): + The request object. Request message for the + InsertProductInput method. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.InsertProductInputRequest): + request = productinputs.InsertProductInputRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.insert_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_product_input(self, + request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, + *, + product_input: Optional[productinputs.ProductInput] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + async def sample_update_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.update_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1.types.UpdateProductInputRequest, dict]]): + The request object. Request message for the + UpdateProductInput method. The product + (primary input) must exist for the + update to succeed. If the update is for + a primary product input, the existing + primary product input must be from the + same data source. + product_input (:class:`google.shopping.merchant_products_v1.types.ProductInput`): + Required. The product input resource + to update. Information you submit will + be applied to the processed product as + well. + + This corresponds to the ``product_input`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. The list of product attributes to be updated. + + If the update mask is omitted, then it is treated as + implied field mask equivalent to all fields that are + populated (have a non-empty value). + + Attributes specified in the update mask without a value + specified in the body will be deleted from the product. + + Update mask can only be specified for top level fields + in attributes and custom attributes. + + To specify the update mask for custom attributes you + need to add the ``custom_attribute.`` prefix. + + Providing special "*" value for full product replacement + is not supported. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [product_input, update_mask] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.UpdateProductInputRequest): + request = productinputs.UpdateProductInputRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_input is not None: + request.product_input = product_input + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.update_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_input.name", request.product_input.name), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product_input(self, + request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: + r"""Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + async def sample_delete_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + await client.delete_product_input(request=request) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1.types.DeleteProductInputRequest, dict]]): + The request object. Request message for the + DeleteProductInput method. + name (:class:`str`): + Required. The name of the product input resource to + delete. Format: + ``accounts/{account}/productInputs/{product}`` where the + last section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for + product name is + ``accounts/123/productInputs/en~US~sku123``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.DeleteProductInputRequest): + request = productinputs.DeleteProductInputRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.delete_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def __aenter__(self) -> "ProductInputsServiceAsyncClient": + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +__all__ = ( + "ProductInputsServiceAsyncClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py new file mode 100644 index 000000000000..8d82ce3788da --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py @@ -0,0 +1,1057 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from http import HTTPStatus +import json +import logging as std_logging +import os +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast +import warnings + +from google.shopping.merchant_products_v1 import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +from google.protobuf import field_mask_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductInputsServiceGrpcTransport +from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport +from .transports.rest import ProductInputsServiceRestTransport + + +class ProductInputsServiceClientMeta(type): + """Metaclass for the ProductInputsService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] + _transport_registry["grpc"] = ProductInputsServiceGrpcTransport + _transport_registry["grpc_asyncio"] = ProductInputsServiceGrpcAsyncIOTransport + _transport_registry["rest"] = ProductInputsServiceRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[ProductInputsServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class ProductInputsServiceClient(metaclass=ProductInputsServiceClientMeta): + """Service to use ProductInput resource.""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "merchantapi.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductInputsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductInputsServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(account: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "accounts/{account}/products/{product}".format(account=account, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_input_path(account: str,productinput: str,) -> str: + """Returns a fully-qualified product_input string.""" + return "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) + + @staticmethod + def parse_product_input_path(path: str) -> Dict[str,str]: + """Parses a product_input path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/productInputs/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Deprecated. Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + + warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning) + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + """Return the API endpoint used by the client. + + Args: + api_override (str): The API endpoint override. If specified, this is always + the return value of this function and the other arguments are not used. + client_cert_source (bytes): The client certificate source used by the client. + universe_domain (str): The universe domain used by the client. + use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. + Possible values are "always", "auto", or "never". + + Returns: + str: The API endpoint to be used by the client. + """ + if api_override is not None: + api_endpoint = api_override + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + _default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") + api_endpoint = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) + return api_endpoint + + @staticmethod + def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ProductInputsServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain + + def _validate_universe_domain(self): + """Validates client's and credentials' universe domains are consistent. + + Returns: + bool: True iff the configured universe domain is valid. + + Raises: + ValueError: If the configured universe domain is not valid. + """ + + # NOTE (b/349488459): universe validation is disabled until further notice. + return True + + def _add_cred_info_for_auth_errors( + self, + error: core_exceptions.GoogleAPICallError + ) -> None: + """Adds credential info string to error details for 401/403/404 errors. + + Args: + error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. + """ + if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: + return + + cred = self._transport._credentials + + # get_cred_info is only available in google-auth>=2.35.0 + if not hasattr(cred, "get_cred_info"): + return + + # ignore the type check since pypy test fails when get_cred_info + # is not available + cred_info = cred.get_cred_info() # type: ignore + if cred_info and hasattr(error._details, "append"): + error._details.append(json.dumps(cred_info)) + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used by the client instance. + """ + return self._universe_domain + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product inputs service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductInputsServiceTransport,Callable[..., ProductInputsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductInputsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that the ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client_options = client_options + if isinstance(self._client_options, dict): + self._client_options = client_options_lib.from_dict(self._client_options) + if self._client_options is None: + self._client_options = client_options_lib.ClientOptions() + self._client_options = cast(client_options_lib.ClientOptions, self._client_options) + + universe_domain_opt = getattr(self._client_options, 'universe_domain', None) + + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductInputsServiceClient._read_environment_variables() + self._client_cert_source = ProductInputsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) + self._universe_domain = ProductInputsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False + + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + + api_key_value = getattr(self._client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + transport_provided = isinstance(transport, ProductInputsServiceTransport) + if transport_provided: + # transport is a ProductInputsServiceTransport instance. + if credentials or self._client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if self._client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = cast(ProductInputsServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = (self._api_endpoint or + ProductInputsServiceClient._get_api_endpoint( + self._client_options.api_endpoint, + self._client_cert_source, + self._universe_domain, + self._use_mtls_endpoint)) + + if not transport_provided: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + transport_init: Union[Type[ProductInputsServiceTransport], Callable[..., ProductInputsServiceTransport]] = ( + ProductInputsServiceClient.get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., ProductInputsServiceTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( + credentials=credentials, + credentials_file=self._client_options.credentials_file, + host=self._api_endpoint, + scopes=self._client_options.scopes, + client_cert_source_for_mtls=self._client_cert_source, + quota_project_id=self._client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=self._client_options.api_audience, + ) + + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1.ProductInputsServiceClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "credentialsType": None, + } + ) + + def insert_product_input(self, + request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""`Uploads a product input to your Merchant Center + account `__. + You must have a products `data + source `__ to be + able to insert a product. The unique identifier of the data + source is passed as a query parameter in the request URL. + + If a product input with the same contentLanguage, offerId, and + dataSource already exists, then the product input inserted by + this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + def sample_insert_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.insert_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1.types.InsertProductInputRequest, dict]): + The request object. Request message for the + InsertProductInput method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.InsertProductInputRequest): + request = productinputs.InsertProductInputRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.insert_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_product_input(self, + request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, + *, + product_input: Optional[productinputs.ProductInput] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + def sample_update_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.update_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1.types.UpdateProductInputRequest, dict]): + The request object. Request message for the + UpdateProductInput method. The product + (primary input) must exist for the + update to succeed. If the update is for + a primary product input, the existing + primary product input must be from the + same data source. + product_input (google.shopping.merchant_products_v1.types.ProductInput): + Required. The product input resource + to update. Information you submit will + be applied to the processed product as + well. + + This corresponds to the ``product_input`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. The list of product attributes to be updated. + + If the update mask is omitted, then it is treated as + implied field mask equivalent to all fields that are + populated (have a non-empty value). + + Attributes specified in the update mask without a value + specified in the body will be deleted from the product. + + Update mask can only be specified for top level fields + in attributes and custom attributes. + + To specify the update mask for custom attributes you + need to add the ``custom_attribute.`` prefix. + + Providing special "*" value for full product replacement + is not supported. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [product_input, update_mask] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.UpdateProductInputRequest): + request = productinputs.UpdateProductInputRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_input is not None: + request.product_input = product_input + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_input.name", request.product_input.name), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product_input(self, + request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: + r"""Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + def sample_delete_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + client.delete_product_input(request=request) + + Args: + request (Union[google.shopping.merchant_products_v1.types.DeleteProductInputRequest, dict]): + The request object. Request message for the + DeleteProductInput method. + name (str): + Required. The name of the product input resource to + delete. Format: + ``accounts/{account}/productInputs/{product}`` where the + last section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for + product name is + ``accounts/123/productInputs/en~US~sku123``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.DeleteProductInputRequest): + request = productinputs.DeleteProductInputRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def __enter__(self) -> "ProductInputsServiceClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + +__all__ = ( + "ProductInputsServiceClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst new file mode 100644 index 000000000000..fa031e4be3c9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst @@ -0,0 +1,9 @@ + +transport inheritance structure +_______________________________ + +`ProductInputsServiceTransport` is the ABC for all transports. +- public child `ProductInputsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). +- public child `ProductInputsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). +- private child `_BaseProductInputsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). +- public child `ProductInputsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py new file mode 100644 index 000000000000..e9792827a667 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import ProductInputsServiceTransport +from .grpc import ProductInputsServiceGrpcTransport +from .grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport +from .rest import ProductInputsServiceRestTransport +from .rest import ProductInputsServiceRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] +_transport_registry['grpc'] = ProductInputsServiceGrpcTransport +_transport_registry['grpc_asyncio'] = ProductInputsServiceGrpcAsyncIOTransport +_transport_registry['rest'] = ProductInputsServiceRestTransport + +__all__ = ( + 'ProductInputsServiceTransport', + 'ProductInputsServiceGrpcTransport', + 'ProductInputsServiceGrpcAsyncIOTransport', + 'ProductInputsServiceRestTransport', + 'ProductInputsServiceRestInterceptor', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py new file mode 100644 index 000000000000..ba6fa5973d53 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py @@ -0,0 +1,188 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.shopping.merchant_products_v1 import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductInputsServiceTransport(abc.ABC): + """Abstract transport class for ProductInputsService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/content', + ) + + DEFAULT_HOST: str = 'merchantapi.googleapis.com' + + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + if not hasattr(self, "_ignore_credentials"): + self._ignore_credentials: bool = False + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None and not self._ignore_credentials: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + @property + def host(self): + return self._host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.insert_product_input: gapic_v1.method.wrap_method( + self.insert_product_input, + default_timeout=None, + client_info=client_info, + ), + self.update_product_input: gapic_v1.method.wrap_method( + self.update_product_input, + default_timeout=None, + client_info=client_info, + ), + self.delete_product_input: gapic_v1.method.wrap_method( + self.delete_product_input, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + Union[ + productinputs.ProductInput, + Awaitable[productinputs.ProductInput] + ]]: + raise NotImplementedError() + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + Union[ + productinputs.ProductInput, + Awaitable[productinputs.ProductInput] + ]]: + raise NotImplementedError() + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'ProductInputsServiceTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py new file mode 100644 index 000000000000..778073cda6d8 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py @@ -0,0 +1,420 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging as std_logging +import pickle +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs +from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductInputsServiceGrpcTransport(ProductInputsServiceTransport): + """gRPC backend transport for ProductInputsService. + + Service to use ProductInput resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, grpc.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) + + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + productinputs.ProductInput]: + r"""Return a callable for the insert product input method over gRPC. + + `Uploads a product input to your Merchant Center + account `__. + You must have a products `data + source `__ to be + able to insert a product. The unique identifier of the data + source is passed as a query parameter in the request URL. + + If a product input with the same contentLanguage, offerId, and + dataSource already exists, then the product input inserted by + this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + Returns: + Callable[[~.InsertProductInputRequest], + ~.ProductInput]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'insert_product_input' not in self._stubs: + self._stubs['insert_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductInputsService/InsertProductInput', + request_serializer=productinputs.InsertProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['insert_product_input'] + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + productinputs.ProductInput]: + r"""Return a callable for the update product input method over gRPC. + + Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.UpdateProductInputRequest], + ~.ProductInput]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_product_input' not in self._stubs: + self._stubs['update_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductInputsService/UpdateProductInput', + request_serializer=productinputs.UpdateProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['update_product_input'] + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product input method over gRPC. + + Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.DeleteProductInputRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_product_input' not in self._stubs: + self._stubs['delete_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductInputsService/DeleteProductInput', + request_serializer=productinputs.DeleteProductInputRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_input'] + + def close(self): + self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'ProductInputsServiceGrpcTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py new file mode 100644 index 000000000000..99663b8f5b2a --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py @@ -0,0 +1,451 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import inspect +import json +import pickle +import logging as std_logging +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import exceptions as core_exceptions +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore +from grpc.experimental import aio # type: ignore + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs +from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductInputsServiceGrpcTransport + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductInputsServiceGrpcAsyncIOTransport(ProductInputsServiceTransport): + """gRPC AsyncIO backend transport for ProductInputsService. + + Service to use ProductInput resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, aio.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel + self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + Awaitable[productinputs.ProductInput]]: + r"""Return a callable for the insert product input method over gRPC. + + `Uploads a product input to your Merchant Center + account `__. + You must have a products `data + source `__ to be + able to insert a product. The unique identifier of the data + source is passed as a query parameter in the request URL. + + If a product input with the same contentLanguage, offerId, and + dataSource already exists, then the product input inserted by + this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + Returns: + Callable[[~.InsertProductInputRequest], + Awaitable[~.ProductInput]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'insert_product_input' not in self._stubs: + self._stubs['insert_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductInputsService/InsertProductInput', + request_serializer=productinputs.InsertProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['insert_product_input'] + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + Awaitable[productinputs.ProductInput]]: + r"""Return a callable for the update product input method over gRPC. + + Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.UpdateProductInputRequest], + Awaitable[~.ProductInput]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_product_input' not in self._stubs: + self._stubs['update_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductInputsService/UpdateProductInput', + request_serializer=productinputs.UpdateProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['update_product_input'] + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product input method over gRPC. + + Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.DeleteProductInputRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_product_input' not in self._stubs: + self._stubs['delete_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductInputsService/DeleteProductInput', + request_serializer=productinputs.DeleteProductInputRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_input'] + + def _prep_wrapped_messages(self, client_info): + """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.insert_product_input: self._wrap_method( + self.insert_product_input, + default_timeout=None, + client_info=client_info, + ), + self.update_product_input: self._wrap_method( + self.update_product_input, + default_timeout=None, + client_info=client_info, + ), + self.delete_product_input: self._wrap_method( + self.delete_product_input, + default_timeout=None, + client_info=client_info, + ), + } + + def _wrap_method(self, func, *args, **kwargs): + if self._wrap_with_kind: # pragma: NO COVER + kwargs["kind"] = self.kind + return gapic_v1.method_async.wrap_method(func, *args, **kwargs) + + def close(self): + return self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc_asyncio" + + +__all__ = ( + 'ProductInputsServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py new file mode 100644 index 000000000000..d9f0259e6b43 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py @@ -0,0 +1,710 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import json # type: ignore + +from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import gapic_v1 +import google.protobuf + +from google.protobuf import json_format + +from requests import __version__ as requests_version +import dataclasses +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs + + +from .rest_base import _BaseProductInputsServiceRestTransport +from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=f"requests@{requests_version}", +) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductInputsServiceRestInterceptor: + """Interceptor for ProductInputsService. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the ProductInputsServiceRestTransport. + + .. code-block:: python + class MyCustomProductInputsServiceInterceptor(ProductInputsServiceRestInterceptor): + def pre_delete_product_input(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_insert_product_input(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_insert_product_input(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_product_input(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_product_input(self, response): + logging.log(f"Received response: {response}") + return response + + transport = ProductInputsServiceRestTransport(interceptor=MyCustomProductInputsServiceInterceptor()) + client = ProductInputsServiceClient(transport=transport) + + + """ + def pre_delete_product_input(self, request: productinputs.DeleteProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.DeleteProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for delete_product_input + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductInputsService server. + """ + return request, metadata + + def pre_insert_product_input(self, request: productinputs.InsertProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.InsertProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for insert_product_input + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductInputsService server. + """ + return request, metadata + + def post_insert_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: + """Post-rpc interceptor for insert_product_input + + DEPRECATED. Please use the `post_insert_product_input_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductInputsService server but before + it is returned to user code. This `post_insert_product_input` interceptor runs + before the `post_insert_product_input_with_metadata` interceptor. + """ + return response + + def post_insert_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for insert_product_input + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductInputsService server but before it is returned to user code. + + We recommend only using this `post_insert_product_input_with_metadata` + interceptor in new development instead of the `post_insert_product_input` interceptor. + When both interceptors are used, this `post_insert_product_input_with_metadata` interceptor runs after the + `post_insert_product_input` interceptor. The (possibly modified) response returned by + `post_insert_product_input` will be passed to + `post_insert_product_input_with_metadata`. + """ + return response, metadata + + def pre_update_product_input(self, request: productinputs.UpdateProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.UpdateProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for update_product_input + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductInputsService server. + """ + return request, metadata + + def post_update_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: + """Post-rpc interceptor for update_product_input + + DEPRECATED. Please use the `post_update_product_input_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductInputsService server but before + it is returned to user code. This `post_update_product_input` interceptor runs + before the `post_update_product_input_with_metadata` interceptor. + """ + return response + + def post_update_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for update_product_input + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductInputsService server but before it is returned to user code. + + We recommend only using this `post_update_product_input_with_metadata` + interceptor in new development instead of the `post_update_product_input` interceptor. + When both interceptors are used, this `post_update_product_input_with_metadata` interceptor runs after the + `post_update_product_input` interceptor. The (possibly modified) response returned by + `post_update_product_input` will be passed to + `post_update_product_input_with_metadata`. + """ + return response, metadata + + +@dataclasses.dataclass +class ProductInputsServiceRestStub: + _session: AuthorizedSession + _host: str + _interceptor: ProductInputsServiceRestInterceptor + + +class ProductInputsServiceRestTransport(_BaseProductInputsServiceRestTransport): + """REST backend synchronous transport for ProductInputsService. + + Service to use ProductInput resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[ProductInputsServiceRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + url_scheme=url_scheme, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or ProductInputsServiceRestInterceptor() + self._prep_wrapped_messages(client_info) + + class _DeleteProductInput(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput, ProductInputsServiceRestStub): + def __hash__(self): + return hash("ProductInputsServiceRestTransport.DeleteProductInput") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__(self, + request: productinputs.DeleteProductInputRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ): + r"""Call the delete product input method over HTTP. + + Args: + request (~.productinputs.DeleteProductInputRequest): + The request object. Request message for the + DeleteProductInput method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + + http_options = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_http_options() + + request, metadata = self._interceptor.pre_delete_product_input(request, metadata) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_transcoded_request(http_options, request) + + # Jsonify the query params + query_params = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1.ProductInputsServiceClient.DeleteProductInput", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": "DeleteProductInput", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductInputsServiceRestTransport._DeleteProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _InsertProductInput(_BaseProductInputsServiceRestTransport._BaseInsertProductInput, ProductInputsServiceRestStub): + def __hash__(self): + return hash("ProductInputsServiceRestTransport.InsertProductInput") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__(self, + request: productinputs.InsertProductInputRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> productinputs.ProductInput: + r"""Call the insert product input method over HTTP. + + Args: + request (~.productinputs.InsertProductInputRequest): + The request object. Request message for the + InsertProductInput method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.productinputs.ProductInput: + This resource represents input data you submit for a + product, not the processed product that you see in + Merchant Center, in Shopping ads, or across Google + surfaces. Product inputs, rules and supplemental data + source data are combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. + For more information, see `Manage + products `__. + + Required product input attributes to pass data + validation checks are primarily defined in the `Products + Data + Specification `__. + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding attribute + in the `Products Data + Specification `__ + with `some + exceptions `__. + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + + http_options = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_http_options() + + request, metadata = self._interceptor.pre_insert_product_input(request, metadata) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_transcoded_request(http_options, request) + + body = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_request_body_json(transcoded_request) + + # Jsonify the query params + query_params = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1.ProductInputsServiceClient.InsertProductInput", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": "InsertProductInput", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductInputsServiceRestTransport._InsertProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = productinputs.ProductInput() + pb_resp = productinputs.ProductInput.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_insert_product_input(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_insert_product_input_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = productinputs.ProductInput.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1.ProductInputsServiceClient.insert_product_input", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": "InsertProductInput", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _UpdateProductInput(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput, ProductInputsServiceRestStub): + def __hash__(self): + return hash("ProductInputsServiceRestTransport.UpdateProductInput") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__(self, + request: productinputs.UpdateProductInputRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> productinputs.ProductInput: + r"""Call the update product input method over HTTP. + + Args: + request (~.productinputs.UpdateProductInputRequest): + The request object. Request message for the + UpdateProductInput method. The product + (primary input) must exist for the + update to succeed. If the update is for + a primary product input, the existing + primary product input must be from the + same data source. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.productinputs.ProductInput: + This resource represents input data you submit for a + product, not the processed product that you see in + Merchant Center, in Shopping ads, or across Google + surfaces. Product inputs, rules and supplemental data + source data are combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. + For more information, see `Manage + products `__. + + Required product input attributes to pass data + validation checks are primarily defined in the `Products + Data + Specification `__. + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding attribute + in the `Products Data + Specification `__ + with `some + exceptions `__. + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + + http_options = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_http_options() + + request, metadata = self._interceptor.pre_update_product_input(request, metadata) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_transcoded_request(http_options, request) + + body = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_request_body_json(transcoded_request) + + # Jsonify the query params + query_params = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1.ProductInputsServiceClient.UpdateProductInput", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": "UpdateProductInput", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductInputsServiceRestTransport._UpdateProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = productinputs.ProductInput() + pb_resp = productinputs.ProductInput.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_update_product_input(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_product_input_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = productinputs.ProductInput.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1.ProductInputsServiceClient.update_product_input", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", + "rpcName": "UpdateProductInput", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteProductInput(self._session, self._host, self._interceptor) # type: ignore + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + productinputs.ProductInput]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._InsertProductInput(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + productinputs.ProductInput]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateProductInput(self._session, self._host, self._interceptor) # type: ignore + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'ProductInputsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py new file mode 100644 index 000000000000..7d00878ac5a9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py @@ -0,0 +1,223 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json # type: ignore +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union + + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import productinputs + + +class _BaseProductInputsServiceRestTransport(ProductInputsServiceTransport): + """Base REST backend transport for ProductInputsService. + + Note: This class is not meant to be used directly. Use its sync and + async sub-classes instead. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[Any]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + + class _BaseDeleteProductInput: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/products/v1/{name=accounts/*/productInputs/*}', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = productinputs.DeleteProductInputRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseInsertProductInput: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/products/v1/{parent=accounts/*}/productInputs:insert', + 'body': 'product_input', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = productinputs.InsertProductInputRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + use_integers_for_enums=True + ) + return body + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseUpdateProductInput: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/products/v1/{product_input.name=accounts/*/productInputs/*}', + 'body': 'product_input', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = productinputs.UpdateProductInputRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + use_integers_for_enums=True + ) + return body + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + +__all__=( + '_BaseProductInputsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py new file mode 100644 index 000000000000..4513749ea12b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import ProductsServiceClient +from .async_client import ProductsServiceAsyncClient + +__all__ = ( + 'ProductsServiceClient', + 'ProductsServiceAsyncClient', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py new file mode 100644 index 000000000000..760a5bd1b3bd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py @@ -0,0 +1,527 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging as std_logging +from collections import OrderedDict +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union + +from google.shopping.merchant_products_v1 import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + + +try: + OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore + +from google.shopping.merchant_products_v1.services.products_service import pagers +from google.shopping.merchant_products_v1.types import products +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport +from .client import ProductsServiceClient + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +class ProductsServiceAsyncClient: + """Service to use Product resource.""" + + _client: ProductsServiceClient + + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = ProductsServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ProductsServiceClient._DEFAULT_UNIVERSE + + product_path = staticmethod(ProductsServiceClient.product_path) + parse_product_path = staticmethod(ProductsServiceClient.parse_product_path) + common_billing_account_path = staticmethod(ProductsServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductsServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductsServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductsServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductsServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductsServiceClient.parse_common_organization_path) + common_project_path = staticmethod(ProductsServiceClient.common_project_path) + parse_common_project_path = staticmethod(ProductsServiceClient.parse_common_project_path) + common_location_path = staticmethod(ProductsServiceClient.common_location_path) + parse_common_location_path = staticmethod(ProductsServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceAsyncClient: The constructed client. + """ + return ProductsServiceClient.from_service_account_info.__func__(ProductsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceAsyncClient: The constructed client. + """ + return ProductsServiceClient.from_service_account_file.__func__(ProductsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ProductsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> ProductsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductsServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._client._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used + by the client instance. + """ + return self._client._universe_domain + + get_transport_class = ProductsServiceClient.get_transport_class + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the products service async client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductsServiceTransport,Callable[..., ProductsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = ProductsServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1.ProductsServiceAsyncClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._client._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "credentialsType": None, + } + ) + + async def get_product(self, + request: Optional[Union[products.GetProductRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: + r"""Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + async def sample_get_product(): + # Create a client + client = merchant_products_v1.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1.types.GetProductRequest, dict]]): + The request object. Request message for the GetProduct + method. + name (:class:`str`): + Required. The name of the product to retrieve. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for + product name is ``accounts/123/products/en~US~sku123``. + A legacy local product name would be + ``accounts/123/products/local~en~US~sku123``. Note: For + calls to the v1beta version, the ``product`` section + consists of: + ``channel~content_language~feed_label~offer_id``, for + example: ``accounts/123/products/online~en~US~sku123``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.types.Product: + The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] + after applying rules and supplemental data sources. + This processed product matches what is shown in your + Merchant Center account. Each product is built from + exactly one primary data source product input, and + multiple supplemental data source inputs. After + inserting, updating, or deleting a product input, it + may take several minutes before the updated processed + product can be retrieved. + + All fields in the processed product and its + sub-messages match the name of their corresponding + attribute in the [Product data + specification](\ https://support.google.com/merchants/answer/7052112) + with some exceptions. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.GetProductRequest): + request = products.GetProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.get_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_products(self, + request: Optional[Union[products.ListProductsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListProductsAsyncPager: + r"""Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + async def sample_list_products(): + # Create a client + client = merchant_products_v1.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1.types.ListProductsRequest, dict]]): + The request object. Request message for the ListProducts + method. + parent (:class:`str`): + Required. The account to list processed products for. + Format: ``accounts/{account}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.services.products_service.pagers.ListProductsAsyncPager: + Response message for the ListProducts + method. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.ListProductsRequest): + request = products.ListProductsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.list_products] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsAsyncPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self) -> "ProductsServiceAsyncClient": + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +__all__ = ( + "ProductsServiceAsyncClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py new file mode 100644 index 000000000000..c7cf6d50815d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py @@ -0,0 +1,886 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from http import HTTPStatus +import json +import logging as std_logging +import os +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast +import warnings + +from google.shopping.merchant_products_v1 import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +from google.shopping.merchant_products_v1.services.products_service import pagers +from google.shopping.merchant_products_v1.types import products +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductsServiceGrpcTransport +from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport +from .transports.rest import ProductsServiceRestTransport + + +class ProductsServiceClientMeta(type): + """Metaclass for the ProductsService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] + _transport_registry["grpc"] = ProductsServiceGrpcTransport + _transport_registry["grpc_asyncio"] = ProductsServiceGrpcAsyncIOTransport + _transport_registry["rest"] = ProductsServiceRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[ProductsServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class ProductsServiceClient(metaclass=ProductsServiceClientMeta): + """Service to use Product resource.""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "merchantapi.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductsServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(account: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "accounts/{account}/products/{product}".format(account=account, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Deprecated. Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + + warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning) + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + """Return the API endpoint used by the client. + + Args: + api_override (str): The API endpoint override. If specified, this is always + the return value of this function and the other arguments are not used. + client_cert_source (bytes): The client certificate source used by the client. + universe_domain (str): The universe domain used by the client. + use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. + Possible values are "always", "auto", or "never". + + Returns: + str: The API endpoint to be used by the client. + """ + if api_override is not None: + api_endpoint = api_override + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + _default_universe = ProductsServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") + api_endpoint = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) + return api_endpoint + + @staticmethod + def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ProductsServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain + + def _validate_universe_domain(self): + """Validates client's and credentials' universe domains are consistent. + + Returns: + bool: True iff the configured universe domain is valid. + + Raises: + ValueError: If the configured universe domain is not valid. + """ + + # NOTE (b/349488459): universe validation is disabled until further notice. + return True + + def _add_cred_info_for_auth_errors( + self, + error: core_exceptions.GoogleAPICallError + ) -> None: + """Adds credential info string to error details for 401/403/404 errors. + + Args: + error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. + """ + if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: + return + + cred = self._transport._credentials + + # get_cred_info is only available in google-auth>=2.35.0 + if not hasattr(cred, "get_cred_info"): + return + + # ignore the type check since pypy test fails when get_cred_info + # is not available + cred_info = cred.get_cred_info() # type: ignore + if cred_info and hasattr(error._details, "append"): + error._details.append(json.dumps(cred_info)) + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used by the client instance. + """ + return self._universe_domain + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the products service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductsServiceTransport,Callable[..., ProductsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that the ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client_options = client_options + if isinstance(self._client_options, dict): + self._client_options = client_options_lib.from_dict(self._client_options) + if self._client_options is None: + self._client_options = client_options_lib.ClientOptions() + self._client_options = cast(client_options_lib.ClientOptions, self._client_options) + + universe_domain_opt = getattr(self._client_options, 'universe_domain', None) + + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductsServiceClient._read_environment_variables() + self._client_cert_source = ProductsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) + self._universe_domain = ProductsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False + + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + + api_key_value = getattr(self._client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + transport_provided = isinstance(transport, ProductsServiceTransport) + if transport_provided: + # transport is a ProductsServiceTransport instance. + if credentials or self._client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if self._client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = cast(ProductsServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = (self._api_endpoint or + ProductsServiceClient._get_api_endpoint( + self._client_options.api_endpoint, + self._client_cert_source, + self._universe_domain, + self._use_mtls_endpoint)) + + if not transport_provided: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + transport_init: Union[Type[ProductsServiceTransport], Callable[..., ProductsServiceTransport]] = ( + ProductsServiceClient.get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., ProductsServiceTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( + credentials=credentials, + credentials_file=self._client_options.credentials_file, + host=self._api_endpoint, + scopes=self._client_options.scopes, + client_cert_source_for_mtls=self._client_cert_source, + quota_project_id=self._client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=self._client_options.api_audience, + ) + + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1.ProductsServiceClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "credentialsType": None, + } + ) + + def get_product(self, + request: Optional[Union[products.GetProductRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: + r"""Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + def sample_get_product(): + # Create a client + client = merchant_products_v1.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1.types.GetProductRequest, dict]): + The request object. Request message for the GetProduct + method. + name (str): + Required. The name of the product to retrieve. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for + product name is ``accounts/123/products/en~US~sku123``. + A legacy local product name would be + ``accounts/123/products/local~en~US~sku123``. Note: For + calls to the v1beta version, the ``product`` section + consists of: + ``channel~content_language~feed_label~offer_id``, for + example: ``accounts/123/products/online~en~US~sku123``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.types.Product: + The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] + after applying rules and supplemental data sources. + This processed product matches what is shown in your + Merchant Center account. Each product is built from + exactly one primary data source product input, and + multiple supplemental data source inputs. After + inserting, updating, or deleting a product input, it + may take several minutes before the updated processed + product can be retrieved. + + All fields in the processed product and its + sub-messages match the name of their corresponding + attribute in the [Product data + specification](\ https://support.google.com/merchants/answer/7052112) + with some exceptions. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.GetProductRequest): + request = products.GetProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_products(self, + request: Optional[Union[products.ListProductsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListProductsPager: + r"""Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1 + + def sample_list_products(): + # Create a client + client = merchant_products_v1.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1.types.ListProductsRequest, dict]): + The request object. Request message for the ListProducts + method. + parent (str): + Required. The account to list processed products for. + Format: ``accounts/{account}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1.services.products_service.pagers.ListProductsPager: + Response message for the ListProducts + method. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.ListProductsRequest): + request = products.ListProductsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_products] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListProductsPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self) -> "ProductsServiceClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + +__all__ = ( + "ProductsServiceClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py new file mode 100644 index 000000000000..be6870244cb5 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import retry_async as retries_async +from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator, Union +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] + OptionalAsyncRetry = Union[retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore + +from google.shopping.merchant_products_v1.types import products + + +class ListProductsPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.shopping.merchant_products_v1.types.ListProductsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.shopping.merchant_products_v1.types.ListProductsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., products.ListProductsResponse], + request: products.ListProductsRequest, + response: products.ListProductsResponse, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.shopping.merchant_products_v1.types.ListProductsRequest): + The initial request object. + response (google.shopping.merchant_products_v1.types.ListProductsResponse): + The initial response object. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + self._method = method + self._request = products.ListProductsRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[products.ListProductsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[products.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsAsyncPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.shopping.merchant_products_v1.types.ListProductsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.shopping.merchant_products_v1.types.ListProductsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[products.ListProductsResponse]], + request: products.ListProductsRequest, + response: products.ListProductsResponse, + *, + retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.shopping.merchant_products_v1.types.ListProductsRequest): + The initial request object. + response (google.shopping.merchant_products_v1.types.ListProductsResponse): + The initial response object. + retry (google.api_core.retry.AsyncRetry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + self._method = method + self._request = products.ListProductsRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[products.ListProductsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[products.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/README.rst new file mode 100644 index 000000000000..c1cbe3d98697 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/README.rst @@ -0,0 +1,9 @@ + +transport inheritance structure +_______________________________ + +`ProductsServiceTransport` is the ABC for all transports. +- public child `ProductsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). +- public child `ProductsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). +- private child `_BaseProductsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). +- public child `ProductsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py new file mode 100644 index 000000000000..29d073519076 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import ProductsServiceTransport +from .grpc import ProductsServiceGrpcTransport +from .grpc_asyncio import ProductsServiceGrpcAsyncIOTransport +from .rest import ProductsServiceRestTransport +from .rest import ProductsServiceRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] +_transport_registry['grpc'] = ProductsServiceGrpcTransport +_transport_registry['grpc_asyncio'] = ProductsServiceGrpcAsyncIOTransport +_transport_registry['rest'] = ProductsServiceRestTransport + +__all__ = ( + 'ProductsServiceTransport', + 'ProductsServiceGrpcTransport', + 'ProductsServiceGrpcAsyncIOTransport', + 'ProductsServiceRestTransport', + 'ProductsServiceRestInterceptor', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py new file mode 100644 index 000000000000..69f23a4a98d5 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py @@ -0,0 +1,173 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.shopping.merchant_products_v1 import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +from google.shopping.merchant_products_v1.types import products + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductsServiceTransport(abc.ABC): + """Abstract transport class for ProductsService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/content', + ) + + DEFAULT_HOST: str = 'merchantapi.googleapis.com' + + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + if not hasattr(self, "_ignore_credentials"): + self._ignore_credentials: bool = False + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None and not self._ignore_credentials: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + @property + def host(self): + return self._host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.get_product: gapic_v1.method.wrap_method( + self.get_product, + default_timeout=None, + client_info=client_info, + ), + self.list_products: gapic_v1.method.wrap_method( + self.list_products, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + Union[ + products.Product, + Awaitable[products.Product] + ]]: + raise NotImplementedError() + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + Union[ + products.ListProductsResponse, + Awaitable[products.ListProductsResponse] + ]]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'ProductsServiceTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py new file mode 100644 index 000000000000..8c65f4a1f35c --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py @@ -0,0 +1,383 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging as std_logging +import pickle +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore + +from google.shopping.merchant_products_v1.types import products +from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductsServiceGrpcTransport(ProductsServiceTransport): + """gRPC backend transport for ProductsService. + + Service to use Product resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, grpc.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) + + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + products.Product]: + r"""Return a callable for the get product method over gRPC. + + Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + Returns: + Callable[[~.GetProductRequest], + ~.Product]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_product' not in self._stubs: + self._stubs['get_product'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductsService/GetProduct', + request_serializer=products.GetProductRequest.serialize, + response_deserializer=products.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + products.ListProductsResponse]: + r"""Return a callable for the list products method over gRPC. + + Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + Returns: + Callable[[~.ListProductsRequest], + ~.ListProductsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_products' not in self._stubs: + self._stubs['list_products'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductsService/ListProducts', + request_serializer=products.ListProductsRequest.serialize, + response_deserializer=products.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + def close(self): + self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'ProductsServiceGrpcTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py new file mode 100644 index 000000000000..76db9834d858 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py @@ -0,0 +1,409 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import inspect +import json +import pickle +import logging as std_logging +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import exceptions as core_exceptions +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore +from grpc.experimental import aio # type: ignore + +from google.shopping.merchant_products_v1.types import products +from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductsServiceGrpcTransport + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductsServiceGrpcAsyncIOTransport(ProductsServiceTransport): + """gRPC AsyncIO backend transport for ProductsService. + + Service to use Product resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, aio.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel + self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + Awaitable[products.Product]]: + r"""Return a callable for the get product method over gRPC. + + Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + Returns: + Callable[[~.GetProductRequest], + Awaitable[~.Product]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_product' not in self._stubs: + self._stubs['get_product'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductsService/GetProduct', + request_serializer=products.GetProductRequest.serialize, + response_deserializer=products.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + Awaitable[products.ListProductsResponse]]: + r"""Return a callable for the list products method over gRPC. + + Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + Returns: + Callable[[~.ListProductsRequest], + Awaitable[~.ListProductsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_products' not in self._stubs: + self._stubs['list_products'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1.ProductsService/ListProducts', + request_serializer=products.ListProductsRequest.serialize, + response_deserializer=products.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + def _prep_wrapped_messages(self, client_info): + """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.get_product: self._wrap_method( + self.get_product, + default_timeout=None, + client_info=client_info, + ), + self.list_products: self._wrap_method( + self.list_products, + default_timeout=None, + client_info=client_info, + ), + } + + def _wrap_method(self, func, *args, **kwargs): + if self._wrap_with_kind: # pragma: NO COVER + kwargs["kind"] = self.kind + return gapic_v1.method_async.wrap_method(func, *args, **kwargs) + + def close(self): + return self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc_asyncio" + + +__all__ = ( + 'ProductsServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py new file mode 100644 index 000000000000..28eb46e5dca5 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py @@ -0,0 +1,542 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import json # type: ignore + +from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import gapic_v1 +import google.protobuf + +from google.protobuf import json_format + +from requests import __version__ as requests_version +import dataclasses +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + + +from google.shopping.merchant_products_v1.types import products + + +from .rest_base import _BaseProductsServiceRestTransport +from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=f"requests@{requests_version}", +) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductsServiceRestInterceptor: + """Interceptor for ProductsService. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the ProductsServiceRestTransport. + + .. code-block:: python + class MyCustomProductsServiceInterceptor(ProductsServiceRestInterceptor): + def pre_get_product(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_product(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_products(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_products(self, response): + logging.log(f"Received response: {response}") + return response + + transport = ProductsServiceRestTransport(interceptor=MyCustomProductsServiceInterceptor()) + client = ProductsServiceClient(transport=transport) + + + """ + def pre_get_product(self, request: products.GetProductRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.GetProductRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for get_product + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductsService server. + """ + return request, metadata + + def post_get_product(self, response: products.Product) -> products.Product: + """Post-rpc interceptor for get_product + + DEPRECATED. Please use the `post_get_product_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductsService server but before + it is returned to user code. This `post_get_product` interceptor runs + before the `post_get_product_with_metadata` interceptor. + """ + return response + + def post_get_product_with_metadata(self, response: products.Product, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.Product, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_product + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductsService server but before it is returned to user code. + + We recommend only using this `post_get_product_with_metadata` + interceptor in new development instead of the `post_get_product` interceptor. + When both interceptors are used, this `post_get_product_with_metadata` interceptor runs after the + `post_get_product` interceptor. The (possibly modified) response returned by + `post_get_product` will be passed to + `post_get_product_with_metadata`. + """ + return response, metadata + + def pre_list_products(self, request: products.ListProductsRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for list_products + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductsService server. + """ + return request, metadata + + def post_list_products(self, response: products.ListProductsResponse) -> products.ListProductsResponse: + """Post-rpc interceptor for list_products + + DEPRECATED. Please use the `post_list_products_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductsService server but before + it is returned to user code. This `post_list_products` interceptor runs + before the `post_list_products_with_metadata` interceptor. + """ + return response + + def post_list_products_with_metadata(self, response: products.ListProductsResponse, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsResponse, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for list_products + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductsService server but before it is returned to user code. + + We recommend only using this `post_list_products_with_metadata` + interceptor in new development instead of the `post_list_products` interceptor. + When both interceptors are used, this `post_list_products_with_metadata` interceptor runs after the + `post_list_products` interceptor. The (possibly modified) response returned by + `post_list_products` will be passed to + `post_list_products_with_metadata`. + """ + return response, metadata + + +@dataclasses.dataclass +class ProductsServiceRestStub: + _session: AuthorizedSession + _host: str + _interceptor: ProductsServiceRestInterceptor + + +class ProductsServiceRestTransport(_BaseProductsServiceRestTransport): + """REST backend synchronous transport for ProductsService. + + Service to use Product resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[ProductsServiceRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + url_scheme=url_scheme, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or ProductsServiceRestInterceptor() + self._prep_wrapped_messages(client_info) + + class _GetProduct(_BaseProductsServiceRestTransport._BaseGetProduct, ProductsServiceRestStub): + def __hash__(self): + return hash("ProductsServiceRestTransport.GetProduct") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__(self, + request: products.GetProductRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> products.Product: + r"""Call the get product method over HTTP. + + Args: + request (~.products.GetProductRequest): + The request object. Request message for the GetProduct + method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.products.Product: + The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] + after applying rules and supplemental data sources. This + processed product matches what is shown in your Merchant + Center account. Each product is built from exactly one + primary data source product input, and multiple + supplemental data source inputs. After inserting, + updating, or deleting a product input, it may take + several minutes before the updated processed product can + be retrieved. + + All fields in the processed product and its sub-messages + match the name of their corresponding attribute in the + `Product data + specification `__ + with some exceptions. + + """ + + http_options = _BaseProductsServiceRestTransport._BaseGetProduct._get_http_options() + + request, metadata = self._interceptor.pre_get_product(request, metadata) + transcoded_request = _BaseProductsServiceRestTransport._BaseGetProduct._get_transcoded_request(http_options, request) + + # Jsonify the query params + query_params = _BaseProductsServiceRestTransport._BaseGetProduct._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1.ProductsServiceClient.GetProduct", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": "GetProduct", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductsServiceRestTransport._GetProduct._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = products.Product() + pb_resp = products.Product.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_get_product(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_product_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = products.Product.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1.ProductsServiceClient.get_product", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": "GetProduct", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _ListProducts(_BaseProductsServiceRestTransport._BaseListProducts, ProductsServiceRestStub): + def __hash__(self): + return hash("ProductsServiceRestTransport.ListProducts") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__(self, + request: products.ListProductsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> products.ListProductsResponse: + r"""Call the list products method over HTTP. + + Args: + request (~.products.ListProductsRequest): + The request object. Request message for the ListProducts + method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.products.ListProductsResponse: + Response message for the ListProducts + method. + + """ + + http_options = _BaseProductsServiceRestTransport._BaseListProducts._get_http_options() + + request, metadata = self._interceptor.pre_list_products(request, metadata) + transcoded_request = _BaseProductsServiceRestTransport._BaseListProducts._get_transcoded_request(http_options, request) + + # Jsonify the query params + query_params = _BaseProductsServiceRestTransport._BaseListProducts._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1.ProductsServiceClient.ListProducts", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": "ListProducts", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductsServiceRestTransport._ListProducts._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = products.ListProductsResponse() + pb_resp = products.ListProductsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_list_products(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_products_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = products.ListProductsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1.ProductsServiceClient.list_products", + extra = { + "serviceName": "google.shopping.merchant.products.v1.ProductsService", + "rpcName": "ListProducts", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + products.Product]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetProduct(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + products.ListProductsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListProducts(self._session, self._host, self._interceptor) # type: ignore + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'ProductsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py new file mode 100644 index 000000000000..5ec7d1f47516 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json # type: ignore +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union + + +from google.shopping.merchant_products_v1.types import products + + +class _BaseProductsServiceRestTransport(ProductsServiceTransport): + """Base REST backend transport for ProductsService. + + Note: This class is not meant to be used directly. Use its sync and + async sub-classes instead. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[Any]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + + class _BaseGetProduct: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/products/v1/{name=accounts/*/products/*}', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = products.GetProductRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductsServiceRestTransport._BaseGetProduct._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListProducts: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/products/v1/{parent=accounts/*}/products', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = products.ListProductsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductsServiceRestTransport._BaseListProducts._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + +__all__=( + '_BaseProductsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py new file mode 100644 index 000000000000..3adb8060e978 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .productinputs import ( + DeleteProductInputRequest, + InsertProductInputRequest, + ProductInput, + UpdateProductInputRequest, +) +from .products import ( + GetProductRequest, + ListProductsRequest, + ListProductsResponse, + Product, +) +from .products_common import ( + AutomatedDiscounts, + CloudExportAdditionalProperties, + FreeShippingThreshold, + LoyaltyPoints, + LoyaltyProgram, + ProductAttributes, + ProductCertification, + ProductDetail, + ProductDimension, + ProductInstallment, + ProductStatus, + ProductSustainabilityIncentive, + ProductWeight, + Shipping, + ShippingDimension, + ShippingWeight, + StructuredDescription, + StructuredTitle, + SubscriptionCost, + UnitPricingBaseMeasure, + UnitPricingMeasure, + AgeGroup, + Availability, + CertificationAuthority, + CertificationName, + Condition, + CreditType, + DigitalSourceType, + EnergyEfficiencyClass, + Gender, + Pause, + PickupMethod, + PickupSla, + SizeSystem, + SizeType, + SubscriptionPeriod, +) + +__all__ = ( + 'DeleteProductInputRequest', + 'InsertProductInputRequest', + 'ProductInput', + 'UpdateProductInputRequest', + 'GetProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'Product', + 'AutomatedDiscounts', + 'CloudExportAdditionalProperties', + 'FreeShippingThreshold', + 'LoyaltyPoints', + 'LoyaltyProgram', + 'ProductAttributes', + 'ProductCertification', + 'ProductDetail', + 'ProductDimension', + 'ProductInstallment', + 'ProductStatus', + 'ProductSustainabilityIncentive', + 'ProductWeight', + 'Shipping', + 'ShippingDimension', + 'ShippingWeight', + 'StructuredDescription', + 'StructuredTitle', + 'SubscriptionCost', + 'UnitPricingBaseMeasure', + 'UnitPricingMeasure', + 'AgeGroup', + 'Availability', + 'CertificationAuthority', + 'CertificationName', + 'Condition', + 'CreditType', + 'DigitalSourceType', + 'EnergyEfficiencyClass', + 'Gender', + 'Pause', + 'PickupMethod', + 'PickupSla', + 'SizeSystem', + 'SizeType', + 'SubscriptionPeriod', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py new file mode 100644 index 000000000000..ef9a740519b8 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py @@ -0,0 +1,313 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import field_mask_pb2 # type: ignore +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types + + +__protobuf__ = proto.module( + package='google.shopping.merchant.products.v1', + manifest={ + 'ProductInput', + 'InsertProductInputRequest', + 'UpdateProductInputRequest', + 'DeleteProductInputRequest', + }, +) + + +class ProductInput(proto.Message): + r"""This resource represents input data you submit for a product, not + the processed product that you see in Merchant Center, in Shopping + ads, or across Google surfaces. Product inputs, rules and + supplemental data source data are combined to create the processed + [Product][google.shopping.merchant.products.v1.Product]. For more + information, see `Manage + products `__. + + Required product input attributes to pass data validation checks are + primarily defined in the `Products Data + Specification `__. + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1.Product.offer_id]. + + After inserting, updating, or deleting a product input, it may take + several minutes before the processed product can be retrieved. + + All fields in the product input and its sub-messages match the + English name of their corresponding attribute in the `Products Data + Specification `__ + with `some + exceptions `__. + The following reference documentation lists the field names in the + **camelCase** casing style while the Products Data Specification + lists the names in the **snake_case** casing style. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + name (str): + Identifier. The name of the product input. Format: + ``accounts/{account}/productInputs/{productinput}`` where + the last section ``productinput`` consists of: + ``content_language~feed_label~offer_id`` example for product + input name is ``accounts/123/productInputs/en~US~sku123``. A + legacy local product input name would be + ``accounts/123/productInputs/local~en~US~sku123``. Note: For + calls to the v1beta version, the ``productInput`` section + consists of: + ``channel~content_language~feed_label~offer_id``, for + example: ``accounts/123/productInputs/online~en~US~sku123``. + product (str): + Output only. The name of the processed product. Format: + ``accounts/{account}/products/{product}`` + legacy_local (bool): + Immutable. Determines whether the product is **only** + targeting local destinations and whether the product name + should be distinguished with a ``local~`` prefix. For + example, ``accounts/123/productInputs/local~en~US~sku123``. + If a product that is not ``legacy_local`` is already + targeting local destinations, creating a ``legacy_local`` + product with an otherwise matching name will fail. + offer_id (str): + Required. Immutable. Your unique identifier for the product. + This is the same for the product input and processed + product. Leading and trailing whitespaces are stripped and + multiple whitespaces are replaced by a single whitespace + upon submission. See the `products data + specification `__ + for details. + content_language (str): + Required. Immutable. The two-letter `ISO + 639-1 `__ language + code for the product. + feed_label (str): + Required. Immutable. The feed label that lets you categorize + and identify your products. The maximum allowed characters + are 20, and the supported characters are ``A-Z``, ``0-9``, + hyphen, and underscore. The feed label must not include any + spaces. For more information, see `Using feed + labels `__. + version_number (int): + Optional. Immutable. Represents the existing version + (freshness) of the product, which can be used to preserve + the right order when multiple updates are done at the same + time. + + If set, the insertion is prevented when version number is + lower than the current version number of the existing + product. Re-insertion (for example, product refresh after 30 + days) can be performed with the current ``version_number``. + + Only supported for insertions into primary data sources. Do + not set this field for updates. Do not set this field for + insertions into supplemental data sources. + + If the operation is prevented, the aborted exception will be + thrown. + + This field is a member of `oneof`_ ``_version_number``. + product_attributes (google.shopping.merchant_products_v1.types.ProductAttributes): + Optional. A list of strongly-typed product + attributes. + custom_attributes (MutableSequence[google.shopping.type.types.CustomAttribute]): + Optional. A list of custom (merchant-provided) attributes. + It can also be used for submitting any attribute of the data + specification in its generic form (for example, + ``{ "name": "size type", "value": "regular" }``). This is + useful for submitting attributes not explicitly exposed by + the API. Maximum allowed number of characters for each + custom attribute is 10240 (represents sum of characters for + name and value). Maximum 2500 custom attributes can be set + per product, with total size of 102.4kB. Underscores in + custom attribute names are replaced by spaces upon + insertion. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + product: str = proto.Field( + proto.STRING, + number=2, + ) + legacy_local: bool = proto.Field( + proto.BOOL, + number=10, + ) + offer_id: str = proto.Field( + proto.STRING, + number=4, + ) + content_language: str = proto.Field( + proto.STRING, + number=5, + ) + feed_label: str = proto.Field( + proto.STRING, + number=6, + ) + version_number: int = proto.Field( + proto.INT64, + number=7, + optional=True, + ) + product_attributes: products_common.ProductAttributes = proto.Field( + proto.MESSAGE, + number=11, + message=products_common.ProductAttributes, + ) + custom_attributes: MutableSequence[types.CustomAttribute] = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=types.CustomAttribute, + ) + + +class InsertProductInputRequest(proto.Message): + r"""Request message for the InsertProductInput method. + + Attributes: + parent (str): + Required. The account where this product will be inserted. + Format: ``accounts/{account}`` + product_input (google.shopping.merchant_products_v1.types.ProductInput): + Required. The product input to insert. + data_source (str): + Required. The primary or supplemental product data source + name. If the product already exists and data source provided + is different, then the product will be moved to a new data + source. For more information, see `Overview of Data sources + sub-API `__. + + Only API data sources are supported. + + Format: ``accounts/{account}/dataSources/{datasource}``. For + example, ``accounts/123456/dataSources/104628``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + product_input: 'ProductInput' = proto.Field( + proto.MESSAGE, + number=2, + message='ProductInput', + ) + data_source: str = proto.Field( + proto.STRING, + number=3, + ) + + +class UpdateProductInputRequest(proto.Message): + r"""Request message for the UpdateProductInput method. + The product (primary input) must exist for the update to + succeed. If the update is for a primary product input, the + existing primary product input must be from the same data + source. + + Attributes: + product_input (google.shopping.merchant_products_v1.types.ProductInput): + Required. The product input resource to + update. Information you submit will be applied + to the processed product as well. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. The list of product attributes to be updated. + + If the update mask is omitted, then it is treated as implied + field mask equivalent to all fields that are populated (have + a non-empty value). + + Attributes specified in the update mask without a value + specified in the body will be deleted from the product. + + Update mask can only be specified for top level fields in + attributes and custom attributes. + + To specify the update mask for custom attributes you need to + add the ``custom_attribute.`` prefix. + + Providing special "*" value for full product replacement is + not supported. + data_source (str): + Required. The primary or supplemental product data source + where ``data_source`` name identifies the product input to + be updated. + + Only API data sources are supported. + + Format: ``accounts/{account}/dataSources/{datasource}``. For + example, ``accounts/123456/dataSources/104628``. + """ + + product_input: 'ProductInput' = proto.Field( + proto.MESSAGE, + number=1, + message='ProductInput', + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + data_source: str = proto.Field( + proto.STRING, + number=3, + ) + + +class DeleteProductInputRequest(proto.Message): + r"""Request message for the DeleteProductInput method. + + Attributes: + name (str): + Required. The name of the product input resource to delete. + Format: ``accounts/{account}/productInputs/{product}`` where + the last section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for product + name is ``accounts/123/productInputs/en~US~sku123``. + data_source (str): + Required. The primary or supplemental data source from which + the product input should be deleted. Format: + ``accounts/{account}/dataSources/{datasource}``. For + example, ``accounts/123456/dataSources/104628``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + data_source: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py new file mode 100644 index 000000000000..120e1e11d584 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py @@ -0,0 +1,272 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types + + +__protobuf__ = proto.module( + package='google.shopping.merchant.products.v1', + manifest={ + 'Product', + 'GetProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + }, +) + + +class Product(proto.Message): + r"""The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] after + applying rules and supplemental data sources. This processed product + matches what is shown in your Merchant Center account. Each product + is built from exactly one primary data source product input, and + multiple supplemental data source inputs. After inserting, updating, + or deleting a product input, it may take several minutes before the + updated processed product can be retrieved. + + All fields in the processed product and its sub-messages match the + name of their corresponding attribute in the `Product data + specification `__ + with some exceptions. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + name (str): + The name of the product. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for product + name is ``accounts/123/products/en~US~sku123``. A legacy + local product name would be + ``accounts/123/products/local~en~US~sku123``. Note: For + calls to the v1beta version, the ``product`` section + consists of: + ``channel~content_language~feed_label~offer_id``, for + example: ``accounts/123/products/online~en~US~sku123``. + legacy_local (bool): + Output only. Determines whether the product is **only** + targeting local destinations and whether the product name + should be distinguished with a ``local~`` prefix. For + example, ``accounts/123/products/local~en~US~sku123``. + offer_id (str): + Output only. Your unique identifier for the product. This is + the same for the product input and processed product. + Leading and trailing whitespaces are stripped and multiple + whitespaces are replaced by a single whitespace upon + submission. See the `product data + specification `__ + for details. + content_language (str): + Output only. The two-letter `ISO + 639-1 `__ language + code for the product. + feed_label (str): + Output only. The feed label lets you categorize and identify + your products. The maximum allowed characters is 20 and the + supported characters are\ ``A-Z``, ``0-9``, hyphen and + underscore. The feed label must not include any spaces. For + more information, see `Using feed + labels `__ + data_source (str): + Output only. The primary data source of the + product. + version_number (int): + Output only. Represents the existing version (freshness) of + the product, which can be used to preserve the right order + when multiple updates are done at the same time. + + If set, the insertion is prevented when version number is + lower than the current version number of the existing + product. Re-insertion (for example, product refresh after 30 + days) can be performed with the current ``version_number``. + + Only supported for insertions into primary data sources. + + If the operation is prevented, the aborted exception will be + thrown. + + This field is a member of `oneof`_ ``_version_number``. + product_attributes (google.shopping.merchant_products_v1.types.ProductAttributes): + Output only. A list of strongly-typed product + attributes. + custom_attributes (MutableSequence[google.shopping.type.types.CustomAttribute]): + Output only. A list of custom (merchant-provided) + attributes. It can also be used to submit any attribute of + the data specification in its generic form (for example, + ``{ "name": "size type", "value": "regular" }``). This is + useful for submitting attributes not explicitly exposed by + the API, such as additional attributes used for Buy on + Google. + product_status (google.shopping.merchant_products_v1.types.ProductStatus): + Output only. The status of a product, data + validation issues, that is, information about a + product computed asynchronously. + automated_discounts (google.shopping.merchant_products_v1.types.AutomatedDiscounts): + Output only. The automated discounts + information for the product. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + legacy_local: bool = proto.Field( + proto.BOOL, + number=11, + ) + offer_id: str = proto.Field( + proto.STRING, + number=3, + ) + content_language: str = proto.Field( + proto.STRING, + number=4, + ) + feed_label: str = proto.Field( + proto.STRING, + number=5, + ) + data_source: str = proto.Field( + proto.STRING, + number=6, + ) + version_number: int = proto.Field( + proto.INT64, + number=7, + optional=True, + ) + product_attributes: products_common.ProductAttributes = proto.Field( + proto.MESSAGE, + number=13, + message=products_common.ProductAttributes, + ) + custom_attributes: MutableSequence[types.CustomAttribute] = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=types.CustomAttribute, + ) + product_status: products_common.ProductStatus = proto.Field( + proto.MESSAGE, + number=10, + message=products_common.ProductStatus, + ) + automated_discounts: products_common.AutomatedDiscounts = proto.Field( + proto.MESSAGE, + number=12, + message=products_common.AutomatedDiscounts, + ) + + +class GetProductRequest(proto.Message): + r"""Request message for the GetProduct method. + + Attributes: + name (str): + Required. The name of the product to retrieve. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of: + ``content_language~feed_label~offer_id`` example for product + name is ``accounts/123/products/en~US~sku123``. A legacy + local product name would be + ``accounts/123/products/local~en~US~sku123``. Note: For + calls to the v1beta version, the ``product`` section + consists of: + ``channel~content_language~feed_label~offer_id``, for + example: ``accounts/123/products/online~en~US~sku123``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ListProductsRequest(proto.Message): + r"""Request message for the ListProducts method. + + Attributes: + parent (str): + Required. The account to list processed products for. + Format: ``accounts/{account}`` + page_size (int): + The maximum number of products to return. The + service may return fewer than this value. + The maximum value is 1000; values above 1000 + will be coerced to 1000. If unspecified, the + default page size of 25 products will be + returned. + page_token (str): + A page token, received from a previous ``ListProducts`` + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListProducts`` must match the call that provided the page + token. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsResponse(proto.Message): + r"""Response message for the ListProducts method. + + Attributes: + products (MutableSequence[google.shopping.merchant_products_v1.types.Product]): + The processed products from the specified + account. These are your processed products after + applying rules and supplemental data sources. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + """ + + @property + def raw_page(self): + return self + + products: MutableSequence['Product'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py new file mode 100644 index 000000000000..c85c38f94b0d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py @@ -0,0 +1,2449 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore +from google.shopping.type.types import types +from google.type import interval_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.shopping.merchant.products.v1', + manifest={ + 'SubscriptionPeriod', + 'AgeGroup', + 'Availability', + 'Condition', + 'Gender', + 'CreditType', + 'SizeSystem', + 'SizeType', + 'EnergyEfficiencyClass', + 'PickupMethod', + 'PickupSla', + 'Pause', + 'CertificationAuthority', + 'CertificationName', + 'DigitalSourceType', + 'ProductAttributes', + 'ShippingWeight', + 'ShippingDimension', + 'UnitPricingBaseMeasure', + 'UnitPricingMeasure', + 'SubscriptionCost', + 'ProductInstallment', + 'LoyaltyPoints', + 'LoyaltyProgram', + 'Shipping', + 'FreeShippingThreshold', + 'ProductDetail', + 'ProductCertification', + 'StructuredTitle', + 'StructuredDescription', + 'ProductDimension', + 'ProductWeight', + 'ProductStatus', + 'CloudExportAdditionalProperties', + 'ProductSustainabilityIncentive', + 'AutomatedDiscounts', + }, +) + + +class SubscriptionPeriod(proto.Enum): + r"""The subscription period of the product. + + Values: + SUBSCRIPTION_PERIOD_UNSPECIFIED (0): + Indicates that the subscription period is + unspecified. + MONTH (1): + Indicates that the subscription period is + month. + YEAR (2): + Indicates that the subscription period is + year. + """ + SUBSCRIPTION_PERIOD_UNSPECIFIED = 0 + MONTH = 1 + YEAR = 2 + + +class AgeGroup(proto.Enum): + r"""Target `age + group `__ of + the item. + + Values: + AGE_GROUP_UNSPECIFIED (0): + Age group is not specified. + ADULT (1): + Teens or older. + KIDS (2): + 5-13 years old. + TODDLER (3): + 1-5 years old. + INFANT (4): + 3-12 months old. + NEWBORN (5): + 0-3 months old. + """ + AGE_GROUP_UNSPECIFIED = 0 + ADULT = 1 + KIDS = 2 + TODDLER = 3 + INFANT = 4 + NEWBORN = 5 + + +class Availability(proto.Enum): + r"""`Availability `__ + status of the item. + + Values: + AVAILABILITY_UNSPECIFIED (0): + Availability is not specified. + IN_STOCK (1): + In stock. + OUT_OF_STOCK (2): + Out of stock. + PREORDER (3): + Pre-order. + LIMITED_AVAILABILITY (4): + Limited availability. + BACKORDER (5): + Backorder. + """ + AVAILABILITY_UNSPECIFIED = 0 + IN_STOCK = 1 + OUT_OF_STOCK = 2 + PREORDER = 3 + LIMITED_AVAILABILITY = 4 + BACKORDER = 5 + + +class Condition(proto.Enum): + r"""`Condition `__ + or state of the item. + + Values: + CONDITION_UNSPECIFIED (0): + Default value. This value is unused. + NEW (1): + Brand new, original, unopened packaging. + USED (2): + Previously used, original packaging opened or + missing. + REFURBISHED (3): + Professionally restored to working order, + comes with a warranty, may or may not have the + original packaging. + """ + CONDITION_UNSPECIFIED = 0 + NEW = 1 + USED = 2 + REFURBISHED = 3 + + +class Gender(proto.Enum): + r"""Target + `gender `__ of + the item. + + Values: + GENDER_UNSPECIFIED (0): + Gender is not specified. + MALE (1): + Male. + FEMALE (2): + Female. + UNISEX (3): + Unisex. + """ + GENDER_UNSPECIFIED = 0 + MALE = 1 + FEMALE = 2 + UNISEX = 3 + + +class CreditType(proto.Enum): + r"""Type of installment payments. + + Values: + CREDIT_TYPE_UNSPECIFIED (0): + Default value. This value is unused. + FINANCE (1): + Finance. + LEASE (2): + Lease. + """ + CREDIT_TYPE_UNSPECIFIED = 0 + FINANCE = 1 + LEASE = 2 + + +class SizeSystem(proto.Enum): + r"""System in which the size is specified. Recommended for apparel + items. For more information, see `Size + system `__. + + Values: + SIZE_SYSTEM_UNSPECIFIED (0): + Unspecified size system. + AU (1): + AU. + BR (2): + BR. + CN (3): + CN. + DE (4): + DE. + EU (5): + EU. + FR (6): + FR. + IT (7): + IT. + JP (8): + JP. + MEX (9): + MEX. + UK (10): + UK. + US (11): + US. + """ + SIZE_SYSTEM_UNSPECIFIED = 0 + AU = 1 + BR = 2 + CN = 3 + DE = 4 + EU = 5 + FR = 6 + IT = 7 + JP = 8 + MEX = 9 + UK = 10 + US = 11 + + +class SizeType(proto.Enum): + r"""The cut of the item. It can be used to represent combined size types + for apparel items. Maximum two of size types can be provided, see + `Size type `__. + + Values: + SIZE_TYPE_UNSPECIFIED (0): + The size type is not specified. + REGULAR (1): + Regular size. + PETITE (2): + Petite size. + MATERNITY (3): + Maternity size. + BIG (4): + Big size. + TALL (5): + Tall size. + PLUS (6): + Plus size. + """ + SIZE_TYPE_UNSPECIFIED = 0 + REGULAR = 1 + PETITE = 2 + MATERNITY = 3 + BIG = 4 + TALL = 5 + PLUS = 6 + + +class EnergyEfficiencyClass(proto.Enum): + r"""The `energy efficiency + class `__ as + defined in EU directive 2010/30/EU. + + Values: + ENERGY_EFFICIENCY_CLASS_UNSPECIFIED (0): + The energy efficiency class is unspecified. + APPP (1): + A+++. + APP (2): + A++. + AP (3): + A+. + A (4): + A. + B (5): + B. + C (6): + C. + D (7): + D. + E (8): + E. + F (9): + F. + G (10): + G. + """ + ENERGY_EFFICIENCY_CLASS_UNSPECIFIED = 0 + APPP = 1 + APP = 2 + AP = 3 + A = 4 + B = 5 + C = 6 + D = 7 + E = 8 + F = 9 + G = 10 + + +class PickupMethod(proto.Enum): + r"""The + `pickup `__ + option for the item. + + Values: + PICKUP_METHOD_UNSPECIFIED (0): + Pickup method is not specified. + NOT_SUPPORTED (1): + The item is not available for store pickup. + BUY (2): + The entire transaction occurs online. + RESERVE (3): + The item is reserved online and the + transaction occurs in-store. + SHIP_TO_STORE (4): + The item is purchased online and shipped to a + local store for the customer to pick up. + """ + PICKUP_METHOD_UNSPECIFIED = 0 + NOT_SUPPORTED = 1 + BUY = 2 + RESERVE = 3 + SHIP_TO_STORE = 4 + + +class PickupSla(proto.Enum): + r"""Item store pickup timeline. For more information, see `Pickup + SLA `__. + + Values: + PICKUP_SLA_UNSPECIFIED (0): + Pickup SLA is not specified. + SAME_DAY (1): + Indicates that the product is available for + pickup the same day that the order is placed, + subject to cut off times. + NEXT_DAY (2): + Indicates that the product is available for + pickup the following day that the order is + placed. + TWO_DAY (3): + Indicates that the product will be shipped to + a store for a customer to pick up in 2 days. + THREE_DAY (4): + Indicates that the product will be shipped to + a store for a customer to pick up in 3 days. + FOUR_DAY (5): + Indicates that the product will be shipped to + a store for a customer to pick up in 4 days + FIVE_DAY (6): + Indicates that the product will be shipped to + a store for a customer to pick up in 5 days. + SIX_DAY (7): + Indicates that the product will be shipped to + a store for a customer to pick up in 6 days. + MULTI_WEEK (8): + Indicates that the product will be shipped to + a store for a customer to pick up in one week or + more. + """ + PICKUP_SLA_UNSPECIFIED = 0 + SAME_DAY = 1 + NEXT_DAY = 2 + TWO_DAY = 3 + THREE_DAY = 4 + FOUR_DAY = 5 + FIVE_DAY = 6 + SIX_DAY = 7 + MULTI_WEEK = 8 + + +class Pause(proto.Enum): + r"""Publication of this item will be temporarily + `paused `__. + + Values: + PAUSE_UNSPECIFIED (0): + The pause is unspecified. + ADS (1): + You’re currently pausing your product for all + ads locations (including Shopping Ads, Display + Ads, and local inventory ads). + ALL (2): + You’re currently pausing your product for all + Shopping locations (including Shopping Ads, + Display Ads, local inventory ads, Buy on Google, + and free listings). + """ + PAUSE_UNSPECIFIED = 0 + ADS = 1 + ALL = 2 + + +class CertificationAuthority(proto.Enum): + r"""The certification authority. + + Values: + CERTIFICATION_AUTHORITY_UNSPECIFIED (0): + Certification authority is not specified. + ADEME (1): + For the French CO2 emissions class for + vehicles. + BMWK (2): + For the German CO2 emissions classes for + vehicles. + EPA (3): + Environment Protection Agency. + EC (4): + European Commission for energy labels in the + EU. + """ + CERTIFICATION_AUTHORITY_UNSPECIFIED = 0 + ADEME = 1 + BMWK = 2 + EPA = 3 + EC = 4 + + +class CertificationName(proto.Enum): + r"""The name of the certification. + + Values: + CERTIFICATION_NAME_UNSPECIFIED (0): + Certification name is not specified. + ENERGY_STAR (1): + Energy Star. + ENERGY_STAR_MOST_EFFICIENT (2): + Energy Star Most Efficient. + EPREL (3): + Represents energy efficiency certifications + in the EU European Registry for Energy Labeling + (EPREL) database. + EU_ECOLABEL (4): + EU Ecolabel. + VEHICLE_ENERGY_EFFICIENCY (5): + The overall CO2 class of a vehicle + VEHICLE_ENERGY_EFFICIENCY_DISCHARGED_BATTERY (6): + For the CO2 class of a vehicle with a + discharged battery. + """ + CERTIFICATION_NAME_UNSPECIFIED = 0 + ENERGY_STAR = 1 + ENERGY_STAR_MOST_EFFICIENT = 2 + EPREL = 3 + EU_ECOLABEL = 4 + VEHICLE_ENERGY_EFFICIENCY = 5 + VEHICLE_ENERGY_EFFICIENCY_DISCHARGED_BATTERY = 6 + + +class DigitalSourceType(proto.Enum): + r"""The digital source type. Following + `IPTC `__. + + Values: + DIGITAL_SOURCE_TYPE_UNSPECIFIED (0): + Digital source type is unspecified. + TRAINED_ALGORITHMIC_MEDIA (1): + Text created algorithmically using a model + derived from sampled content. + DEFAULT (2): + Text NOT created algorithmically using a + model derived from sampled content (the default) + """ + DIGITAL_SOURCE_TYPE_UNSPECIFIED = 0 + TRAINED_ALGORITHMIC_MEDIA = 1 + DEFAULT = 2 + + +class ProductAttributes(proto.Message): + r"""Product attributes. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + identifier_exists (bool): + Set this value to false when the item does + not have unique product identifiers appropriate + to its category, such as GTIN, MPN, and brand. + Defaults to true, if not provided. + + This field is a member of `oneof`_ ``_identifier_exists``. + is_bundle (bool): + Whether the item is a business-defined sub-API. A [sub-API] + (https://support.google.com/merchants/answer/6324449) is a + custom grouping of different products sold by a business for + a single price. + + This field is a member of `oneof`_ ``_is_bundle``. + title (str): + Title of the item. + + This field is a member of `oneof`_ ``_title``. + description (str): + Description of the item. + + This field is a member of `oneof`_ ``_description``. + link (str): + URL directly linking to your item's page on + your online store. + + This field is a member of `oneof`_ ``_link``. + mobile_link (str): + URL for the mobile-optimized version of your + item's landing page. + + This field is a member of `oneof`_ ``_mobile_link``. + canonical_link (str): + URL for the canonical version of your item's + landing page. + + This field is a member of `oneof`_ ``_canonical_link``. + image_link (str): + URL of an image of the item. + + This field is a member of `oneof`_ ``_image_link``. + additional_image_links (MutableSequence[str]): + Additional URLs of images of the item. + expiration_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item should expire, as specified upon + insertion, in `ISO + 8601 `__ format. The + actual expiration date is exposed in ``productstatuses`` as + `googleExpirationDate `__ + and might be earlier if ``expirationDate`` is too far in the + future. + disclosure_date (google.protobuf.timestamp_pb2.Timestamp): + The date time when an offer becomes visible in search + results across Google’s YouTube surfaces, in `ISO + 8601 `__ format. See + `Disclosure + date `__ + for more information. + adult (bool): + Set to true if the item is targeted towards + adults. + + This field is a member of `oneof`_ ``_adult``. + age_group (google.shopping.merchant_products_v1.types.AgeGroup): + Target `age + group `__ + of the item. + + This field is a member of `oneof`_ ``_age_group``. + availability (google.shopping.merchant_products_v1.types.Availability): + `Availability `__ + status of the item. + + This field is a member of `oneof`_ ``_availability``. + availability_date (google.protobuf.timestamp_pb2.Timestamp): + The day a pre-ordered product becomes available for + delivery, in `ISO + 8601 `__ format. + brand (str): + `Brand `__ + of the item. For example, "Google". + + This field is a member of `oneof`_ ``_brand``. + color (str): + `Color `__ + of the item. For example, "red". + + This field is a member of `oneof`_ ``_color``. + condition (google.shopping.merchant_products_v1.types.Condition): + `Condition `__ + or state of the item. + + This field is a member of `oneof`_ ``_condition``. + gender (google.shopping.merchant_products_v1.types.Gender): + Target + `gender `__ + of the item. + + This field is a member of `oneof`_ ``_gender``. + google_product_category (str): + Google's category of the item (see `Google product + taxonomy `__). + When querying products, this field will contain the user + provided value. There is currently no way to get back the + auto assigned google product categories through the API. + + This field is a member of `oneof`_ ``_google_product_category``. + gtins (MutableSequence[str]): + Global Trade Item Numbers + (`GTIN `__) + of the item. You can provide up to 10 GTINs. + item_group_id (str): + Shared identifier for all variants of the + same product. + + This field is a member of `oneof`_ ``_item_group_id``. + material (str): + The + `material `__ + of which the item is made. For example, "Leather" or + "Cotton". + + This field is a member of `oneof`_ ``_material``. + mpn (str): + Manufacturer Part Number + (`MPN `__) + of the item. + + This field is a member of `oneof`_ ``_mpn``. + pattern (str): + The item's + `pattern `__. + For example, polka dots. + + This field is a member of `oneof`_ ``_pattern``. + price (google.shopping.type.types.Price): + Price of the item. + maximum_retail_price (google.shopping.type.types.Price): + Maximum retail price (MRP) of the item. + Applicable to India only. + installment (google.shopping.merchant_products_v1.types.ProductInstallment): + Number and amount of installments to pay for + an item. + subscription_cost (google.shopping.merchant_products_v1.types.SubscriptionCost): + Number of periods (months or years) and + amount of payment per period for an item with an + associated subscription contract. + loyalty_points (google.shopping.merchant_products_v1.types.LoyaltyPoints): + Loyalty points that users receive after + purchasing the item. Japan only. + loyalty_programs (MutableSequence[google.shopping.merchant_products_v1.types.LoyaltyProgram]): + A list of loyalty program information that is + used to surface loyalty benefits (for example, + better pricing, points, etc) to the user of this + item. + product_types (MutableSequence[str]): + Categories of the item (formatted as in `product data + specification `__). + sale_price (google.shopping.type.types.Price): + Advertised sale price of the item. + sale_price_effective_date (google.type.interval_pb2.Interval): + Date range during which the item is on sale, see `product + data + specification `__. + sell_on_google_quantity (int): + The quantity of the product that is available + for selling on Google. Supported only for online + products. + + This field is a member of `oneof`_ ``_sell_on_google_quantity``. + product_height (google.shopping.merchant_products_v1.types.ProductDimension): + The height of the product in the units + provided. The value must be between + 0 (exclusive) and 3000 (inclusive). + product_length (google.shopping.merchant_products_v1.types.ProductDimension): + The length of the product in the units + provided. The value must be between 0 + (exclusive) and 3000 (inclusive). + product_width (google.shopping.merchant_products_v1.types.ProductDimension): + The width of the product in the units + provided. The value must be between 0 + (exclusive) and 3000 (inclusive). + product_weight (google.shopping.merchant_products_v1.types.ProductWeight): + The weight of the product in the units + provided. The value must be between 0 + (exclusive) and 2000 (inclusive). + shipping (MutableSequence[google.shopping.merchant_products_v1.types.Shipping]): + Shipping rules. + free_shipping_threshold (MutableSequence[google.shopping.merchant_products_v1.types.FreeShippingThreshold]): + Conditions to be met for a product to have + free shipping. + shipping_weight (google.shopping.merchant_products_v1.types.ShippingWeight): + Weight of the item for shipping. + shipping_length (google.shopping.merchant_products_v1.types.ShippingDimension): + Length of the item for shipping. + shipping_width (google.shopping.merchant_products_v1.types.ShippingDimension): + Width of the item for shipping. + shipping_height (google.shopping.merchant_products_v1.types.ShippingDimension): + Height of the item for shipping. + max_handling_time (int): + Maximal product handling time (in business + days). + + This field is a member of `oneof`_ ``_max_handling_time``. + min_handling_time (int): + Minimal product handling time (in business + days). + + This field is a member of `oneof`_ ``_min_handling_time``. + shipping_label (str): + The shipping label of the product, used to + group product in account-level shipping rules. + + This field is a member of `oneof`_ ``_shipping_label``. + transit_time_label (str): + The transit time label of the product, used + to group product in account-level transit time + tables. + + This field is a member of `oneof`_ ``_transit_time_label``. + size (str): + Size of the item. Only one value is allowed. For variants + with different sizes, insert a separate product for each + size with the same ``itemGroupId`` value, see + `Size `__. + + This field is a member of `oneof`_ ``_size``. + size_system (google.shopping.merchant_products_v1.types.SizeSystem): + System in which the size is specified. Recommended for + apparel items. For more information, see `Size + system `__. + + This field is a member of `oneof`_ ``_size_system``. + size_types (MutableSequence[google.shopping.merchant_products_v1.types.SizeType]): + The cut of the item. It can be used to represent combined + size types for apparel items. Maximum two of size types can + be provided, see `Size + type `__. + energy_efficiency_class (google.shopping.merchant_products_v1.types.EnergyEfficiencyClass): + The `energy efficiency + class `__ + as defined in EU directive 2010/30/EU. + + This field is a member of `oneof`_ ``_energy_efficiency_class``. + min_energy_efficiency_class (google.shopping.merchant_products_v1.types.EnergyEfficiencyClass): + The `energy efficiency + class `__ + as defined in EU directive 2010/30/EU. + + This field is a member of `oneof`_ ``_min_energy_efficiency_class``. + max_energy_efficiency_class (google.shopping.merchant_products_v1.types.EnergyEfficiencyClass): + The `energy efficiency + class `__ + as defined in EU directive 2010/30/EU. + + This field is a member of `oneof`_ ``_max_energy_efficiency_class``. + unit_pricing_measure (google.shopping.merchant_products_v1.types.UnitPricingMeasure): + The measure and dimension of an item. + unit_pricing_base_measure (google.shopping.merchant_products_v1.types.UnitPricingBaseMeasure): + The preference of the denominator of the unit + price. + multipack (int): + The number of identical products in a + business-defined multipack. + + This field is a member of `oneof`_ ``_multipack``. + ads_grouping (str): + Used to group items in an arbitrary way. Only for CPA%, + discouraged otherwise. For more information, see `Display + ads + attribute `__. + + This field is a member of `oneof`_ ``_ads_grouping``. + ads_labels (MutableSequence[str]): + Similar to ads_grouping, but only works on CPC. + ads_redirect (str): + Allows advertisers to override the item URL + when the product is shown within the context of + Product ads. + + This field is a member of `oneof`_ ``_ads_redirect``. + cost_of_goods_sold (google.shopping.type.types.Price): + Cost of goods sold. Used for gross profit + reporting. + product_details (MutableSequence[google.shopping.merchant_products_v1.types.ProductDetail]): + Technical specification or additional product + details. + product_highlights (MutableSequence[str]): + Bullet points describing the most relevant `product + highlights `__. + display_ads_id (str): + An identifier for an item for dynamic + remarketing campaigns. + + This field is a member of `oneof`_ ``_display_ads_id``. + display_ads_similar_ids (MutableSequence[str]): + Advertiser-specified recommendations. For more information, + see `Display ads attribute + specification `__. + display_ads_title (str): + Title of an item for dynamic remarketing + campaigns. + + This field is a member of `oneof`_ ``_display_ads_title``. + display_ads_link (str): + URL directly to your item's landing page for + dynamic remarketing campaigns. + + This field is a member of `oneof`_ ``_display_ads_link``. + display_ads_value (float): + Offer margin for dynamic remarketing campaigns. For more + information, see `Display ads + attribute `__. + + This field is a member of `oneof`_ ``_display_ads_value``. + promotion_ids (MutableSequence[str]): + The unique ID of a promotion. + pickup_method (google.shopping.merchant_products_v1.types.PickupMethod): + The + `pickup `__ + option for the item. + + This field is a member of `oneof`_ ``_pickup_method``. + pickup_sla (google.shopping.merchant_products_v1.types.PickupSla): + Item store pickup timeline. For more information, see + `Pickup + SLA `__. + + This field is a member of `oneof`_ ``_pickup_sla``. + link_template (str): + `Link + template `__ + for business hosted local storefront. + + This field is a member of `oneof`_ ``_link_template``. + mobile_link_template (str): + `Link + template `__ + for business hosted local storefront optimized for mobile + devices. + + This field is a member of `oneof`_ ``_mobile_link_template``. + custom_label_0 (str): + `Custom label + 0 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_0``. + custom_label_1 (str): + `Custom label + 1 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_1``. + custom_label_2 (str): + `Custom label + 2 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_2``. + custom_label_3 (str): + `Custom label + 3 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_3``. + custom_label_4 (str): + `Custom label + 4 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_4``. + included_destinations (MutableSequence[google.shopping.type.types.Destination.DestinationEnum]): + The list of destinations to include for this target + (corresponds to checked check boxes in Merchant Center). + Default destinations are always included unless provided in + ``excludedDestinations``. + + For more information, see `Included + destination `__. + + Note: We recommend setting destinations on datasources level + for most use cases. Use this field within products to only + setup exceptions. + excluded_destinations (MutableSequence[google.shopping.type.types.Destination.DestinationEnum]): + The list of destinations to exclude for this target + (corresponds to unchecked check boxes in Merchant Center). + + For more information, see `Excluded + destination `__. + + Note: We recommend setting destinations on datasources level + for most use cases. Use this field within products to only + setup exceptions. + shopping_ads_excluded_countries (MutableSequence[str]): + List of country codes `(ISO 3166-1 + alpha-2) `__ + to exclude the offer from Shopping Ads destination. + Countries from this list are removed from countries + configured in data source settings. + external_seller_id (str): + Required for multi-seller accounts. Use this + attribute if you're a marketplace uploading + products for various sellers to your + multi-seller account. + + This field is a member of `oneof`_ ``_external_seller_id``. + pause (google.shopping.merchant_products_v1.types.Pause): + Publication of this item will be temporarily + `paused `__. + + This field is a member of `oneof`_ ``_pause``. + lifestyle_image_links (MutableSequence[str]): + Additional URLs of lifestyle images of the item, used to + explicitly identify images that showcase your item in a + real-world context. See the `Help Center + article `__ + for more information. + cloud_export_additional_properties (MutableSequence[google.shopping.merchant_products_v1.types.CloudExportAdditionalProperties]): + Extra fields to export to the Cloud Retail + program. + virtual_model_link (str): + URL of the 3D image of the item. See the `Help Center + article `__ + for more information. + + This field is a member of `oneof`_ ``_virtual_model_link``. + certifications (MutableSequence[google.shopping.merchant_products_v1.types.ProductCertification]): + Product Certifications, for example for energy efficiency + labeling of products recorded in the `EU + EPREL `__ database. + See the `Help + Center `__ + article for more information. + structured_title (google.shopping.merchant_products_v1.types.StructuredTitle): + Structured title, for algorithmically + (AI)-generated titles. + + This field is a member of `oneof`_ ``_structured_title``. + structured_description (google.shopping.merchant_products_v1.types.StructuredDescription): + Structured description, for algorithmically + (AI)-generated descriptions. + + This field is a member of `oneof`_ ``_structured_description``. + auto_pricing_min_price (google.shopping.type.types.Price): + A safeguard in the [automated discounts] + (https://support.google.com/merchants/answer/10295759) and + "Dynamic Promotions" + (https://support.google.com/merchants/answer/13949249) + projects, ensuring that discounts on business offers do not + fall below this value, thereby preserving the offer's value + and profitability. + sustainability_incentives (MutableSequence[google.shopping.merchant_products_v1.types.ProductSustainabilityIncentive]): + The list of sustainability incentive + programs. + """ + + identifier_exists: bool = proto.Field( + proto.BOOL, + number=4, + optional=True, + ) + is_bundle: bool = proto.Field( + proto.BOOL, + number=5, + optional=True, + ) + title: str = proto.Field( + proto.STRING, + number=6, + optional=True, + ) + description: str = proto.Field( + proto.STRING, + number=7, + optional=True, + ) + link: str = proto.Field( + proto.STRING, + number=8, + optional=True, + ) + mobile_link: str = proto.Field( + proto.STRING, + number=9, + optional=True, + ) + canonical_link: str = proto.Field( + proto.STRING, + number=10, + optional=True, + ) + image_link: str = proto.Field( + proto.STRING, + number=11, + optional=True, + ) + additional_image_links: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=12, + ) + expiration_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=16, + message=timestamp_pb2.Timestamp, + ) + disclosure_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=79, + message=timestamp_pb2.Timestamp, + ) + adult: bool = proto.Field( + proto.BOOL, + number=17, + optional=True, + ) + age_group: 'AgeGroup' = proto.Field( + proto.ENUM, + number=18, + optional=True, + enum='AgeGroup', + ) + availability: 'Availability' = proto.Field( + proto.ENUM, + number=19, + optional=True, + enum='Availability', + ) + availability_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=20, + message=timestamp_pb2.Timestamp, + ) + brand: str = proto.Field( + proto.STRING, + number=21, + optional=True, + ) + color: str = proto.Field( + proto.STRING, + number=22, + optional=True, + ) + condition: 'Condition' = proto.Field( + proto.ENUM, + number=23, + optional=True, + enum='Condition', + ) + gender: 'Gender' = proto.Field( + proto.ENUM, + number=24, + optional=True, + enum='Gender', + ) + google_product_category: str = proto.Field( + proto.STRING, + number=25, + optional=True, + ) + gtins: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=140, + ) + item_group_id: str = proto.Field( + proto.STRING, + number=27, + optional=True, + ) + material: str = proto.Field( + proto.STRING, + number=28, + optional=True, + ) + mpn: str = proto.Field( + proto.STRING, + number=29, + optional=True, + ) + pattern: str = proto.Field( + proto.STRING, + number=30, + optional=True, + ) + price: types.Price = proto.Field( + proto.MESSAGE, + number=31, + message=types.Price, + ) + maximum_retail_price: types.Price = proto.Field( + proto.MESSAGE, + number=139, + message=types.Price, + ) + installment: 'ProductInstallment' = proto.Field( + proto.MESSAGE, + number=32, + message='ProductInstallment', + ) + subscription_cost: 'SubscriptionCost' = proto.Field( + proto.MESSAGE, + number=33, + message='SubscriptionCost', + ) + loyalty_points: 'LoyaltyPoints' = proto.Field( + proto.MESSAGE, + number=34, + message='LoyaltyPoints', + ) + loyalty_programs: MutableSequence['LoyaltyProgram'] = proto.RepeatedField( + proto.MESSAGE, + number=136, + message='LoyaltyProgram', + ) + product_types: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=35, + ) + sale_price: types.Price = proto.Field( + proto.MESSAGE, + number=36, + message=types.Price, + ) + sale_price_effective_date: interval_pb2.Interval = proto.Field( + proto.MESSAGE, + number=37, + message=interval_pb2.Interval, + ) + sell_on_google_quantity: int = proto.Field( + proto.INT64, + number=38, + optional=True, + ) + product_height: 'ProductDimension' = proto.Field( + proto.MESSAGE, + number=119, + message='ProductDimension', + ) + product_length: 'ProductDimension' = proto.Field( + proto.MESSAGE, + number=120, + message='ProductDimension', + ) + product_width: 'ProductDimension' = proto.Field( + proto.MESSAGE, + number=121, + message='ProductDimension', + ) + product_weight: 'ProductWeight' = proto.Field( + proto.MESSAGE, + number=122, + message='ProductWeight', + ) + shipping: MutableSequence['Shipping'] = proto.RepeatedField( + proto.MESSAGE, + number=39, + message='Shipping', + ) + free_shipping_threshold: MutableSequence['FreeShippingThreshold'] = proto.RepeatedField( + proto.MESSAGE, + number=135, + message='FreeShippingThreshold', + ) + shipping_weight: 'ShippingWeight' = proto.Field( + proto.MESSAGE, + number=40, + message='ShippingWeight', + ) + shipping_length: 'ShippingDimension' = proto.Field( + proto.MESSAGE, + number=41, + message='ShippingDimension', + ) + shipping_width: 'ShippingDimension' = proto.Field( + proto.MESSAGE, + number=42, + message='ShippingDimension', + ) + shipping_height: 'ShippingDimension' = proto.Field( + proto.MESSAGE, + number=43, + message='ShippingDimension', + ) + max_handling_time: int = proto.Field( + proto.INT64, + number=44, + optional=True, + ) + min_handling_time: int = proto.Field( + proto.INT64, + number=45, + optional=True, + ) + shipping_label: str = proto.Field( + proto.STRING, + number=46, + optional=True, + ) + transit_time_label: str = proto.Field( + proto.STRING, + number=47, + optional=True, + ) + size: str = proto.Field( + proto.STRING, + number=48, + optional=True, + ) + size_system: 'SizeSystem' = proto.Field( + proto.ENUM, + number=49, + optional=True, + enum='SizeSystem', + ) + size_types: MutableSequence['SizeType'] = proto.RepeatedField( + proto.ENUM, + number=50, + enum='SizeType', + ) + energy_efficiency_class: 'EnergyEfficiencyClass' = proto.Field( + proto.ENUM, + number=53, + optional=True, + enum='EnergyEfficiencyClass', + ) + min_energy_efficiency_class: 'EnergyEfficiencyClass' = proto.Field( + proto.ENUM, + number=54, + optional=True, + enum='EnergyEfficiencyClass', + ) + max_energy_efficiency_class: 'EnergyEfficiencyClass' = proto.Field( + proto.ENUM, + number=55, + optional=True, + enum='EnergyEfficiencyClass', + ) + unit_pricing_measure: 'UnitPricingMeasure' = proto.Field( + proto.MESSAGE, + number=56, + message='UnitPricingMeasure', + ) + unit_pricing_base_measure: 'UnitPricingBaseMeasure' = proto.Field( + proto.MESSAGE, + number=57, + message='UnitPricingBaseMeasure', + ) + multipack: int = proto.Field( + proto.INT64, + number=58, + optional=True, + ) + ads_grouping: str = proto.Field( + proto.STRING, + number=59, + optional=True, + ) + ads_labels: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=60, + ) + ads_redirect: str = proto.Field( + proto.STRING, + number=61, + optional=True, + ) + cost_of_goods_sold: types.Price = proto.Field( + proto.MESSAGE, + number=62, + message=types.Price, + ) + product_details: MutableSequence['ProductDetail'] = proto.RepeatedField( + proto.MESSAGE, + number=63, + message='ProductDetail', + ) + product_highlights: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=64, + ) + display_ads_id: str = proto.Field( + proto.STRING, + number=65, + optional=True, + ) + display_ads_similar_ids: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=66, + ) + display_ads_title: str = proto.Field( + proto.STRING, + number=67, + optional=True, + ) + display_ads_link: str = proto.Field( + proto.STRING, + number=68, + optional=True, + ) + display_ads_value: float = proto.Field( + proto.DOUBLE, + number=69, + optional=True, + ) + promotion_ids: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=70, + ) + pickup_method: 'PickupMethod' = proto.Field( + proto.ENUM, + number=80, + optional=True, + enum='PickupMethod', + ) + pickup_sla: 'PickupSla' = proto.Field( + proto.ENUM, + number=81, + optional=True, + enum='PickupSla', + ) + link_template: str = proto.Field( + proto.STRING, + number=82, + optional=True, + ) + mobile_link_template: str = proto.Field( + proto.STRING, + number=83, + optional=True, + ) + custom_label_0: str = proto.Field( + proto.STRING, + number=71, + optional=True, + ) + custom_label_1: str = proto.Field( + proto.STRING, + number=72, + optional=True, + ) + custom_label_2: str = proto.Field( + proto.STRING, + number=73, + optional=True, + ) + custom_label_3: str = proto.Field( + proto.STRING, + number=74, + optional=True, + ) + custom_label_4: str = proto.Field( + proto.STRING, + number=75, + optional=True, + ) + included_destinations: MutableSequence[types.Destination.DestinationEnum] = proto.RepeatedField( + proto.ENUM, + number=76, + enum=types.Destination.DestinationEnum, + ) + excluded_destinations: MutableSequence[types.Destination.DestinationEnum] = proto.RepeatedField( + proto.ENUM, + number=77, + enum=types.Destination.DestinationEnum, + ) + shopping_ads_excluded_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=78, + ) + external_seller_id: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + pause: 'Pause' = proto.Field( + proto.ENUM, + number=13, + optional=True, + enum='Pause', + ) + lifestyle_image_links: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=14, + ) + cloud_export_additional_properties: MutableSequence['CloudExportAdditionalProperties'] = proto.RepeatedField( + proto.MESSAGE, + number=84, + message='CloudExportAdditionalProperties', + ) + virtual_model_link: str = proto.Field( + proto.STRING, + number=130, + optional=True, + ) + certifications: MutableSequence['ProductCertification'] = proto.RepeatedField( + proto.MESSAGE, + number=123, + message='ProductCertification', + ) + structured_title: 'StructuredTitle' = proto.Field( + proto.MESSAGE, + number=132, + optional=True, + message='StructuredTitle', + ) + structured_description: 'StructuredDescription' = proto.Field( + proto.MESSAGE, + number=133, + optional=True, + message='StructuredDescription', + ) + auto_pricing_min_price: types.Price = proto.Field( + proto.MESSAGE, + number=124, + message=types.Price, + ) + sustainability_incentives: MutableSequence['ProductSustainabilityIncentive'] = proto.RepeatedField( + proto.MESSAGE, + number=138, + message='ProductSustainabilityIncentive', + ) + + +class ShippingWeight(proto.Message): + r"""The ShippingWeight of the product. + + Attributes: + value (float): + The weight of the product used to calculate + the shipping cost of the item. + unit (str): + The unit of value. + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ShippingDimension(proto.Message): + r"""The ShippingDimension of the product. + + Attributes: + value (float): + The dimension of the product used to + calculate the shipping cost of the item. + unit (str): + The unit of value. + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class UnitPricingBaseMeasure(proto.Message): + r"""The UnitPricingBaseMeasure of the product. + + Attributes: + value (int): + The denominator of the unit price. + unit (str): + The unit of the denominator. + """ + + value: int = proto.Field( + proto.INT64, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class UnitPricingMeasure(proto.Message): + r"""The UnitPricingMeasure of the product. + + Attributes: + value (float): + The measure of an item. + unit (str): + The unit of the measure. + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class SubscriptionCost(proto.Message): + r"""The SubscriptionCost of the product. + + Attributes: + period (google.shopping.merchant_products_v1.types.SubscriptionPeriod): + The type of subscription period. Supported values are: + + - "``month``" + - "``year``". + period_length (int): + The number of subscription periods the buyer + has to pay. + amount (google.shopping.type.types.Price): + The amount the buyer has to pay per + subscription period. + """ + + period: 'SubscriptionPeriod' = proto.Field( + proto.ENUM, + number=1, + enum='SubscriptionPeriod', + ) + period_length: int = proto.Field( + proto.INT64, + number=2, + ) + amount: types.Price = proto.Field( + proto.MESSAGE, + number=3, + message=types.Price, + ) + + +class ProductInstallment(proto.Message): + r"""A message that represents installment. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + months (int): + The number of installments the buyer has to + pay. + amount (google.shopping.type.types.Price): + The amount the buyer has to pay per month. + downpayment (google.shopping.type.types.Price): + The up-front down payment amount the buyer + has to pay. + + This field is a member of `oneof`_ ``_downpayment``. + credit_type (google.shopping.merchant_products_v1.types.CreditType): + Type of installment payments. + + This field is a member of `oneof`_ ``_credit_type``. + """ + + months: int = proto.Field( + proto.INT64, + number=1, + ) + amount: types.Price = proto.Field( + proto.MESSAGE, + number=2, + message=types.Price, + ) + downpayment: types.Price = proto.Field( + proto.MESSAGE, + number=3, + optional=True, + message=types.Price, + ) + credit_type: 'CreditType' = proto.Field( + proto.ENUM, + number=4, + optional=True, + enum='CreditType', + ) + + +class LoyaltyPoints(proto.Message): + r"""A message that represents loyalty points. + + Attributes: + name (str): + Name of loyalty points program. It is + recommended to limit the name to 12 full-width + characters or 24 Roman characters. + points_value (int): + The retailer's loyalty points in absolute + value. + ratio (float): + The ratio of a point when converted to + currency. Google assumes currency based on + Merchant Center settings. If ratio is left out, + it defaults to 1.0. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + points_value: int = proto.Field( + proto.INT64, + number=2, + ) + ratio: float = proto.Field( + proto.DOUBLE, + number=3, + ) + + +class LoyaltyProgram(proto.Message): + r"""A message that represents loyalty program. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + program_label (str): + The label of the loyalty program. This is an + internal label that uniquely identifies the + relationship between a business entity and a + loyalty program entity. The label must be + provided so that the system can associate the + assets below (for example, price and points) + with a business. The corresponding program must + be linked to the Merchant Center account. + + This field is a member of `oneof`_ ``_program_label``. + tier_label (str): + The label of the tier within the loyalty + program. Must match one of the labels within the + program. + + This field is a member of `oneof`_ ``_tier_label``. + price (google.shopping.type.types.Price): + The price for members of the given tier, that + is, the instant discount price. Must be smaller + or equal to the regular price. + + This field is a member of `oneof`_ ``_price``. + cashback_for_future_use (google.shopping.type.types.Price): + The cashback that can be used for future + purchases. + + This field is a member of `oneof`_ ``_cashback_for_future_use``. + loyalty_points (int): + The amount of loyalty points earned on a + purchase. + + This field is a member of `oneof`_ ``_loyalty_points``. + member_price_effective_date (google.type.interval_pb2.Interval): + A date range during which the item is + eligible for member price. If not specified, the + member price is always applicable. The date + range is represented by a pair of ISO 8601 dates + separated by a space, comma, or slash. + + This field is a member of `oneof`_ ``_member_price_effective_date``. + shipping_label (str): + The label of the shipping benefit. If the + field has value, this offer has loyalty shipping + benefit. If the field value isn't provided, the + item is not eligible for loyalty shipping for + the given loyalty tier. + + This field is a member of `oneof`_ ``_shipping_label``. + """ + + program_label: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + tier_label: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + price: types.Price = proto.Field( + proto.MESSAGE, + number=3, + optional=True, + message=types.Price, + ) + cashback_for_future_use: types.Price = proto.Field( + proto.MESSAGE, + number=4, + optional=True, + message=types.Price, + ) + loyalty_points: int = proto.Field( + proto.INT64, + number=5, + optional=True, + ) + member_price_effective_date: interval_pb2.Interval = proto.Field( + proto.MESSAGE, + number=6, + optional=True, + message=interval_pb2.Interval, + ) + shipping_label: str = proto.Field( + proto.STRING, + number=7, + optional=True, + ) + + +class Shipping(proto.Message): + r"""The Shipping of the product. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + price (google.shopping.type.types.Price): + Fixed shipping price, represented as a + number. + country (str): + The `CLDR territory + code `__ + of the country to which an item will ship. + region (str): + The geographic region to which a shipping rate applies. See + `region `__ + for more information. + service (str): + A free-form description of the service class + or delivery speed. + location_id (int): + The numeric ID of a location that the shipping rate applies + to as defined in the `AdWords + API `__. + location_group_name (str): + The location where the shipping is + applicable, represented by a location group + name. + postal_code (str): + The postal code range that the shipping rate applies to, + represented by a postal code, a postal code prefix followed + by a \* wildcard, a range between two postal codes or two + postal code prefixes of equal length. + min_handling_time (int): + Minimum handling time (inclusive) between when the order is + received and shipped in business days. 0 means that the + order is shipped on the same day as it is received if it + happens before the cut-off time. + [minHandlingTime][google.shopping.merchant.products.v1.Shipping.min_handling_time] + can only be present together with + [maxHandlingTime][google.shopping.merchant.products.v1.Shipping.max_handling_time]; + but it is not required if + [maxHandlingTime][google.shopping.merchant.products.v1.Shipping.max_handling_time] + is present. + + This field is a member of `oneof`_ ``_min_handling_time``. + max_handling_time (int): + Maximum handling time (inclusive) between when the order is + received and shipped in business days. 0 means that the + order is shipped on the same day as it is received if it + happens before the cut-off time. Both + [maxHandlingTime][google.shopping.merchant.products.v1.Shipping.max_handling_time] + and + [maxTransitTime][google.shopping.merchant.products.v1.Shipping.max_transit_time] + are required if providing shipping speeds. + [minHandlingTime][google.shopping.merchant.products.v1.Shipping.min_handling_time] + is optional if + [maxHandlingTime][google.shopping.merchant.products.v1.Shipping.max_handling_time] + is present. + + This field is a member of `oneof`_ ``_max_handling_time``. + min_transit_time (int): + Minimum transit time (inclusive) between when the order has + shipped and when it is delivered in business days. 0 means + that the order is delivered on the same day as it ships. + [minTransitTime][google.shopping.merchant.products.v1.Shipping.min_transit_time] + can only be present together with + [maxTransitTime][google.shopping.merchant.products.v1.Shipping.max_transit_time]; + but it is not required if + [maxTransitTime][google.shopping.merchant.products.v1.Shipping.max_transit_time] + is present. + + This field is a member of `oneof`_ ``_min_transit_time``. + max_transit_time (int): + Maximum transit time (inclusive) between when the order has + shipped and when it is delivered in business days. 0 means + that the order is delivered on the same day as it ships. + Both + [maxHandlingTime][google.shopping.merchant.products.v1.Shipping.max_handling_time] + and + [maxTransitTime][google.shopping.merchant.products.v1.Shipping.max_transit_time] + are required if providing shipping speeds. + [minTransitTime][google.shopping.merchant.products.v1.Shipping.min_transit_time] + is optional if + [maxTransitTime][google.shopping.merchant.products.v1.Shipping.max_transit_time] + is present. + + This field is a member of `oneof`_ ``_max_transit_time``. + """ + + price: types.Price = proto.Field( + proto.MESSAGE, + number=1, + message=types.Price, + ) + country: str = proto.Field( + proto.STRING, + number=2, + ) + region: str = proto.Field( + proto.STRING, + number=3, + ) + service: str = proto.Field( + proto.STRING, + number=4, + ) + location_id: int = proto.Field( + proto.INT64, + number=5, + ) + location_group_name: str = proto.Field( + proto.STRING, + number=6, + ) + postal_code: str = proto.Field( + proto.STRING, + number=7, + ) + min_handling_time: int = proto.Field( + proto.INT64, + number=8, + optional=True, + ) + max_handling_time: int = proto.Field( + proto.INT64, + number=9, + optional=True, + ) + min_transit_time: int = proto.Field( + proto.INT64, + number=10, + optional=True, + ) + max_transit_time: int = proto.Field( + proto.INT64, + number=11, + optional=True, + ) + + +class FreeShippingThreshold(proto.Message): + r"""Conditions to be met for a product to have free shipping. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + country (str): + The `CLDR territory + code `__ + of the country to which an item will ship. + + This field is a member of `oneof`_ ``_country``. + price_threshold (google.shopping.type.types.Price): + The minimum product price for the shipping + cost to become free. Represented as a number. + + This field is a member of `oneof`_ ``_price_threshold``. + """ + + country: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + price_threshold: types.Price = proto.Field( + proto.MESSAGE, + number=2, + optional=True, + message=types.Price, + ) + + +class ProductDetail(proto.Message): + r"""The product details. + + Attributes: + section_name (str): + The section header used to group a set of + product details. + attribute_name (str): + The name of the product detail. + attribute_value (str): + The value of the product detail. + """ + + section_name: str = proto.Field( + proto.STRING, + number=1, + ) + attribute_name: str = proto.Field( + proto.STRING, + number=2, + ) + attribute_value: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ProductCertification(proto.Message): + r"""Product + `certification `__, + initially introduced for EU energy efficiency labeling compliance + using the EU EPREL database. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + certification_authority (google.shopping.merchant_products_v1.types.CertificationAuthority): + The certification authority. + + This field is a member of `oneof`_ ``_certification_authority``. + certification_name (google.shopping.merchant_products_v1.types.CertificationName): + The name of the certification. + + This field is a member of `oneof`_ ``_certification_name``. + certification_code (str): + The certification code. + Maximum length is 2000 characters. + + This field is a member of `oneof`_ ``_certification_code``. + certification_value (str): + The certification value (also known as class, + level or grade), for example "A+", "C", "gold". + Maximum length is 2000 characters. + + This field is a member of `oneof`_ ``_certification_value``. + """ + + certification_authority: 'CertificationAuthority' = proto.Field( + proto.ENUM, + number=1, + optional=True, + enum='CertificationAuthority', + ) + certification_name: 'CertificationName' = proto.Field( + proto.ENUM, + number=2, + optional=True, + enum='CertificationName', + ) + certification_code: str = proto.Field( + proto.STRING, + number=3, + optional=True, + ) + certification_value: str = proto.Field( + proto.STRING, + number=4, + optional=True, + ) + + +class StructuredTitle(proto.Message): + r"""Structured title, for algorithmically (AI)-generated titles. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + digital_source_type (google.shopping.merchant_products_v1.types.DigitalSourceType): + The digital source type. Following + `IPTC `__. + + This field is a member of `oneof`_ ``_digital_source_type``. + content (str): + The title text + Maximum length is 150 characters + + This field is a member of `oneof`_ ``_content``. + """ + + digital_source_type: 'DigitalSourceType' = proto.Field( + proto.ENUM, + number=1, + optional=True, + enum='DigitalSourceType', + ) + content: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + + +class StructuredDescription(proto.Message): + r"""Structured description, for algorithmically (AI)-generated + descriptions. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + digital_source_type (google.shopping.merchant_products_v1.types.DigitalSourceType): + The digital source type. Following + `IPTC `__. + + This field is a member of `oneof`_ ``_digital_source_type``. + content (str): + The description text + Maximum length is 5000 characters + + This field is a member of `oneof`_ ``_content``. + """ + + digital_source_type: 'DigitalSourceType' = proto.Field( + proto.ENUM, + number=1, + optional=True, + enum='DigitalSourceType', + ) + content: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + + +class ProductDimension(proto.Message): + r"""The dimension of the product. + + Attributes: + value (float): + Required. The dimension value represented as + a number. The value can have a maximum precision + of four decimal places. + unit (str): + Required. The dimension units. Acceptable values are: + + - "``in``" + - "``cm``". + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ProductWeight(proto.Message): + r"""The weight of the product. + + Attributes: + value (float): + Required. The weight represented as a number. + The weight can have a maximum precision of four + decimal places. + unit (str): + Required. The weight unit. Acceptable values are: + + - "``g``" + - "``kg``" + - "``oz``" + - "``lb``". + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ProductStatus(proto.Message): + r"""The status of a product, data validation issues, that is, + information about a product computed asynchronously. + + Attributes: + destination_statuses (MutableSequence[google.shopping.merchant_products_v1.types.ProductStatus.DestinationStatus]): + The intended destinations for the product. + item_level_issues (MutableSequence[google.shopping.merchant_products_v1.types.ProductStatus.ItemLevelIssue]): + A list of all issues associated with the + product. + creation_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item has been created, in `ISO + 8601 `__ format. + last_update_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item has been last updated, in `ISO + 8601 `__ format. + google_expiration_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item expires, in `ISO + 8601 `__ format. + """ + + class DestinationStatus(proto.Message): + r"""The destination status of the product status. + + Attributes: + reporting_context (google.shopping.type.types.ReportingContext.ReportingContextEnum): + The name of the reporting context. + approved_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where the offer is approved. + pending_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where the offer is pending approval. + disapproved_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where the offer is disapproved. + """ + + reporting_context: types.ReportingContext.ReportingContextEnum = proto.Field( + proto.ENUM, + number=1, + enum=types.ReportingContext.ReportingContextEnum, + ) + approved_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + pending_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=3, + ) + disapproved_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=4, + ) + + class ItemLevelIssue(proto.Message): + r"""The ItemLevelIssue of the product status. + + Attributes: + code (str): + The error code of the issue. + severity (google.shopping.merchant_products_v1.types.ProductStatus.ItemLevelIssue.Severity): + How this issue affects serving of the offer. + resolution (str): + Whether the issue can be resolved by the + business. + attribute (str): + The attribute's name, if the issue is caused + by a single attribute. + reporting_context (google.shopping.type.types.ReportingContext.ReportingContextEnum): + The reporting context the issue applies to. + description (str): + A short issue description in English. + detail (str): + A detailed issue description in English. + documentation (str): + The URL of a web page to help with resolving + this issue. + applicable_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where issue applies to the offer. + """ + class Severity(proto.Enum): + r"""How the issue affects the serving of the product. + + Values: + SEVERITY_UNSPECIFIED (0): + Not specified. + NOT_IMPACTED (1): + This issue represents a warning and does not + have a direct affect on the product. + DEMOTED (2): + The product is demoted and most likely have + limited performance in search results + DISAPPROVED (3): + Issue disapproves the product. + """ + SEVERITY_UNSPECIFIED = 0 + NOT_IMPACTED = 1 + DEMOTED = 2 + DISAPPROVED = 3 + + code: str = proto.Field( + proto.STRING, + number=1, + ) + severity: 'ProductStatus.ItemLevelIssue.Severity' = proto.Field( + proto.ENUM, + number=2, + enum='ProductStatus.ItemLevelIssue.Severity', + ) + resolution: str = proto.Field( + proto.STRING, + number=3, + ) + attribute: str = proto.Field( + proto.STRING, + number=4, + ) + reporting_context: types.ReportingContext.ReportingContextEnum = proto.Field( + proto.ENUM, + number=5, + enum=types.ReportingContext.ReportingContextEnum, + ) + description: str = proto.Field( + proto.STRING, + number=6, + ) + detail: str = proto.Field( + proto.STRING, + number=7, + ) + documentation: str = proto.Field( + proto.STRING, + number=8, + ) + applicable_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=9, + ) + + destination_statuses: MutableSequence[DestinationStatus] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=DestinationStatus, + ) + item_level_issues: MutableSequence[ItemLevelIssue] = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=ItemLevelIssue, + ) + creation_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + last_update_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + google_expiration_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + + +class CloudExportAdditionalProperties(proto.Message): + r"""Product property for the Cloud Retail API. + For example, properties for a TV product could be + "Screen-Resolution" or "Screen-Size". + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + property_name (str): + Name of the given property. For example, + "Screen-Resolution" for a TV product. Maximum + string size is 256 characters. + + This field is a member of `oneof`_ ``_property_name``. + text_value (MutableSequence[str]): + Text value of the given property. For + example, "8K(UHD)" could be a text value for a + TV product. Maximum repeatedness of this value + is 400. Values are stored in an arbitrary but + consistent order. Maximum string size is 256 + characters. + bool_value (bool): + Boolean value of the given property. For + example for a TV product, "True" or "False" if + the screen is UHD. + + This field is a member of `oneof`_ ``_bool_value``. + int_value (MutableSequence[int]): + Integer values of the given property. For + example, 1080 for a TV product's Screen + Resolution. Maximum repeatedness of this value + is 400. Values are stored in an arbitrary but + consistent order. + float_value (MutableSequence[float]): + Float values of the given property. For + example for a TV product 1.2345. Maximum + repeatedness of this value is 400. Values are + stored in an arbitrary but consistent order. + min_value (float): + Minimum float value of the given property. + For example for a TV product 1.00. + + This field is a member of `oneof`_ ``_min_value``. + max_value (float): + Maximum float value of the given property. + For example for a TV product 100.00. + + This field is a member of `oneof`_ ``_max_value``. + unit_code (str): + Unit of the given property. For example, + "Pixels" for a TV product. Maximum string size + is 256B. + + This field is a member of `oneof`_ ``_unit_code``. + """ + + property_name: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + text_value: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + bool_value: bool = proto.Field( + proto.BOOL, + number=3, + optional=True, + ) + int_value: MutableSequence[int] = proto.RepeatedField( + proto.INT64, + number=4, + ) + float_value: MutableSequence[float] = proto.RepeatedField( + proto.FLOAT, + number=5, + ) + min_value: float = proto.Field( + proto.FLOAT, + number=6, + optional=True, + ) + max_value: float = proto.Field( + proto.FLOAT, + number=7, + optional=True, + ) + unit_code: str = proto.Field( + proto.STRING, + number=8, + optional=True, + ) + + +class ProductSustainabilityIncentive(proto.Message): + r"""Information regarding sustainability-related incentive + programs such as rebates or tax relief. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + amount (google.shopping.type.types.Price): + The fixed amount of the incentive. + + This field is a member of `oneof`_ ``value``. + percentage (float): + The percentage of the sale price that the + incentive is applied to. + + This field is a member of `oneof`_ ``value``. + type_ (google.shopping.merchant_products_v1.types.ProductSustainabilityIncentive.Type): + Sustainability incentive program. + + This field is a member of `oneof`_ ``_type``. + """ + class Type(proto.Enum): + r"""Types of supported sustainability incentive programs. + + Values: + TYPE_UNSPECIFIED (0): + Unspecified or unknown sustainability + incentive type. + EV_TAX_CREDIT (1): + Program offering tax liability reductions for + electric vehicles and, in some countries, + plug-in hybrids. These reductions can be based + on a specific amount or a percentage of the sale + price. + EV_PRICE_DISCOUNT (2): + A subsidy program, often called an + environmental bonus, provides a purchase grant + for electric vehicles and, in some countries, + plug-in hybrids. The grant amount may be a fixed + sum or a percentage of the sale price. + """ + TYPE_UNSPECIFIED = 0 + EV_TAX_CREDIT = 1 + EV_PRICE_DISCOUNT = 2 + + amount: types.Price = proto.Field( + proto.MESSAGE, + number=2, + oneof='value', + message=types.Price, + ) + percentage: float = proto.Field( + proto.DOUBLE, + number=3, + oneof='value', + ) + type_: Type = proto.Field( + proto.ENUM, + number=1, + optional=True, + enum=Type, + ) + + +class AutomatedDiscounts(proto.Message): + r"""Information regarding Automated Discounts. + + Attributes: + prior_price (google.shopping.type.types.Price): + The price prior to the application of the + first price reduction. Absent if the information + about the prior price of the product is not + available. + prior_price_progressive (google.shopping.type.types.Price): + The price prior to the application of + consecutive price reductions. Absent if the + information about the prior price of the product + is not available. + gad_price (google.shopping.type.types.Price): + The current sale price for products with a price optimized + using Google Automated Discounts (GAD). Absent if the + information about the GAD_price of the product is not + available. + """ + + prior_price: types.Price = proto.Field( + proto.MESSAGE, + number=1, + message=types.Price, + ) + prior_price_progressive: types.Price = proto.Field( + proto.MESSAGE, + number=2, + message=types.Price, + ) + gad_price: types.Price = proto.Field( + proto.MESSAGE, + number=3, + message=types.Price, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini b/owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini new file mode 100644 index 000000000000..574c5aed394b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.7 +namespace_packages = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py b/owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py new file mode 100644 index 000000000000..317670e1652b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py @@ -0,0 +1,591 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import re +import shutil + +from typing import Dict, List +import warnings + +import nox + +BLACK_VERSION = "black[jupyter]==23.7.0" +ISORT_VERSION = "isort==5.11.0" + +LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] + +ALL_PYTHON = [ + "3.7", + "3.8", + "3.9", + "3.10", + "3.11", + "3.12", + "3.13", +] + +DEFAULT_PYTHON_VERSION = ALL_PYTHON[-1] + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = "google-shopping-merchant-products" + +UNIT_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", +] +UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] +UNIT_TEST_DEPENDENCIES: List[str] = [] +UNIT_TEST_EXTRAS: List[str] = [] +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} + +SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "pytest", + "google-cloud-testutils", +] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [] +SYSTEM_TEST_DEPENDENCIES: List[str] = [] +SYSTEM_TEST_EXTRAS: List[str] = [] +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} + +nox.options.sessions = [ + "unit", + "system", + "cover", + "lint", + "lint_setup_py", + "blacken", + "docs", +] + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + + +@nox.session(python=ALL_PYTHON) +def mypy(session): + """Run the type checker.""" + session.install( + "mypy", + "types-requests", + "types-protobuf", + ) + session.install(".") + session.run( + "mypy", + "-p", + "google", + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install("google-cloud-testutils") + session.install(".") + + session.run( + "lower-bound-checker", + "update", + "--package-name", + PACKAGE_NAME, + "--constraints-file", + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install("google-cloud-testutils") + session.install(".") + + session.run( + "lower-bound-checker", + "check", + "--package-name", + PACKAGE_NAME, + "--constraints-file", + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint(session): + """Run linters. + + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", BLACK_VERSION) + session.run( + "black", + "--check", + *LINT_PATHS, + ) + + session.run("flake8", "google", "tests") + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def blacken(session): + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + session.run( + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def format(session): + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run( + "isort", + "--fss", + *LINT_PATHS, + ) + session.run( + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install("setuptools", "docutils", "pygments") + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") + + +def install_unittest_dependencies(session, *constraints): + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, *constraints) + + if UNIT_TEST_EXTERNAL_DEPENDENCIES: + warnings.warn( + "'unit_test_external_dependencies' is deprecated. Instead, please " + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", + DeprecationWarning, + ) + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_LOCAL_DEPENDENCIES: + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_EXTRAS_BY_PYTHON: + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif UNIT_TEST_EXTRAS: + extras = UNIT_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + +@nox.session(python=ALL_PYTHON) +@nox.parametrize( + "protobuf_implementation", + ["python", "upb", "cpp"], +) +def unit(session, protobuf_implementation): + # Install all test dependencies, then install this package in-place. + + if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): + session.skip("cpp implementation is not supported in python 3.11+") + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + install_unittest_dependencies(session, "-c", constraints_path) + + # TODO(https://github.com/googleapis/synthtool/issues/1976): + # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. + # The 'cpp' implementation requires Protobuf<4. + if protobuf_implementation == "cpp": + session.install("protobuf<4") + + # Run py.test against the unit tests. + session.run( + "py.test", + "--quiet", + f"--junitxml=unit_{session.python}_sponge_log.xml", + "--cov=google", + "--cov=tests/unit", + "--cov-append", + "--cov-config=.coveragerc", + "--cov-report=", + "--cov-fail-under=0", + os.path.join("tests", "unit"), + *session.posargs, + env={ + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, + }, + ) + + +def install_systemtest_dependencies(session, *constraints): + session.install("--pre", "grpcio") + + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_LOCAL_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTRAS_BY_PYTHON: + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif SYSTEM_TEST_EXTRAS: + extras = SYSTEM_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + +@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) +def system(session): + """Run the system test suite.""" + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + system_test_path = os.path.join("tests", "system.py") + system_test_folder_path = os.path.join("tests", "system") + + # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. + if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": + session.skip("RUN_SYSTEM_TESTS is set to false, skipping") + # Install pyopenssl for mTLS testing. + if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": + session.install("pyopenssl") + + system_test_exists = os.path.exists(system_test_path) + system_test_folder_exists = os.path.exists(system_test_folder_path) + # Sanity check: only run tests if found. + if not system_test_exists and not system_test_folder_exists: + session.skip("System tests were not found") + + install_systemtest_dependencies(session, "-c", constraints_path) + + # Run py.test against the system tests. + if system_test_exists: + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_path, + *session.posargs, + ) + if system_test_folder_exists: + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_folder_path, + *session.posargs, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def cover(session): + """Run the final coverage report. + + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python="3.10") +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", + "sphinx==4.5.0", + "alabaster", + "recommonmark", + ) + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python="3.10") +def docfx(session): + """Build the docfx yaml files for this library.""" + + session.install("-e", ".") + session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", + "gcp-sphinx-docfx-yaml", + "alabaster", + "recommonmark", + ) + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-T", # show full traceback on exception + "-N", # no colors + "-D", + ( + "extensions=sphinx.ext.autodoc," + "sphinx.ext.autosummary," + "docfx_yaml.extension," + "sphinx.ext.intersphinx," + "sphinx.ext.coverage," + "sphinx.ext.napoleon," + "sphinx.ext.todo," + "sphinx.ext.viewcode," + "recommonmark" + ), + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +@nox.parametrize( + "protobuf_implementation", + ["python", "upb", "cpp"], +) +def prerelease_deps(session, protobuf_implementation): + """ + Run all tests with pre-release versions of dependencies installed + rather than the standard non pre-release versions. + Pre-release versions can be installed using + `pip install --pre `. + """ + + if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): + session.skip("cpp implementation is not supported in python 3.11+") + + # Install all dependencies + session.install("-e", ".") + + # Install dependencies for the unit test environment + unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES + session.install(*unit_deps_all) + + # Install dependencies for the system test environment + system_deps_all = ( + SYSTEM_TEST_STANDARD_DEPENDENCIES + + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + + SYSTEM_TEST_EXTRAS + ) + session.install(*system_deps_all) + + # Because we test minimum dependency versions on the minimum Python + # version, the first version we test with in the unit tests sessions has a + # constraints file containing all dependencies and extras. + with open( + CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", + encoding="utf-8", + ) as constraints_file: + constraints_text = constraints_file.read() + + # Ignore leading whitespace and comment lines. + constraints_deps = [ + match.group(1) + for match in re.finditer( + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE + ) + ] + + # Install dependencies specified in `testing/constraints-X.txt`. + session.install(*constraints_deps) + + # Note: If a dependency is added to the `prerel_deps` list, + # the `core_dependencies_from_source` list in the `core_deps_from_source` + # nox session should also be updated. + prerel_deps = [ + "googleapis-common-protos", + "google-api-core", + "google-auth", + "grpc-google-iam-v1", + "grpcio", + "grpcio-status", + "protobuf", + "proto-plus", + ] + + for dep in prerel_deps: + session.install("--pre", "--no-deps", "--ignore-installed", dep) + # TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status`` + # to the dictionary below once this bug is fixed. + # TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add + # `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below + # once this bug is fixed. + package_namespaces = { + "google-api-core": "google.api_core", + "google-auth": "google.auth", + "grpcio": "grpc", + "protobuf": "google.protobuf", + "proto-plus": "proto", + } + + version_namespace = package_namespaces.get(dep) + + print(f"Installed {dep}") + if version_namespace: + session.run( + "python", + "-c", + f"import {version_namespace}; print({version_namespace}.__version__)", + ) + + session.run( + "py.test", + "tests/unit", + env={ + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, + }, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +@nox.parametrize( + "protobuf_implementation", + ["python", "upb"], +) +def core_deps_from_source(session, protobuf_implementation): + """Run all tests with core dependencies installed from source + rather than pulling the dependencies from PyPI. + """ + + # Install all dependencies + session.install("-e", ".") + + # Install dependencies for the unit test environment + unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES + session.install(*unit_deps_all) + + # Install dependencies for the system test environment + system_deps_all = ( + SYSTEM_TEST_STANDARD_DEPENDENCIES + + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + + SYSTEM_TEST_EXTRAS + ) + session.install(*system_deps_all) + + # Because we test minimum dependency versions on the minimum Python + # version, the first version we test with in the unit tests sessions has a + # constraints file containing all dependencies and extras. + with open( + CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", + encoding="utf-8", + ) as constraints_file: + constraints_text = constraints_file.read() + + # Ignore leading whitespace and comment lines. + constraints_deps = [ + match.group(1) + for match in re.finditer( + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE + ) + ] + + # Install dependencies specified in `testing/constraints-X.txt`. + session.install(*constraints_deps) + + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and + # `grpcio-status` should be added to the list below so that they are installed from source, + # rather than PyPI. + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be + # added to the list below so that it is installed from source, rather than PyPI + # Note: If a dependency is added to the `core_dependencies_from_source` list, + # the `prerel_deps` list in the `prerelease_deps` nox session should also be updated. + core_dependencies_from_source = [ + "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", + "google-api-core @ git+https://github.com/googleapis/python-api-core.git", + "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", + "proto-plus @ git+https://github.com/googleapis/proto-plus-python.git", + ] + + for dep in core_dependencies_from_source: + session.install(dep, "--no-deps", "--ignore-installed") + print(f"Installed {dep}") + + session.run( + "py.test", + "tests/unit", + env={ + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, + }, + ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py new file mode 100644 index 000000000000..06b1ad4f0cb3 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductInputsService_DeleteProductInput_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +async def sample_delete_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + await client.delete_product_input(request=request) + + +# [END merchantapi_v1_generated_ProductInputsService_DeleteProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py new file mode 100644 index 000000000000..5d6a0ff4b1d4 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductInputsService_DeleteProductInput_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +def sample_delete_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + client.delete_product_input(request=request) + + +# [END merchantapi_v1_generated_ProductInputsService_DeleteProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py new file mode 100644 index 000000000000..dd97d9dfc5a5 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for InsertProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductInputsService_InsertProductInput_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +async def sample_insert_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.insert_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1_generated_ProductInputsService_InsertProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py new file mode 100644 index 000000000000..55ef5037c3ea --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for InsertProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductInputsService_InsertProductInput_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +def sample_insert_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.insert_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1_generated_ProductInputsService_InsertProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py new file mode 100644 index 000000000000..5f88aef90bed --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductInputsService_UpdateProductInput_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +async def sample_update_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.update_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1_generated_ProductInputsService_UpdateProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py new file mode 100644 index 000000000000..bd005be7bbff --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductInputsService_UpdateProductInput_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +def sample_update_product_input(): + # Create a client + client = merchant_products_v1.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.update_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1_generated_ProductInputsService_UpdateProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py new file mode 100644 index 000000000000..5a462caa41c2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductsService_GetProduct_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +async def sample_get_product(): + # Create a client + client = merchant_products_v1.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1_generated_ProductsService_GetProduct_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py new file mode 100644 index 000000000000..4e09f3572fe4 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductsService_GetProduct_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +def sample_get_product(): + # Create a client + client = merchant_products_v1.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1_generated_ProductsService_GetProduct_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py new file mode 100644 index 000000000000..dd588cde394b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductsService_ListProducts_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +async def sample_list_products(): + # Create a client + client = merchant_products_v1.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END merchantapi_v1_generated_ProductsService_ListProducts_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py new file mode 100644 index 000000000000..3c8fbda19048 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1_generated_ProductsService_ListProducts_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1 + + +def sample_list_products(): + # Create a client + client = merchant_products_v1.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END merchantapi_v1_generated_ProductsService_ListProducts_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json new file mode 100644 index 000000000000..d4eccf58dc52 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json @@ -0,0 +1,814 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.shopping.merchant.products.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-shopping-merchant-products", + "version": "0.1.0" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceAsyncClient", + "shortName": "ProductInputsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceAsyncClient.delete_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService.DeleteProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "DeleteProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.DeleteProductInputRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "shortName": "delete_product_input" + }, + "description": "Sample for DeleteProductInput", + "file": "merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductInputsService_DeleteProductInput_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceClient", + "shortName": "ProductInputsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceClient.delete_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService.DeleteProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "DeleteProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.DeleteProductInputRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "shortName": "delete_product_input" + }, + "description": "Sample for DeleteProductInput", + "file": "merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductInputsService_DeleteProductInput_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceAsyncClient", + "shortName": "ProductInputsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceAsyncClient.insert_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService.InsertProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "InsertProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.InsertProductInputRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.types.ProductInput", + "shortName": "insert_product_input" + }, + "description": "Sample for InsertProductInput", + "file": "merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductInputsService_InsertProductInput_async", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 52, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 53, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceClient", + "shortName": "ProductInputsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceClient.insert_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService.InsertProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "InsertProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.InsertProductInputRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.types.ProductInput", + "shortName": "insert_product_input" + }, + "description": "Sample for InsertProductInput", + "file": "merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductInputsService_InsertProductInput_sync", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 52, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 53, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceAsyncClient", + "shortName": "ProductInputsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceAsyncClient.update_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService.UpdateProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "UpdateProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.UpdateProductInputRequest" + }, + { + "name": "product_input", + "type": "google.shopping.merchant_products_v1.types.ProductInput" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.types.ProductInput", + "shortName": "update_product_input" + }, + "description": "Sample for UpdateProductInput", + "file": "merchantapi_v1_generated_product_inputs_service_update_product_input_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductInputsService_UpdateProductInput_async", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_product_inputs_service_update_product_input_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceClient", + "shortName": "ProductInputsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductInputsServiceClient.update_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService.UpdateProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "UpdateProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.UpdateProductInputRequest" + }, + { + "name": "product_input", + "type": "google.shopping.merchant_products_v1.types.ProductInput" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.types.ProductInput", + "shortName": "update_product_input" + }, + "description": "Sample for UpdateProductInput", + "file": "merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductInputsService_UpdateProductInput_sync", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductsServiceAsyncClient", + "shortName": "ProductsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductsServiceAsyncClient.get_product", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductsService.GetProduct", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "GetProduct" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.GetProductRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.types.Product", + "shortName": "get_product" + }, + "description": "Sample for GetProduct", + "file": "merchantapi_v1_generated_products_service_get_product_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductsService_GetProduct_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_products_service_get_product_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductsServiceClient", + "shortName": "ProductsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductsServiceClient.get_product", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductsService.GetProduct", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "GetProduct" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.GetProductRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.types.Product", + "shortName": "get_product" + }, + "description": "Sample for GetProduct", + "file": "merchantapi_v1_generated_products_service_get_product_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductsService_GetProduct_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_products_service_get_product_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductsServiceAsyncClient", + "shortName": "ProductsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductsServiceAsyncClient.list_products", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductsService.ListProducts", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "ListProducts" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.ListProductsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.services.products_service.pagers.ListProductsAsyncPager", + "shortName": "list_products" + }, + "description": "Sample for ListProducts", + "file": "merchantapi_v1_generated_products_service_list_products_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductsService_ListProducts_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_products_service_list_products_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1.ProductsServiceClient", + "shortName": "ProductsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1.ProductsServiceClient.list_products", + "method": { + "fullName": "google.shopping.merchant.products.v1.ProductsService.ListProducts", + "service": { + "fullName": "google.shopping.merchant.products.v1.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "ListProducts" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1.types.ListProductsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1.services.products_service.pagers.ListProductsPager", + "shortName": "list_products" + }, + "description": "Sample for ListProducts", + "file": "merchantapi_v1_generated_products_service_list_products_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1_generated_ProductsService_ListProducts_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1_generated_products_service_list_products_sync.py" + } + ] +} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/scripts/fixup_merchant_products_v1_keywords.py b/owl-bot-staging/google-shopping-merchant-products/v1/scripts/fixup_merchant_products_v1_keywords.py new file mode 100644 index 000000000000..da63187314ee --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/scripts/fixup_merchant_products_v1_keywords.py @@ -0,0 +1,180 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class merchant_productsCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'delete_product_input': ('name', 'data_source', ), + 'get_product': ('name', ), + 'insert_product_input': ('parent', 'product_input', 'data_source', ), + 'list_products': ('parent', 'page_size', 'page_token', ), + 'update_product_input': ('product_input', 'data_source', 'update_mask', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: a.keyword.value not in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=merchant_productsCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the merchant_products client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/setup.py b/owl-bot-staging/google-shopping-merchant-products/v1/setup.py new file mode 100644 index 000000000000..d1544a0a16b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/setup.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os +import re + +import setuptools # type: ignore + +package_root = os.path.abspath(os.path.dirname(__file__)) + +name = 'google-shopping-merchant-products' + + +description = "Google Shopping Merchant Products API client library" + +version = None + +with open(os.path.join(package_root, 'google/shopping/merchant_products/gapic_version.py')) as fp: + version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read()) + assert (len(version_candidates) == 1) + version = version_candidates[0] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + +dependencies = [ + "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + # Exclude incompatible versions of `google-auth` + # See https://github.com/googleapis/google-cloud-python/issues/12364 + "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", + "proto-plus >= 1.22.3, <2.0.0", + "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", + "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "google-shopping-type >= 0.1.6, <1.0.0", +] +extras = { +} +url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-shopping-merchant-products" + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, "README.rst") +with io.open(readme_filename, encoding="utf-8") as readme_file: + readme = readme_file.read() + +packages = [ + package + for package in setuptools.find_namespace_packages() + if package.startswith("google") +] + +setuptools.setup( + name=name, + version=version, + description=description, + long_description=readme, + author="Google LLC", + author_email="googleapis-packages@google.com", + license="Apache 2.0", + url=url, + classifiers=[ + release_status, + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Operating System :: OS Independent", + "Topic :: Internet", + ], + platforms="Posix; MacOS X; Windows", + packages=packages, + python_requires=">=3.7", + install_requires=dependencies, + extras_require=extras, + include_package_data=True, + zip_safe=False, +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt new file mode 100644 index 000000000000..0112695e5bbb --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt @@ -0,0 +1,12 @@ +# We use the constraints file for the latest Python version +# (currently this file) to check that the latest +# major versions of dependencies are supported in setup.py. +# List all library dependencies and extras in this file. +# Require the latest major version be installed for each dependency. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# Then this file should have google-cloud-foo>=1 +google-api-core>=2 +google-auth>=2 +proto-plus>=1 +protobuf>=6 +google-shopping-type>=0 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt new file mode 100644 index 000000000000..2af887ec8ba0 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt @@ -0,0 +1,11 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file. +# Pin the version to the lower bound. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.1 +google-auth==2.14.1 +proto-plus==1.22.3 +protobuf==3.20.2 +google-shopping-type==0.1.6 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py new file mode 100644 index 000000000000..5103ab754262 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py @@ -0,0 +1,3573 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable, AsyncIterable +from google.protobuf import json_format +import json +import math +import pytest +from google.api_core import api_core_version +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +try: + from google.auth.aio import credentials as ga_credentials_async + HAS_GOOGLE_AUTH_AIO = True +except ImportError: # pragma: NO COVER + HAS_GOOGLE_AUTH_AIO = False + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.shopping.merchant_products_v1.services.product_inputs_service import ProductInputsServiceAsyncClient +from google.shopping.merchant_products_v1.services.product_inputs_service import ProductInputsServiceClient +from google.shopping.merchant_products_v1.services.product_inputs_service import transports +from google.shopping.merchant_products_v1.types import productinputs +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types +from google.type import interval_pb2 # type: ignore +import google.auth + + + +CRED_INFO_JSON = { + "credential_source": "/path/to/file", + "credential_type": "service account credentials", + "principal": "service-account@example.com", +} +CRED_INFO_STRING = json.dumps(CRED_INFO_JSON) + + +async def mock_async_gen(data, chunk_size=1): + for i in range(0, len(data)): # pragma: NO COVER + chunk = data[i : i + chunk_size] + yield chunk.encode("utf-8") + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + +# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. +# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. +def async_anonymous_credentials(): + if HAS_GOOGLE_AUTH_AIO: + return ga_credentials_async.AnonymousCredentials() + return ga_credentials.AnonymousCredentials() + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + +# If default endpoint template is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint template so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint_template(client): + return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert ProductInputsServiceClient._get_default_mtls_endpoint(None) is None + assert ProductInputsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + +def test__read_environment_variables(): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ProductInputsServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + ProductInputsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductInputsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", "foo.com") + +def test__get_client_cert_source(): + mock_provided_cert_source = mock.Mock() + mock_default_cert_source = mock.Mock() + + assert ProductInputsServiceClient._get_client_cert_source(None, False) is None + assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None + assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source + + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): + assert ProductInputsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source + assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source + +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + assert ProductInputsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override + assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint + assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductInputsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint + assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint + + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") + assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." + + +def test__get_universe_domain(): + client_universe_domain = "foo.com" + universe_domain_env = "bar.com" + + assert ProductInputsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain + assert ProductInputsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env + assert ProductInputsServiceClient._get_universe_domain(None, None) == ProductInputsServiceClient._DEFAULT_UNIVERSE + + with pytest.raises(ValueError) as excinfo: + ProductInputsServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + +@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ + (401, CRED_INFO_JSON, True), + (403, CRED_INFO_JSON, True), + (404, CRED_INFO_JSON, True), + (500, CRED_INFO_JSON, False), + (401, None, False), + (403, None, False), + (404, None, False), + (500, None, False) +]) +def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): + cred = mock.Mock(["get_cred_info"]) + cred.get_cred_info = mock.Mock(return_value=cred_info_json) + client = ProductInputsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=["foo"]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + if show_cred_info: + assert error.details == ["foo", CRED_INFO_STRING] + else: + assert error.details == ["foo"] + +@pytest.mark.parametrize("error_code", [401,403,404,500]) +def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): + cred = mock.Mock([]) + assert not hasattr(cred, "get_cred_info") + client = ProductInputsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=[]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + assert error.details == [] + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductInputsServiceClient, "grpc"), + (ProductInputsServiceAsyncClient, "grpc_asyncio"), + (ProductInputsServiceClient, "rest"), +]) +def test_product_inputs_service_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductInputsServiceGrpcTransport, "grpc"), + (transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.ProductInputsServiceRestTransport, "rest"), +]) +def test_product_inputs_service_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductInputsServiceClient, "grpc"), + (ProductInputsServiceAsyncClient, "grpc_asyncio"), + (ProductInputsServiceClient, "rest"), +]) +def test_product_inputs_service_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +def test_product_inputs_service_client_get_transport_class(): + transport = ProductInputsServiceClient.get_transport_class() + available_transports = [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceRestTransport, + ] + assert transport in available_transports + + transport = ProductInputsServiceClient.get_transport_class("grpc") + assert transport == transports.ProductInputsServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), +]) +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +def test_product_inputs_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "true"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "false"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "true"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "false"), +]) +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_product_inputs_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + ProductInputsServiceClient, ProductInputsServiceAsyncClient +]) +@mock.patch.object(ProductInputsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceAsyncClient)) +def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + +@pytest.mark.parametrize("client_class", [ + ProductInputsServiceClient, ProductInputsServiceAsyncClient +]) +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +def test_product_inputs_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", + # use ClientOptions.api_endpoint as the api endpoint regardless. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == api_override + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", + # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + + # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), + # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, + # and ClientOptions.universe_domain="bar.com", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. + options = client_options.ClientOptions() + universe_exists = hasattr(options, "universe_domain") + if universe_exists: + options = client_options.ClientOptions(universe_domain=mock_universe) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + else: + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) + assert client.universe_domain == (mock_universe if universe_exists else default_universe) + + # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + options = client_options.ClientOptions() + if hasattr(options, "universe_domain"): + delattr(options, "universe_domain") + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), +]) +def test_product_inputs_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", None), +]) +def test_product_inputs_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_product_inputs_service_client_client_options_from_dict(): + with mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductInputsServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_product_inputs_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=None, + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + productinputs.InsertProductInputRequest, + dict, +]) +def test_insert_product_input(request_type, transport: str = 'grpc'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + response = client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = productinputs.InsertProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +def test_insert_product_input_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = productinputs.InsertProductInputRequest( + parent='parent_value', + data_source='data_source_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.insert_product_input(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == productinputs.InsertProductInputRequest( + parent='parent_value', + data_source='data_source_value', + ) + +def test_insert_product_input_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.insert_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc + request = {} + client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.insert_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_insert_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.insert_product_input in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.insert_product_input] = mock_rpc + + request = {} + await client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.insert_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_insert_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.InsertProductInputRequest): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + response = await client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = productinputs.InsertProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.asyncio +async def test_insert_product_input_async_from_dict(): + await test_insert_product_input_async(request_type=dict) + +def test_insert_product_input_field_headers(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.InsertProductInputRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_insert_product_input_field_headers_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.InsertProductInputRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + await client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + productinputs.UpdateProductInputRequest, + dict, +]) +def test_update_product_input(request_type, transport: str = 'grpc'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + response = client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = productinputs.UpdateProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +def test_update_product_input_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = productinputs.UpdateProductInputRequest( + data_source='data_source_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.update_product_input(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == productinputs.UpdateProductInputRequest( + data_source='data_source_value', + ) + +def test_update_product_input_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc + request = {} + client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.update_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_update_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.update_product_input in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.update_product_input] = mock_rpc + + request = {} + await client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.update_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_update_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.UpdateProductInputRequest): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + response = await client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = productinputs.UpdateProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.asyncio +async def test_update_product_input_async_from_dict(): + await test_update_product_input_async(request_type=dict) + +def test_update_product_input_field_headers(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.UpdateProductInputRequest() + + request.product_input.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'product_input.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_input_field_headers_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.UpdateProductInputRequest() + + request.product_input.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + await client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'product_input.name=name_value', + ) in kw['metadata'] + + +def test_update_product_input_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product_input( + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].product_input + mock_val = productinputs.ProductInput(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + + +def test_update_product_input_flattened_error(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_product_input( + productinputs.UpdateProductInputRequest(), + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + +@pytest.mark.asyncio +async def test_update_product_input_flattened_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product_input( + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].product_input + mock_val = productinputs.ProductInput(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_product_input_flattened_error_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_product_input( + productinputs.UpdateProductInputRequest(), + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.parametrize("request_type", [ + productinputs.DeleteProductInputRequest, + dict, +]) +def test_delete_product_input(request_type, transport: str = 'grpc'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = productinputs.DeleteProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_input_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = productinputs.DeleteProductInputRequest( + name='name_value', + data_source='data_source_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.delete_product_input(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == productinputs.DeleteProductInputRequest( + name='name_value', + data_source='data_source_value', + ) + +def test_delete_product_input_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc + request = {} + client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.delete_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_delete_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.delete_product_input in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.delete_product_input] = mock_rpc + + request = {} + await client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.delete_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_delete_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.DeleteProductInputRequest): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = productinputs.DeleteProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_input_async_from_dict(): + await test_delete_product_input_async(request_type=dict) + +def test_delete_product_input_field_headers(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.DeleteProductInputRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value = None + client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_product_input_field_headers_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.DeleteProductInputRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_delete_product_input_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product_input( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_delete_product_input_flattened_error(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_product_input( + productinputs.DeleteProductInputRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_delete_product_input_flattened_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product_input( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_delete_product_input_flattened_error_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_product_input( + productinputs.DeleteProductInputRequest(), + name='name_value', + ) + + +def test_insert_product_input_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.insert_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc + + request = {} + client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.insert_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_insert_product_input_rest_required_fields(request_type=productinputs.InsertProductInputRequest): + transport_class = transports.ProductInputsServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["data_source"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "dataSource" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == request_init["data_source"] + + jsonified_request["parent"] = 'parent_value' + jsonified_request["dataSource"] = 'data_source_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("data_source", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == 'data_source_value' + + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.insert_product_input(request) + + expected_params = [ + ( + "dataSource", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_insert_product_input_rest_unset_required_fields(): + transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.insert_product_input._get_unset_required_fields({}) + assert set(unset_fields) == (set(("dataSource", )) & set(("parent", "productInput", "dataSource", ))) + + +def test_update_product_input_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc + + request = {} + client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.update_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_update_product_input_rest_required_fields(request_type=productinputs.UpdateProductInputRequest): + transport_class = transports.ProductInputsServiceRestTransport + + request_init = {} + request_init["data_source"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "dataSource" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == request_init["data_source"] + + jsonified_request["dataSource"] = 'data_source_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("data_source", "update_mask", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == 'data_source_value' + + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_product_input(request) + + expected_params = [ + ( + "dataSource", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_product_input_rest_unset_required_fields(): + transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_product_input._get_unset_required_fields({}) + assert set(unset_fields) == (set(("dataSource", "updateMask", )) & set(("productInput", "dataSource", ))) + + +def test_update_product_input_rest_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput() + + # get arguments that satisfy an http rule for this method + sample_request = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + + # get truthy value for each flattened field + mock_args = dict( + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_product_input(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1/{product_input.name=accounts/*/productInputs/*}" % client.transport._host, args[1]) + + +def test_update_product_input_rest_flattened_error(transport: str = 'rest'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_product_input( + productinputs.UpdateProductInputRequest(), + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product_input_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc + + request = {} + client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.delete_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_product_input_rest_required_fields(request_type=productinputs.DeleteProductInputRequest): + transport_class = transports.ProductInputsServiceRestTransport + + request_init = {} + request_init["name"] = "" + request_init["data_source"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "dataSource" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == request_init["data_source"] + + jsonified_request["name"] = 'name_value' + jsonified_request["dataSource"] = 'data_source_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("data_source", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == 'data_source_value' + + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_product_input(request) + + expected_params = [ + ( + "dataSource", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_delete_product_input_rest_unset_required_fields(): + transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.delete_product_input._get_unset_required_fields({}) + assert set(unset_fields) == (set(("dataSource", )) & set(("name", "dataSource", ))) + + +def test_delete_product_input_rest_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'accounts/sample1/productInputs/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_product_input(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1/{name=accounts/*/productInputs/*}" % client.transport._host, args[1]) + + +def test_delete_product_input_rest_flattened_error(transport: str = 'rest'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_product_input( + productinputs.DeleteProductInputRequest(), + name='name_value', + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductInputsServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductInputsServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + transports.ProductInputsServiceRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_kind_grpc(): + transport = ProductInputsServiceClient.get_transport_class("grpc")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "grpc" + + +def test_initialize_client_w_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_insert_product_input_empty_call_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.insert_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.InsertProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_product_input_empty_call_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.update_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.UpdateProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_product_input_empty_call_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value = None + client.delete_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.DeleteProductInputRequest() + + assert args[0] == request_msg + + +def test_transport_kind_grpc_asyncio(): + transport = ProductInputsServiceAsyncClient.get_transport_class("grpc_asyncio")( + credentials=async_anonymous_credentials() + ) + assert transport.kind == "grpc_asyncio" + + +def test_initialize_client_w_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_insert_product_input_empty_call_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + await client.insert_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.InsertProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_product_input_empty_call_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + await client.update_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.UpdateProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_product_input_empty_call_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.DeleteProductInputRequest() + + assert args[0] == request_msg + + +def test_transport_kind_rest(): + transport = ProductInputsServiceClient.get_transport_class("rest")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "rest" + + +def test_insert_product_input_rest_bad_request(request_type=productinputs.InsertProductInputRequest): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.insert_product_input(request) + + +@pytest.mark.parametrize("request_type", [ + productinputs.InsertProductInputRequest, + dict, +]) +def test_insert_product_input_rest_call_success(request_type): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request_init["product_input"] = {'name': 'name_value', 'product': 'product_value', 'legacy_local': True, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'product_attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 1, 'availability': 1, 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 1, 'gender': 1, 'google_product_category': 'google_product_category_value', 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 1}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 1, 'size_types': [1], 'energy_efficiency_class': 1, 'min_energy_efficiency_class': 1, 'max_energy_efficiency_class': 1, 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 1, 'pickup_sla': 1, 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': [1], 'excluded_destinations': [1], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 1, 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 1, 'certification_name': 1, 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 1, 'content': 'content_value'}, 'structured_description': {'digital_source_type': 1, 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = productinputs.InsertProductInputRequest.meta.fields["product_input"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["product_input"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + {"field": field, "subfield": subfield, "is_repeated": is_repeated} + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["product_input"][field])): + del request_init["product_input"][field][i][subfield] + else: + del request_init["product_input"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.insert_product_input(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_insert_product_input_rest_interceptors(null_interceptor): + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), + ) + client = ProductInputsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input") as post, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_insert_product_input") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = productinputs.InsertProductInputRequest.pb(productinputs.InsertProductInputRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = productinputs.ProductInput.to_json(productinputs.ProductInput()) + req.return_value.content = return_value + + request = productinputs.InsertProductInputRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = productinputs.ProductInput() + post_with_metadata.return_value = productinputs.ProductInput(), metadata + + client.insert_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_update_product_input_rest_bad_request(request_type=productinputs.UpdateProductInputRequest): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_product_input(request) + + +@pytest.mark.parametrize("request_type", [ + productinputs.UpdateProductInputRequest, + dict, +]) +def test_update_product_input_rest_call_success(request_type): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + request_init["product_input"] = {'name': 'accounts/sample1/productInputs/sample2', 'product': 'product_value', 'legacy_local': True, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'product_attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 1, 'availability': 1, 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 1, 'gender': 1, 'google_product_category': 'google_product_category_value', 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 1}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 1, 'size_types': [1], 'energy_efficiency_class': 1, 'min_energy_efficiency_class': 1, 'max_energy_efficiency_class': 1, 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 1, 'pickup_sla': 1, 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': [1], 'excluded_destinations': [1], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 1, 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 1, 'certification_name': 1, 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 1, 'content': 'content_value'}, 'structured_description': {'digital_source_type': 1, 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = productinputs.UpdateProductInputRequest.meta.fields["product_input"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["product_input"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + {"field": field, "subfield": subfield, "is_repeated": is_repeated} + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["product_input"][field])): + del request_init["product_input"][field][i][subfield] + else: + del request_init["product_input"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_product_input(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_product_input_rest_interceptors(null_interceptor): + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), + ) + client = ProductInputsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input") as post, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_update_product_input") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = productinputs.UpdateProductInputRequest.pb(productinputs.UpdateProductInputRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = productinputs.ProductInput.to_json(productinputs.ProductInput()) + req.return_value.content = return_value + + request = productinputs.UpdateProductInputRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = productinputs.ProductInput() + post_with_metadata.return_value = productinputs.ProductInput(), metadata + + client.update_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_delete_product_input_rest_bad_request(request_type=productinputs.DeleteProductInputRequest): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/productInputs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_product_input(request) + + +@pytest.mark.parametrize("request_type", [ + productinputs.DeleteProductInputRequest, + dict, +]) +def test_delete_product_input_rest_call_success(request_type): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/productInputs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = '' + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_product_input(request) + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_product_input_rest_interceptors(null_interceptor): + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), + ) + client = ProductInputsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_delete_product_input") as pre: + pre.assert_not_called() + pb_message = productinputs.DeleteProductInputRequest.pb(productinputs.DeleteProductInputRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + request = productinputs.DeleteProductInputRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + +def test_initialize_client_w_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_insert_product_input_empty_call_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + client.insert_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.InsertProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_product_input_empty_call_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + client.update_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.UpdateProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_product_input_empty_call_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + client.delete_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.DeleteProductInputRequest() + + assert args[0] == request_msg + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductInputsServiceGrpcTransport, + ) + +def test_product_inputs_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductInputsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_product_inputs_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductInputsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'insert_product_input', + 'update_product_input', + 'delete_product_input', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_product_inputs_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductInputsServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id="octopus", + ) + + +def test_product_inputs_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductInputsServiceTransport() + adc.assert_called_once() + + +def test_product_inputs_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ProductInputsServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + ], +) +def test_product_inputs_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/content',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + transports.ProductInputsServiceRestTransport, + ], +) +def test_product_inputs_service_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductInputsServiceGrpcTransport, grpc_helpers), + (transports.ProductInputsServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_product_inputs_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=["1", "2"], + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +def test_product_inputs_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_product_inputs_service_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.ProductInputsServiceRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_product_inputs_service_host_no_port(transport_name): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_product_inputs_service_host_with_port(transport_name): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_product_inputs_service_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = ProductInputsServiceClient( + credentials=creds1, + transport=transport_name, + ) + client2 = ProductInputsServiceClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.insert_product_input._session + session2 = client2.transport.insert_product_input._session + assert session1 != session2 + session1 = client1.transport.update_product_input._session + session2 = client2.transport.update_product_input._session + assert session1 != session2 + session1 = client1.transport.delete_product_input._session + session2 = client2.transport.delete_product_input._session + assert session1 != session2 +def test_product_inputs_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductInputsServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_product_inputs_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductInputsServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +def test_product_inputs_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +def test_product_inputs_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_product_path(): + account = "squid" + product = "clam" + expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) + actual = ProductInputsServiceClient.product_path(account, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "account": "whelk", + "product": "octopus", + } + path = ProductInputsServiceClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_product_path(path) + assert expected == actual + +def test_product_input_path(): + account = "oyster" + productinput = "nudibranch" + expected = "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) + actual = ProductInputsServiceClient.product_input_path(account, productinput) + assert expected == actual + + +def test_parse_product_input_path(): + expected = { + "account": "cuttlefish", + "productinput": "mussel", + } + path = ProductInputsServiceClient.product_input_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_product_input_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductInputsServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = ProductInputsServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductInputsServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = ProductInputsServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductInputsServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = ProductInputsServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format(project=project, ) + actual = ProductInputsServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = ProductInputsServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductInputsServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = ProductInputsServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductInputsServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +def test_transport_close_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +@pytest.mark.asyncio +async def test_transport_close_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py new file mode 100644 index 000000000000..63ae6fc1b949 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py @@ -0,0 +1,3099 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable, AsyncIterable +from google.protobuf import json_format +import json +import math +import pytest +from google.api_core import api_core_version +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +try: + from google.auth.aio import credentials as ga_credentials_async + HAS_GOOGLE_AUTH_AIO = True +except ImportError: # pragma: NO COVER + HAS_GOOGLE_AUTH_AIO = False + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.oauth2 import service_account +from google.shopping.merchant_products_v1.services.products_service import ProductsServiceAsyncClient +from google.shopping.merchant_products_v1.services.products_service import ProductsServiceClient +from google.shopping.merchant_products_v1.services.products_service import pagers +from google.shopping.merchant_products_v1.services.products_service import transports +from google.shopping.merchant_products_v1.types import products +from google.shopping.merchant_products_v1.types import products_common +from google.shopping.type.types import types +import google.auth + + + +CRED_INFO_JSON = { + "credential_source": "/path/to/file", + "credential_type": "service account credentials", + "principal": "service-account@example.com", +} +CRED_INFO_STRING = json.dumps(CRED_INFO_JSON) + + +async def mock_async_gen(data, chunk_size=1): + for i in range(0, len(data)): # pragma: NO COVER + chunk = data[i : i + chunk_size] + yield chunk.encode("utf-8") + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + +# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. +# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. +def async_anonymous_credentials(): + if HAS_GOOGLE_AUTH_AIO: + return ga_credentials_async.AnonymousCredentials() + return ga_credentials.AnonymousCredentials() + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + +# If default endpoint template is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint template so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint_template(client): + return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert ProductsServiceClient._get_default_mtls_endpoint(None) is None + assert ProductsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + +def test__read_environment_variables(): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ProductsServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + ProductsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + assert ProductsServiceClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ProductsServiceClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", "foo.com") + +def test__get_client_cert_source(): + mock_provided_cert_source = mock.Mock() + mock_default_cert_source = mock.Mock() + + assert ProductsServiceClient._get_client_cert_source(None, False) is None + assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None + assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source + + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): + assert ProductsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source + assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source + +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ProductsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + assert ProductsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override + assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint + assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint + assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint + + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") + assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." + + +def test__get_universe_domain(): + client_universe_domain = "foo.com" + universe_domain_env = "bar.com" + + assert ProductsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain + assert ProductsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env + assert ProductsServiceClient._get_universe_domain(None, None) == ProductsServiceClient._DEFAULT_UNIVERSE + + with pytest.raises(ValueError) as excinfo: + ProductsServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + +@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ + (401, CRED_INFO_JSON, True), + (403, CRED_INFO_JSON, True), + (404, CRED_INFO_JSON, True), + (500, CRED_INFO_JSON, False), + (401, None, False), + (403, None, False), + (404, None, False), + (500, None, False) +]) +def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): + cred = mock.Mock(["get_cred_info"]) + cred.get_cred_info = mock.Mock(return_value=cred_info_json) + client = ProductsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=["foo"]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + if show_cred_info: + assert error.details == ["foo", CRED_INFO_STRING] + else: + assert error.details == ["foo"] + +@pytest.mark.parametrize("error_code", [401,403,404,500]) +def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): + cred = mock.Mock([]) + assert not hasattr(cred, "get_cred_info") + client = ProductsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=[]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + assert error.details == [] + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductsServiceClient, "grpc"), + (ProductsServiceAsyncClient, "grpc_asyncio"), + (ProductsServiceClient, "rest"), +]) +def test_products_service_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductsServiceGrpcTransport, "grpc"), + (transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.ProductsServiceRestTransport, "rest"), +]) +def test_products_service_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductsServiceClient, "grpc"), + (ProductsServiceAsyncClient, "grpc_asyncio"), + (ProductsServiceClient, "rest"), +]) +def test_products_service_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +def test_products_service_client_get_transport_class(): + transport = ProductsServiceClient.get_transport_class() + available_transports = [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceRestTransport, + ] + assert transport in available_transports + + transport = ProductsServiceClient.get_transport_class("grpc") + assert transport == transports.ProductsServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), +]) +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +def test_products_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "true"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "false"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "true"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "false"), +]) +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_products_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + ProductsServiceClient, ProductsServiceAsyncClient +]) +@mock.patch.object(ProductsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceAsyncClient)) +def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + +@pytest.mark.parametrize("client_class", [ + ProductsServiceClient, ProductsServiceAsyncClient +]) +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +def test_products_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ProductsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", + # use ClientOptions.api_endpoint as the api endpoint regardless. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == api_override + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", + # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + + # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), + # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, + # and ClientOptions.universe_domain="bar.com", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. + options = client_options.ClientOptions() + universe_exists = hasattr(options, "universe_domain") + if universe_exists: + options = client_options.ClientOptions(universe_domain=mock_universe) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + else: + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) + assert client.universe_domain == (mock_universe if universe_exists else default_universe) + + # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + options = client_options.ClientOptions() + if hasattr(options, "universe_domain"): + delattr(options, "universe_domain") + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), +]) +def test_products_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", None), +]) +def test_products_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_products_service_client_client_options_from_dict(): + with mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductsServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_products_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=None, + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + products.GetProductRequest, + dict, +]) +def test_get_product(request_type, transport: str = 'grpc'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.Product( + name='name_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + ) + response = client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = products.GetProductRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, products.Product) + assert response.name == 'name_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.data_source == 'data_source_value' + assert response.version_number == 1518 + + +def test_get_product_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = products.GetProductRequest( + name='name_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.get_product(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == products.GetProductRequest( + name='name_value', + ) + +def test_get_product_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_product in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.get_product] = mock_rpc + request = {} + client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_product(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_get_product_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.get_product in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.get_product] = mock_rpc + + request = {} + await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.get_product(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=products.GetProductRequest): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.Product( + name='name_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + )) + response = await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = products.GetProductRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, products.Product) + assert response.name == 'name_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.data_source == 'data_source_value' + assert response.version_number == 1518 + + +@pytest.mark.asyncio +async def test_get_product_async_from_dict(): + await test_get_product_async(request_type=dict) + +def test_get_product_field_headers(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.GetProductRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = products.Product() + client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_product_field_headers_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.GetProductRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) + await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_product_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_product_flattened_error(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_product( + products.GetProductRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_product_flattened_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_product_flattened_error_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_product( + products.GetProductRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + products.ListProductsRequest, + dict, +]) +def test_list_products(request_type, transport: str = 'grpc'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.ListProductsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = products.ListProductsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = products.ListProductsRequest( + parent='parent_value', + page_token='page_token_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.list_products(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == products.ListProductsRequest( + parent='parent_value', + page_token='page_token_value', + ) + +def test_list_products_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_products in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.list_products] = mock_rpc + request = {} + client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_products(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_list_products_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.list_products in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.list_products] = mock_rpc + + request = {} + await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.list_products(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=products.ListProductsRequest): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = products.ListProductsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_async_from_dict(): + await test_list_products_async(request_type=dict) + +def test_list_products_field_headers(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.ListProductsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = products.ListProductsResponse() + client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_products_field_headers_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.ListProductsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) + await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_products_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.ListProductsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_products_flattened_error(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_products( + products.ListProductsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_products_flattened_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.ListProductsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_products_flattened_error_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_products( + products.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_pager(transport_name: str = "grpc"): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_products(request={}, retry=retry, timeout=timeout) + + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, products.Product) + for i in results) +def test_list_products_pages(transport_name: str = "grpc"): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_products_async_pager(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, products.Product) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_products_async_pages(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_products(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +def test_get_product_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_product in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.get_product] = mock_rpc + + request = {} + client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_product(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_product_rest_required_fields(request_type=products.GetProductRequest): + transport_class = transports.ProductsServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = products.Product() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.Product.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_product(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_product_rest_unset_required_fields(): + transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_product._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +def test_get_product_rest_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.Product() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'accounts/sample1/products/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = products.Product.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_product(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1/{name=accounts/*/products/*}" % client.transport._host, args[1]) + + +def test_get_product_rest_flattened_error(transport: str = 'rest'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_product( + products.GetProductRequest(), + name='name_value', + ) + + +def test_list_products_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_products in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.list_products] = mock_rpc + + request = {} + client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_products(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_products_rest_required_fields(request_type=products.ListProductsRequest): + transport_class = transports.ProductsServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = products.ListProductsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.ListProductsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_products(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_products_rest_unset_required_fields(): + transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_products._get_unset_required_fields({}) + assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) + + +def test_list_products_rest_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.ListProductsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'accounts/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = products.ListProductsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_products(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1/{parent=accounts/*}/products" % client.transport._host, args[1]) + + +def test_list_products_rest_flattened_error(transport: str = 'rest'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_products( + products.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_rest_pager(transport: str = 'rest'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(products.ListProductsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'accounts/sample1'} + + pager = client.list_products(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, products.Product) + for i in results) + + pages = list(client.list_products(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductsServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductsServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + transports.ProductsServiceRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_kind_grpc(): + transport = ProductsServiceClient.get_transport_class("grpc")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "grpc" + + +def test_initialize_client_w_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_product_empty_call_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = products.Product() + client.get_product(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.GetProductRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_products_empty_call_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = products.ListProductsResponse() + client.list_products(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.ListProductsRequest() + + assert args[0] == request_msg + + +def test_transport_kind_grpc_asyncio(): + transport = ProductsServiceAsyncClient.get_transport_class("grpc_asyncio")( + credentials=async_anonymous_credentials() + ) + assert transport.kind == "grpc_asyncio" + + +def test_initialize_client_w_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_product_empty_call_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product( + name='name_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + )) + await client.get_product(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.GetProductRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_products_empty_call_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( + next_page_token='next_page_token_value', + )) + await client.list_products(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.ListProductsRequest() + + assert args[0] == request_msg + + +def test_transport_kind_rest(): + transport = ProductsServiceClient.get_transport_class("rest")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "rest" + + +def test_get_product_rest_bad_request(request_type=products.GetProductRequest): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/products/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_product(request) + + +@pytest.mark.parametrize("request_type", [ + products.GetProductRequest, + dict, +]) +def test_get_product_rest_call_success(request_type): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/products/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.Product( + name='name_value', + legacy_local=True, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.Product.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_product(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, products.Product) + assert response.name == 'name_value' + assert response.legacy_local is True + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.data_source == 'data_source_value' + assert response.version_number == 1518 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_product_rest_interceptors(null_interceptor): + transport = transports.ProductsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), + ) + client = ProductsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product") as post, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_get_product") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = products.GetProductRequest.pb(products.GetProductRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = products.Product.to_json(products.Product()) + req.return_value.content = return_value + + request = products.GetProductRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = products.Product() + post_with_metadata.return_value = products.Product(), metadata + + client.get_product(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_products_rest_bad_request(request_type=products.ListProductsRequest): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_products(request) + + +@pytest.mark.parametrize("request_type", [ + products.ListProductsRequest, + dict, +]) +def test_list_products_rest_call_success(request_type): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.ListProductsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.ListProductsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_products(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_products_rest_interceptors(null_interceptor): + transport = transports.ProductsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), + ) + client = ProductsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products") as post, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_list_products") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = products.ListProductsRequest.pb(products.ListProductsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = products.ListProductsResponse.to_json(products.ListProductsResponse()) + req.return_value.content = return_value + + request = products.ListProductsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = products.ListProductsResponse() + post_with_metadata.return_value = products.ListProductsResponse(), metadata + + client.list_products(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + +def test_initialize_client_w_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_product_empty_call_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + client.get_product(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.GetProductRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_products_empty_call_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + client.list_products(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.ListProductsRequest() + + assert args[0] == request_msg + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductsServiceGrpcTransport, + ) + +def test_products_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_products_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'get_product', + 'list_products', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_products_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductsServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id="octopus", + ) + + +def test_products_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductsServiceTransport() + adc.assert_called_once() + + +def test_products_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ProductsServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + ], +) +def test_products_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/content',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + transports.ProductsServiceRestTransport, + ], +) +def test_products_service_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductsServiceGrpcTransport, grpc_helpers), + (transports.ProductsServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_products_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=["1", "2"], + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +def test_products_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_products_service_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.ProductsServiceRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_products_service_host_no_port(transport_name): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_products_service_host_with_port(transport_name): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_products_service_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = ProductsServiceClient( + credentials=creds1, + transport=transport_name, + ) + client2 = ProductsServiceClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.get_product._session + session2 = client2.transport.get_product._session + assert session1 != session2 + session1 = client1.transport.list_products._session + session2 = client2.transport.list_products._session + assert session1 != session2 +def test_products_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductsServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_products_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductsServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +def test_products_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +def test_products_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_product_path(): + account = "squid" + product = "clam" + expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) + actual = ProductsServiceClient.product_path(account, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "account": "whelk", + "product": "octopus", + } + path = ProductsServiceClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_product_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "oyster" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductsServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nudibranch", + } + path = ProductsServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "cuttlefish" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductsServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "mussel", + } + path = ProductsServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "winkle" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductsServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nautilus", + } + path = ProductsServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "scallop" + expected = "projects/{project}".format(project=project, ) + actual = ProductsServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "abalone", + } + path = ProductsServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "squid" + location = "clam" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductsServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "whelk", + "location": "octopus", + } + path = ProductsServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductsServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +def test_transport_close_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +@pytest.mark.asyncio +async def test_transport_close_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc b/owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc new file mode 100644 index 000000000000..0d94c2da5109 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc @@ -0,0 +1,13 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/shopping/merchant_products/__init__.py + google/shopping/merchant_products/gapic_version.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 b/owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 new file mode 100644 index 000000000000..90316de21489 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +[flake8] +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): +# Resolve flake8 lint issues +ignore = E203, E231, E266, E501, W503 +exclude = + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): + # Ensure that generated code passes flake8 lint + **/gapic/** + **/services/** + **/types/** + # Exclude Protobuf gencode + *_pb2.py + + # Standard linting exemptions. + **/.nox/** + __pycache__, + .git, + *.pyc, + conf.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE b/owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE new file mode 100644 index 000000000000..d64569567334 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in b/owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in new file mode 100644 index 000000000000..dae249ec8976 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +include README.rst LICENSE +recursive-include google *.py *.pyi *.json *.proto py.typed +recursive-include tests * +global-exclude *.py[co] +global-exclude __pycache__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst new file mode 100644 index 000000000000..f80c16dfa082 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst @@ -0,0 +1,143 @@ +Python Client for Google Shopping Merchant Products API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Shopping Merchant Products API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library + + +Logging +------- + +This library uses the standard Python :code:`logging` functionality to log some RPC events that could be of interest for debugging and monitoring purposes. +Note the following: + +#. Logs may contain sensitive information. Take care to **restrict access to the logs** if they are saved, whether it be on local storage or on Google Cloud Logging. +#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**. +#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below. + + +Simple, environment-based configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To enable logging for this library without any changes in your code, set the :code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to a valid Google +logging scope. This configures handling of logging events (at level :code:`logging.DEBUG` or higher) from this library in a default manner, emitting the logged +messages in a structured format. It does not currently allow customizing the logging levels captured nor the handlers, formatters, etc. used for any logging +event. + +A logging scope is a period-separated namespace that begins with :code:`google`, identifying the Python module or package to log. + +- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc. +- Invalid logging scopes: :code:`foo`, :code:`123`, etc. + +**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers. + + +Examples +^^^^^^^^ + +- Enabling the default handler for all Google-based loggers + +.. code-block:: console + + export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google + +- Enabling the default handler for a specific Google module (for a client library called :code:`library_v1`): + +.. code-block:: console + + export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1 + + +Advanced, code-based configuration +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also configure a valid logging scope using Python's standard `logging` mechanism. + + +Examples +^^^^^^^^ + +- Configuring a handler for all Google-based loggers + +.. code-block:: python + + import logging + + from google.cloud.translate_v3 import translate + + base_logger = logging.getLogger("google") + base_logger.addHandler(logging.StreamHandler()) + base_logger.setLevel(logging.DEBUG) + +- Configuring a handler for a specific Google module (for a client library called :code:`library_v1`): + +.. code-block:: python + + import logging + + from google.cloud.translate_v3 import translate + + base_logger = logging.getLogger("google.cloud.library_v1") + base_logger.addHandler(logging.StreamHandler()) + base_logger.setLevel(logging.DEBUG) + + +Logging details +~~~~~~~~~~~~~~~ + +#. Regardless of which of the mechanisms above you use to configure logging for this library, by default logging events are not propagated up to the root + logger from the `google`-level logger. If you need the events to be propagated to the root logger, you must explicitly set + :code:`logging.getLogger("google").propagate = True` in your code. +#. You can mix the different logging configurations above for different Google modules. For example, you may want use a code-based logging configuration for + one library, but decide you need to also set up environment-based logging configuration for another library. + + #. If you attempt to use both code-based and environment-based configuration for the same module, the environment-based configuration will be ineffectual + if the code -based configuration gets applied first. + +#. The Google-specific logging configurations (default handlers for environment-based configuration; not propagating logging events to the root logger) get + executed the first time *any* client library is instantiated in your application, and only if the affected loggers have not been previously configured. + (This is the reason for 2.i. above.) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css new file mode 100644 index 000000000000..b0a295464b23 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css @@ -0,0 +1,20 @@ +div#python2-eol { + border-color: red; + border-width: medium; +} + +/* Ensure minimum width for 'Parameters' / 'Returns' column */ +dl.field-list > dt { + min-width: 100px +} + +/* Insert space between methods for readability */ +dl.method { + padding-top: 10px; + padding-bottom: 10px +} + +/* Insert empty space between classes */ +dl.class { + padding-bottom: 50px +} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html new file mode 100644 index 000000000000..95e9c77fcfe1 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html @@ -0,0 +1,50 @@ + +{% extends "!layout.html" %} +{%- block content %} +{%- if theme_fixed_sidebar|lower == 'true' %} +
+ {{ sidebar() }} + {%- block document %} +
+ {%- if render_sidebar %} +
+ {%- endif %} + + {%- block relbar_top %} + {%- if theme_show_relbar_top|tobool %} + + {%- endif %} + {% endblock %} + +
+
+ As of January 1, 2020 this library no longer supports Python 2 on the latest released version. + Library versions released prior to that date will continue to be available. For more information please + visit Python 2 support on Google Cloud. +
+ {% block body %} {% endblock %} +
+ + {%- block relbar_bottom %} + {%- if theme_show_relbar_bottom|tobool %} + + {%- endif %} + {% endblock %} + + {%- if render_sidebar %} +
+ {%- endif %} +
+ {%- endblock %} +
+
+{%- else %} +{{ super() }} +{%- endif %} +{%- endblock %} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py new file mode 100644 index 000000000000..302daf996542 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py @@ -0,0 +1,385 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-shopping-merchant-products documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +# For plugins that can not read conf.py. +# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 +sys.path.insert(0, os.path.abspath(".")) + +__version__ = "" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "4.5.0" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", + "recommonmark", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_options = {"members": True} +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The root toctree document. +root_doc = "index" + +# General information about the project. +project = u"google-shopping-merchant-products" +copyright = u"2025, Google, LLC" +author = u"Google APIs" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [ + "_build", + "**/.nox/**/*", + "samples/AUTHORING_GUIDE.md", + "samples/CONTRIBUTING.md", + "samples/snippets/README.rst", +] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Shopping Client Libraries for google-shopping-merchant-products", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-shopping-merchant-products-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + root_doc, + "google-shopping-merchant-products.tex", + u"google-shopping-merchant-products Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + root_doc, + "google-shopping-merchant-products", + "google-shopping-merchant-products Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + root_doc, + "google-shopping-merchant-products", + "google-shopping-merchant-products Documentation", + author, + "google-shopping-merchant-products", + "google-shopping-merchant-products Library", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("https://python.readthedocs.org/en/latest/", None), + "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), + "grpc": ("https://grpc.github.io/grpc/python/", None), + "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst new file mode 100644 index 000000000000..eee21402d328 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst @@ -0,0 +1,10 @@ +.. include:: multiprocessing.rst + + +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + merchant_products_v1beta/services_ + merchant_products_v1beta/types_ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst new file mode 100644 index 000000000000..99e2c59bfb43 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst @@ -0,0 +1,6 @@ +ProductInputsService +-------------------------------------- + +.. automodule:: google.shopping.merchant_products_v1beta.services.product_inputs_service + :members: + :inherited-members: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst new file mode 100644 index 000000000000..f20ce0b9e362 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst @@ -0,0 +1,10 @@ +ProductsService +--------------------------------- + +.. automodule:: google.shopping.merchant_products_v1beta.services.products_service + :members: + :inherited-members: + +.. automodule:: google.shopping.merchant_products_v1beta.services.products_service.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst new file mode 100644 index 000000000000..ce641539544e --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst @@ -0,0 +1,7 @@ +Services for Google Shopping Merchant Products v1beta API +========================================================= +.. toctree:: + :maxdepth: 2 + + product_inputs_service + products_service diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst new file mode 100644 index 000000000000..af3a6c59c20f --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst @@ -0,0 +1,6 @@ +Types for Google Shopping Merchant Products v1beta API +====================================================== + +.. automodule:: google.shopping.merchant_products_v1beta.types + :members: + :show-inheritance: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst new file mode 100644 index 000000000000..536d17b2ea65 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst @@ -0,0 +1,7 @@ +.. note:: + + Because this client uses :mod:`grpc` library, it is safe to + share instances across threads. In multiprocessing scenarios, the best + practice is to create client instances *after* the invocation of + :func:`os.fork` by :class:`multiprocessing.pool.Pool` or + :class:`multiprocessing.Process`. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py new file mode 100644 index 000000000000..92054cbf7e04 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.shopping.merchant_products import gapic_version as package_version + +__version__ = package_version.__version__ + + +from google.shopping.merchant_products_v1beta.services.product_inputs_service.client import ProductInputsServiceClient +from google.shopping.merchant_products_v1beta.services.product_inputs_service.async_client import ProductInputsServiceAsyncClient +from google.shopping.merchant_products_v1beta.services.products_service.client import ProductsServiceClient +from google.shopping.merchant_products_v1beta.services.products_service.async_client import ProductsServiceAsyncClient + +from google.shopping.merchant_products_v1beta.types.productinputs import DeleteProductInputRequest +from google.shopping.merchant_products_v1beta.types.productinputs import InsertProductInputRequest +from google.shopping.merchant_products_v1beta.types.productinputs import ProductInput +from google.shopping.merchant_products_v1beta.types.productinputs import UpdateProductInputRequest +from google.shopping.merchant_products_v1beta.types.products import GetProductRequest +from google.shopping.merchant_products_v1beta.types.products import ListProductsRequest +from google.shopping.merchant_products_v1beta.types.products import ListProductsResponse +from google.shopping.merchant_products_v1beta.types.products import Product +from google.shopping.merchant_products_v1beta.types.products_common import Attributes +from google.shopping.merchant_products_v1beta.types.products_common import AutomatedDiscounts +from google.shopping.merchant_products_v1beta.types.products_common import Certification +from google.shopping.merchant_products_v1beta.types.products_common import CloudExportAdditionalProperties +from google.shopping.merchant_products_v1beta.types.products_common import FreeShippingThreshold +from google.shopping.merchant_products_v1beta.types.products_common import Installment +from google.shopping.merchant_products_v1beta.types.products_common import LoyaltyPoints +from google.shopping.merchant_products_v1beta.types.products_common import LoyaltyProgram +from google.shopping.merchant_products_v1beta.types.products_common import ProductDetail +from google.shopping.merchant_products_v1beta.types.products_common import ProductDimension +from google.shopping.merchant_products_v1beta.types.products_common import ProductStatus +from google.shopping.merchant_products_v1beta.types.products_common import ProductStructuredDescription +from google.shopping.merchant_products_v1beta.types.products_common import ProductStructuredTitle +from google.shopping.merchant_products_v1beta.types.products_common import ProductSustainabilityIncentive +from google.shopping.merchant_products_v1beta.types.products_common import ProductWeight +from google.shopping.merchant_products_v1beta.types.products_common import Shipping +from google.shopping.merchant_products_v1beta.types.products_common import ShippingDimension +from google.shopping.merchant_products_v1beta.types.products_common import ShippingWeight +from google.shopping.merchant_products_v1beta.types.products_common import SubscriptionCost +from google.shopping.merchant_products_v1beta.types.products_common import Tax +from google.shopping.merchant_products_v1beta.types.products_common import UnitPricingBaseMeasure +from google.shopping.merchant_products_v1beta.types.products_common import UnitPricingMeasure +from google.shopping.merchant_products_v1beta.types.products_common import SubscriptionPeriod + +__all__ = ('ProductInputsServiceClient', + 'ProductInputsServiceAsyncClient', + 'ProductsServiceClient', + 'ProductsServiceAsyncClient', + 'DeleteProductInputRequest', + 'InsertProductInputRequest', + 'ProductInput', + 'UpdateProductInputRequest', + 'GetProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'Product', + 'Attributes', + 'AutomatedDiscounts', + 'Certification', + 'CloudExportAdditionalProperties', + 'FreeShippingThreshold', + 'Installment', + 'LoyaltyPoints', + 'LoyaltyProgram', + 'ProductDetail', + 'ProductDimension', + 'ProductStatus', + 'ProductStructuredDescription', + 'ProductStructuredTitle', + 'ProductSustainabilityIncentive', + 'ProductWeight', + 'Shipping', + 'ShippingDimension', + 'ShippingWeight', + 'SubscriptionCost', + 'Tax', + 'UnitPricingBaseMeasure', + 'UnitPricingMeasure', + 'SubscriptionPeriod', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py new file mode 100644 index 000000000000..20a9cd975b02 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed new file mode 100644 index 000000000000..962817aecdcd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py new file mode 100644 index 000000000000..ab41e40727d8 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +__version__ = package_version.__version__ + + +from .services.product_inputs_service import ProductInputsServiceClient +from .services.product_inputs_service import ProductInputsServiceAsyncClient +from .services.products_service import ProductsServiceClient +from .services.products_service import ProductsServiceAsyncClient + +from .types.productinputs import DeleteProductInputRequest +from .types.productinputs import InsertProductInputRequest +from .types.productinputs import ProductInput +from .types.productinputs import UpdateProductInputRequest +from .types.products import GetProductRequest +from .types.products import ListProductsRequest +from .types.products import ListProductsResponse +from .types.products import Product +from .types.products_common import Attributes +from .types.products_common import AutomatedDiscounts +from .types.products_common import Certification +from .types.products_common import CloudExportAdditionalProperties +from .types.products_common import FreeShippingThreshold +from .types.products_common import Installment +from .types.products_common import LoyaltyPoints +from .types.products_common import LoyaltyProgram +from .types.products_common import ProductDetail +from .types.products_common import ProductDimension +from .types.products_common import ProductStatus +from .types.products_common import ProductStructuredDescription +from .types.products_common import ProductStructuredTitle +from .types.products_common import ProductSustainabilityIncentive +from .types.products_common import ProductWeight +from .types.products_common import Shipping +from .types.products_common import ShippingDimension +from .types.products_common import ShippingWeight +from .types.products_common import SubscriptionCost +from .types.products_common import Tax +from .types.products_common import UnitPricingBaseMeasure +from .types.products_common import UnitPricingMeasure +from .types.products_common import SubscriptionPeriod + +__all__ = ( + 'ProductInputsServiceAsyncClient', + 'ProductsServiceAsyncClient', +'Attributes', +'AutomatedDiscounts', +'Certification', +'CloudExportAdditionalProperties', +'DeleteProductInputRequest', +'FreeShippingThreshold', +'GetProductRequest', +'InsertProductInputRequest', +'Installment', +'ListProductsRequest', +'ListProductsResponse', +'LoyaltyPoints', +'LoyaltyProgram', +'Product', +'ProductDetail', +'ProductDimension', +'ProductInput', +'ProductInputsServiceClient', +'ProductStatus', +'ProductStructuredDescription', +'ProductStructuredTitle', +'ProductSustainabilityIncentive', +'ProductWeight', +'ProductsServiceClient', +'Shipping', +'ShippingDimension', +'ShippingWeight', +'SubscriptionCost', +'SubscriptionPeriod', +'Tax', +'UnitPricingBaseMeasure', +'UnitPricingMeasure', +'UpdateProductInputRequest', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json new file mode 100644 index 000000000000..bcae8fc1c898 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json @@ -0,0 +1,122 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.shopping.merchant_products_v1beta", + "protoPackage": "google.shopping.merchant.products.v1beta", + "schema": "1.0", + "services": { + "ProductInputsService": { + "clients": { + "grpc": { + "libraryClient": "ProductInputsServiceClient", + "rpcs": { + "DeleteProductInput": { + "methods": [ + "delete_product_input" + ] + }, + "InsertProductInput": { + "methods": [ + "insert_product_input" + ] + }, + "UpdateProductInput": { + "methods": [ + "update_product_input" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductInputsServiceAsyncClient", + "rpcs": { + "DeleteProductInput": { + "methods": [ + "delete_product_input" + ] + }, + "InsertProductInput": { + "methods": [ + "insert_product_input" + ] + }, + "UpdateProductInput": { + "methods": [ + "update_product_input" + ] + } + } + }, + "rest": { + "libraryClient": "ProductInputsServiceClient", + "rpcs": { + "DeleteProductInput": { + "methods": [ + "delete_product_input" + ] + }, + "InsertProductInput": { + "methods": [ + "insert_product_input" + ] + }, + "UpdateProductInput": { + "methods": [ + "update_product_input" + ] + } + } + } + } + }, + "ProductsService": { + "clients": { + "grpc": { + "libraryClient": "ProductsServiceClient", + "rpcs": { + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ProductsServiceAsyncClient", + "rpcs": { + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + } + } + }, + "rest": { + "libraryClient": "ProductsServiceClient", + "rpcs": { + "GetProduct": { + "methods": [ + "get_product" + ] + }, + "ListProducts": { + "methods": [ + "list_products" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py new file mode 100644 index 000000000000..20a9cd975b02 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed new file mode 100644 index 000000000000..962817aecdcd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/__init__.py new file mode 100644 index 000000000000..cbf94b283c70 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py new file mode 100644 index 000000000000..570e3b7a9ffd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import ProductInputsServiceClient +from .async_client import ProductInputsServiceAsyncClient + +__all__ = ( + 'ProductInputsServiceClient', + 'ProductInputsServiceAsyncClient', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py new file mode 100644 index 000000000000..ee37c23d3725 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py @@ -0,0 +1,689 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging as std_logging +from collections import OrderedDict +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union + +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + + +try: + OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore + +from google.protobuf import field_mask_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport +from .client import ProductInputsServiceClient + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +class ProductInputsServiceAsyncClient: + """Service to use ProductInput resource. + This service works for products with online channel only. + """ + + _client: ProductInputsServiceClient + + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = ProductInputsServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ProductInputsServiceClient._DEFAULT_UNIVERSE + + product_path = staticmethod(ProductInputsServiceClient.product_path) + parse_product_path = staticmethod(ProductInputsServiceClient.parse_product_path) + product_input_path = staticmethod(ProductInputsServiceClient.product_input_path) + parse_product_input_path = staticmethod(ProductInputsServiceClient.parse_product_input_path) + common_billing_account_path = staticmethod(ProductInputsServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductInputsServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductInputsServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductInputsServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductInputsServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductInputsServiceClient.parse_common_organization_path) + common_project_path = staticmethod(ProductInputsServiceClient.common_project_path) + parse_common_project_path = staticmethod(ProductInputsServiceClient.parse_common_project_path) + common_location_path = staticmethod(ProductInputsServiceClient.common_location_path) + parse_common_location_path = staticmethod(ProductInputsServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceAsyncClient: The constructed client. + """ + return ProductInputsServiceClient.from_service_account_info.__func__(ProductInputsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceAsyncClient: The constructed client. + """ + return ProductInputsServiceClient.from_service_account_file.__func__(ProductInputsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ProductInputsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> ProductInputsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductInputsServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._client._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used + by the client instance. + """ + return self._client._universe_domain + + get_transport_class = ProductInputsServiceClient.get_transport_class + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product inputs service async client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductInputsServiceTransport,Callable[..., ProductInputsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductInputsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = ProductInputsServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1beta.ProductInputsServiceAsyncClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._client._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "credentialsType": None, + } + ) + + async def insert_product_input(self, + request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""`Uploads a product input to your Merchant Center + account `__. + You must have a products data source to be able to insert a + product. The unique identifier of the data source is passed as a + query parameter in the request URL. + + If an input with the same contentLanguage, offerId, and + dataSource already exists, this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + async def sample_insert_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.insert_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1beta.types.InsertProductInputRequest, dict]]): + The request object. Request message for the + InsertProductInput method. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.InsertProductInputRequest): + request = productinputs.InsertProductInputRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.insert_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_product_input(self, + request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, + *, + product_input: Optional[productinputs.ProductInput] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + async def sample_update_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.update_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest, dict]]): + The request object. Request message for the + UpdateProductInput method. The product + (primary input) must exist for the + update to succeed. If the update is for + a primary product input, the existing + primary product input must be from the + same data source. + product_input (:class:`google.shopping.merchant_products_v1beta.types.ProductInput`): + Required. The product input resource + to update. Information you submit will + be applied to the processed product as + well. + + This corresponds to the ``product_input`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. The list of product attributes to be updated. + + If the update mask is omitted, then it is treated as + implied field mask equivalent to all fields that are + populated (have a non-empty value). + + Attributes specified in the update mask without a value + specified in the body will be deleted from the product. + + Update mask can only be specified for top level fields + in attributes and custom attributes. + + To specify the update mask for custom attributes you + need to add the ``custom_attribute.`` prefix. + + Providing special "*" value for full product replacement + is not supported. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [product_input, update_mask] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.UpdateProductInputRequest): + request = productinputs.UpdateProductInputRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_input is not None: + request.product_input = product_input + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.update_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_input.name", request.product_input.name), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_product_input(self, + request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: + r"""Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + async def sample_delete_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + await client.delete_product_input(request=request) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest, dict]]): + The request object. Request message for the + DeleteProductInput method. + name (:class:`str`): + Required. The name of the product input resource to + delete. Format: + ``accounts/{account}/productInputs/{product}`` where the + last section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example + for product name is + ``accounts/123/productInputs/online~en~US~sku123``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.DeleteProductInputRequest): + request = productinputs.DeleteProductInputRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.delete_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def __aenter__(self) -> "ProductInputsServiceAsyncClient": + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +__all__ = ( + "ProductInputsServiceAsyncClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py new file mode 100644 index 000000000000..6b98c8ed0463 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py @@ -0,0 +1,1057 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from http import HTTPStatus +import json +import logging as std_logging +import os +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast +import warnings + +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +from google.protobuf import field_mask_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductInputsServiceGrpcTransport +from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport +from .transports.rest import ProductInputsServiceRestTransport + + +class ProductInputsServiceClientMeta(type): + """Metaclass for the ProductInputsService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] + _transport_registry["grpc"] = ProductInputsServiceGrpcTransport + _transport_registry["grpc_asyncio"] = ProductInputsServiceGrpcAsyncIOTransport + _transport_registry["rest"] = ProductInputsServiceRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[ProductInputsServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class ProductInputsServiceClient(metaclass=ProductInputsServiceClientMeta): + """Service to use ProductInput resource. + This service works for products with online channel only. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "merchantapi.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductInputsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductInputsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductInputsServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(account: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "accounts/{account}/products/{product}".format(account=account, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def product_input_path(account: str,productinput: str,) -> str: + """Returns a fully-qualified product_input string.""" + return "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) + + @staticmethod + def parse_product_input_path(path: str) -> Dict[str,str]: + """Parses a product_input path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/productInputs/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Deprecated. Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + + warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning) + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + """Return the API endpoint used by the client. + + Args: + api_override (str): The API endpoint override. If specified, this is always + the return value of this function and the other arguments are not used. + client_cert_source (bytes): The client certificate source used by the client. + universe_domain (str): The universe domain used by the client. + use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. + Possible values are "always", "auto", or "never". + + Returns: + str: The API endpoint to be used by the client. + """ + if api_override is not None: + api_endpoint = api_override + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + _default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") + api_endpoint = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) + return api_endpoint + + @staticmethod + def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ProductInputsServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain + + def _validate_universe_domain(self): + """Validates client's and credentials' universe domains are consistent. + + Returns: + bool: True iff the configured universe domain is valid. + + Raises: + ValueError: If the configured universe domain is not valid. + """ + + # NOTE (b/349488459): universe validation is disabled until further notice. + return True + + def _add_cred_info_for_auth_errors( + self, + error: core_exceptions.GoogleAPICallError + ) -> None: + """Adds credential info string to error details for 401/403/404 errors. + + Args: + error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. + """ + if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: + return + + cred = self._transport._credentials + + # get_cred_info is only available in google-auth>=2.35.0 + if not hasattr(cred, "get_cred_info"): + return + + # ignore the type check since pypy test fails when get_cred_info + # is not available + cred_info = cred.get_cred_info() # type: ignore + if cred_info and hasattr(error._details, "append"): + error._details.append(json.dumps(cred_info)) + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used by the client instance. + """ + return self._universe_domain + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the product inputs service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductInputsServiceTransport,Callable[..., ProductInputsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductInputsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that the ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client_options = client_options + if isinstance(self._client_options, dict): + self._client_options = client_options_lib.from_dict(self._client_options) + if self._client_options is None: + self._client_options = client_options_lib.ClientOptions() + self._client_options = cast(client_options_lib.ClientOptions, self._client_options) + + universe_domain_opt = getattr(self._client_options, 'universe_domain', None) + + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductInputsServiceClient._read_environment_variables() + self._client_cert_source = ProductInputsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) + self._universe_domain = ProductInputsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False + + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + + api_key_value = getattr(self._client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + transport_provided = isinstance(transport, ProductInputsServiceTransport) + if transport_provided: + # transport is a ProductInputsServiceTransport instance. + if credentials or self._client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if self._client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = cast(ProductInputsServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = (self._api_endpoint or + ProductInputsServiceClient._get_api_endpoint( + self._client_options.api_endpoint, + self._client_cert_source, + self._universe_domain, + self._use_mtls_endpoint)) + + if not transport_provided: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + transport_init: Union[Type[ProductInputsServiceTransport], Callable[..., ProductInputsServiceTransport]] = ( + ProductInputsServiceClient.get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., ProductInputsServiceTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( + credentials=credentials, + credentials_file=self._client_options.credentials_file, + host=self._api_endpoint, + scopes=self._client_options.scopes, + client_cert_source_for_mtls=self._client_cert_source, + quota_project_id=self._client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=self._client_options.api_audience, + ) + + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1beta.ProductInputsServiceClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "credentialsType": None, + } + ) + + def insert_product_input(self, + request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""`Uploads a product input to your Merchant Center + account `__. + You must have a products data source to be able to insert a + product. The unique identifier of the data source is passed as a + query parameter in the request URL. + + If an input with the same contentLanguage, offerId, and + dataSource already exists, this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + def sample_insert_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.insert_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1beta.types.InsertProductInputRequest, dict]): + The request object. Request message for the + InsertProductInput method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.InsertProductInputRequest): + request = productinputs.InsertProductInputRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.insert_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_product_input(self, + request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, + *, + product_input: Optional[productinputs.ProductInput] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: + r"""Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + def sample_update_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.update_product_input(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest, dict]): + The request object. Request message for the + UpdateProductInput method. The product + (primary input) must exist for the + update to succeed. If the update is for + a primary product input, the existing + primary product input must be from the + same data source. + product_input (google.shopping.merchant_products_v1beta.types.ProductInput): + Required. The product input resource + to update. Information you submit will + be applied to the processed product as + well. + + This corresponds to the ``product_input`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. The list of product attributes to be updated. + + If the update mask is omitted, then it is treated as + implied field mask equivalent to all fields that are + populated (have a non-empty value). + + Attributes specified in the update mask without a value + specified in the body will be deleted from the product. + + Update mask can only be specified for top level fields + in attributes and custom attributes. + + To specify the update mask for custom attributes you + need to add the ``custom_attribute.`` prefix. + + Providing special "*" value for full product replacement + is not supported. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.types.ProductInput: + This resource represents input data you submit for a product, not the + processed product that you see in Merchant Center, in + Shopping ads, or across Google surfaces. Product + inputs, rules and supplemental data source data are + combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. + For more information, see [Manage + products](/merchant/api/guides/products/overview). + + Required product input attributes to pass data + validation checks are primarily defined in the + [Products Data + Specification](\ https://support.google.com/merchants/answer/188494). + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product + input, it may take several minutes before the + processed product can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding + attribute in the [Products Data + Specification](\ https://support.google.com/merchants/answer/188494) + with [some + exceptions](\ https://support.google.com/merchants/answer/7052112). + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [product_input, update_mask] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.UpdateProductInputRequest): + request = productinputs.UpdateProductInputRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if product_input is not None: + request.product_input = product_input + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("product_input.name", request.product_input.name), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_product_input(self, + request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: + r"""Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + def sample_delete_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + client.delete_product_input(request=request) + + Args: + request (Union[google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest, dict]): + The request object. Request message for the + DeleteProductInput method. + name (str): + Required. The name of the product input resource to + delete. Format: + ``accounts/{account}/productInputs/{product}`` where the + last section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example + for product name is + ``accounts/123/productInputs/online~en~US~sku123``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, productinputs.DeleteProductInputRequest): + request = productinputs.DeleteProductInputRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_product_input] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def __enter__(self) -> "ProductInputsServiceClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + +__all__ = ( + "ProductInputsServiceClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst new file mode 100644 index 000000000000..fa031e4be3c9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst @@ -0,0 +1,9 @@ + +transport inheritance structure +_______________________________ + +`ProductInputsServiceTransport` is the ABC for all transports. +- public child `ProductInputsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). +- public child `ProductInputsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). +- private child `_BaseProductInputsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). +- public child `ProductInputsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py new file mode 100644 index 000000000000..e9792827a667 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import ProductInputsServiceTransport +from .grpc import ProductInputsServiceGrpcTransport +from .grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport +from .rest import ProductInputsServiceRestTransport +from .rest import ProductInputsServiceRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] +_transport_registry['grpc'] = ProductInputsServiceGrpcTransport +_transport_registry['grpc_asyncio'] = ProductInputsServiceGrpcAsyncIOTransport +_transport_registry['rest'] = ProductInputsServiceRestTransport + +__all__ = ( + 'ProductInputsServiceTransport', + 'ProductInputsServiceGrpcTransport', + 'ProductInputsServiceGrpcAsyncIOTransport', + 'ProductInputsServiceRestTransport', + 'ProductInputsServiceRestInterceptor', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py new file mode 100644 index 000000000000..2fbd406ff780 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py @@ -0,0 +1,188 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductInputsServiceTransport(abc.ABC): + """Abstract transport class for ProductInputsService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/content', + ) + + DEFAULT_HOST: str = 'merchantapi.googleapis.com' + + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + if not hasattr(self, "_ignore_credentials"): + self._ignore_credentials: bool = False + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None and not self._ignore_credentials: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + @property + def host(self): + return self._host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.insert_product_input: gapic_v1.method.wrap_method( + self.insert_product_input, + default_timeout=None, + client_info=client_info, + ), + self.update_product_input: gapic_v1.method.wrap_method( + self.update_product_input, + default_timeout=None, + client_info=client_info, + ), + self.delete_product_input: gapic_v1.method.wrap_method( + self.delete_product_input, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + Union[ + productinputs.ProductInput, + Awaitable[productinputs.ProductInput] + ]]: + raise NotImplementedError() + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + Union[ + productinputs.ProductInput, + Awaitable[productinputs.ProductInput] + ]]: + raise NotImplementedError() + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'ProductInputsServiceTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py new file mode 100644 index 000000000000..79403a317639 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py @@ -0,0 +1,419 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging as std_logging +import pickle +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs +from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductInputsServiceGrpcTransport(ProductInputsServiceTransport): + """gRPC backend transport for ProductInputsService. + + Service to use ProductInput resource. + This service works for products with online channel only. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, grpc.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) + + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + productinputs.ProductInput]: + r"""Return a callable for the insert product input method over gRPC. + + `Uploads a product input to your Merchant Center + account `__. + You must have a products data source to be able to insert a + product. The unique identifier of the data source is passed as a + query parameter in the request URL. + + If an input with the same contentLanguage, offerId, and + dataSource already exists, this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + Returns: + Callable[[~.InsertProductInputRequest], + ~.ProductInput]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'insert_product_input' not in self._stubs: + self._stubs['insert_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductInputsService/InsertProductInput', + request_serializer=productinputs.InsertProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['insert_product_input'] + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + productinputs.ProductInput]: + r"""Return a callable for the update product input method over gRPC. + + Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.UpdateProductInputRequest], + ~.ProductInput]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_product_input' not in self._stubs: + self._stubs['update_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductInputsService/UpdateProductInput', + request_serializer=productinputs.UpdateProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['update_product_input'] + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete product input method over gRPC. + + Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.DeleteProductInputRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_product_input' not in self._stubs: + self._stubs['delete_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductInputsService/DeleteProductInput', + request_serializer=productinputs.DeleteProductInputRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_input'] + + def close(self): + self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'ProductInputsServiceGrpcTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py new file mode 100644 index 000000000000..a7c5e8de0a0e --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py @@ -0,0 +1,450 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import inspect +import json +import pickle +import logging as std_logging +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import exceptions as core_exceptions +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore +from grpc.experimental import aio # type: ignore + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs +from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductInputsServiceGrpcTransport + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductInputsServiceGrpcAsyncIOTransport(ProductInputsServiceTransport): + """gRPC AsyncIO backend transport for ProductInputsService. + + Service to use ProductInput resource. + This service works for products with online channel only. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, aio.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel + self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + Awaitable[productinputs.ProductInput]]: + r"""Return a callable for the insert product input method over gRPC. + + `Uploads a product input to your Merchant Center + account `__. + You must have a products data source to be able to insert a + product. The unique identifier of the data source is passed as a + query parameter in the request URL. + + If an input with the same contentLanguage, offerId, and + dataSource already exists, this method replaces that entry. + + After inserting, updating, or deleting a product input, it may + take several minutes before the processed product can be + retrieved. + + Returns: + Callable[[~.InsertProductInputRequest], + Awaitable[~.ProductInput]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'insert_product_input' not in self._stubs: + self._stubs['insert_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductInputsService/InsertProductInput', + request_serializer=productinputs.InsertProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['insert_product_input'] + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + Awaitable[productinputs.ProductInput]]: + r"""Return a callable for the update product input method over gRPC. + + Updates the existing product input in your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.UpdateProductInputRequest], + Awaitable[~.ProductInput]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_product_input' not in self._stubs: + self._stubs['update_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductInputsService/UpdateProductInput', + request_serializer=productinputs.UpdateProductInputRequest.serialize, + response_deserializer=productinputs.ProductInput.deserialize, + ) + return self._stubs['update_product_input'] + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete product input method over gRPC. + + Deletes a product input from your Merchant Center + account. + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + Returns: + Callable[[~.DeleteProductInputRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_product_input' not in self._stubs: + self._stubs['delete_product_input'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductInputsService/DeleteProductInput', + request_serializer=productinputs.DeleteProductInputRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_product_input'] + + def _prep_wrapped_messages(self, client_info): + """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.insert_product_input: self._wrap_method( + self.insert_product_input, + default_timeout=None, + client_info=client_info, + ), + self.update_product_input: self._wrap_method( + self.update_product_input, + default_timeout=None, + client_info=client_info, + ), + self.delete_product_input: self._wrap_method( + self.delete_product_input, + default_timeout=None, + client_info=client_info, + ), + } + + def _wrap_method(self, func, *args, **kwargs): + if self._wrap_with_kind: # pragma: NO COVER + kwargs["kind"] = self.kind + return gapic_v1.method_async.wrap_method(func, *args, **kwargs) + + def close(self): + return self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc_asyncio" + + +__all__ = ( + 'ProductInputsServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py new file mode 100644 index 000000000000..5284480922da --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py @@ -0,0 +1,711 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import json # type: ignore + +from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import gapic_v1 +import google.protobuf + +from google.protobuf import json_format + +from requests import __version__ as requests_version +import dataclasses +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs + + +from .rest_base import _BaseProductInputsServiceRestTransport +from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=f"requests@{requests_version}", +) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductInputsServiceRestInterceptor: + """Interceptor for ProductInputsService. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the ProductInputsServiceRestTransport. + + .. code-block:: python + class MyCustomProductInputsServiceInterceptor(ProductInputsServiceRestInterceptor): + def pre_delete_product_input(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_insert_product_input(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_insert_product_input(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_product_input(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_product_input(self, response): + logging.log(f"Received response: {response}") + return response + + transport = ProductInputsServiceRestTransport(interceptor=MyCustomProductInputsServiceInterceptor()) + client = ProductInputsServiceClient(transport=transport) + + + """ + def pre_delete_product_input(self, request: productinputs.DeleteProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.DeleteProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for delete_product_input + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductInputsService server. + """ + return request, metadata + + def pre_insert_product_input(self, request: productinputs.InsertProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.InsertProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for insert_product_input + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductInputsService server. + """ + return request, metadata + + def post_insert_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: + """Post-rpc interceptor for insert_product_input + + DEPRECATED. Please use the `post_insert_product_input_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductInputsService server but before + it is returned to user code. This `post_insert_product_input` interceptor runs + before the `post_insert_product_input_with_metadata` interceptor. + """ + return response + + def post_insert_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for insert_product_input + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductInputsService server but before it is returned to user code. + + We recommend only using this `post_insert_product_input_with_metadata` + interceptor in new development instead of the `post_insert_product_input` interceptor. + When both interceptors are used, this `post_insert_product_input_with_metadata` interceptor runs after the + `post_insert_product_input` interceptor. The (possibly modified) response returned by + `post_insert_product_input` will be passed to + `post_insert_product_input_with_metadata`. + """ + return response, metadata + + def pre_update_product_input(self, request: productinputs.UpdateProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.UpdateProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for update_product_input + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductInputsService server. + """ + return request, metadata + + def post_update_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: + """Post-rpc interceptor for update_product_input + + DEPRECATED. Please use the `post_update_product_input_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductInputsService server but before + it is returned to user code. This `post_update_product_input` interceptor runs + before the `post_update_product_input_with_metadata` interceptor. + """ + return response + + def post_update_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for update_product_input + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductInputsService server but before it is returned to user code. + + We recommend only using this `post_update_product_input_with_metadata` + interceptor in new development instead of the `post_update_product_input` interceptor. + When both interceptors are used, this `post_update_product_input_with_metadata` interceptor runs after the + `post_update_product_input` interceptor. The (possibly modified) response returned by + `post_update_product_input` will be passed to + `post_update_product_input_with_metadata`. + """ + return response, metadata + + +@dataclasses.dataclass +class ProductInputsServiceRestStub: + _session: AuthorizedSession + _host: str + _interceptor: ProductInputsServiceRestInterceptor + + +class ProductInputsServiceRestTransport(_BaseProductInputsServiceRestTransport): + """REST backend synchronous transport for ProductInputsService. + + Service to use ProductInput resource. + This service works for products with online channel only. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[ProductInputsServiceRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + url_scheme=url_scheme, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or ProductInputsServiceRestInterceptor() + self._prep_wrapped_messages(client_info) + + class _DeleteProductInput(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput, ProductInputsServiceRestStub): + def __hash__(self): + return hash("ProductInputsServiceRestTransport.DeleteProductInput") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__(self, + request: productinputs.DeleteProductInputRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ): + r"""Call the delete product input method over HTTP. + + Args: + request (~.productinputs.DeleteProductInputRequest): + The request object. Request message for the + DeleteProductInput method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + + http_options = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_http_options() + + request, metadata = self._interceptor.pre_delete_product_input(request, metadata) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_transcoded_request(http_options, request) + + # Jsonify the query params + query_params = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.DeleteProductInput", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": "DeleteProductInput", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductInputsServiceRestTransport._DeleteProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _InsertProductInput(_BaseProductInputsServiceRestTransport._BaseInsertProductInput, ProductInputsServiceRestStub): + def __hash__(self): + return hash("ProductInputsServiceRestTransport.InsertProductInput") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__(self, + request: productinputs.InsertProductInputRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> productinputs.ProductInput: + r"""Call the insert product input method over HTTP. + + Args: + request (~.productinputs.InsertProductInputRequest): + The request object. Request message for the + InsertProductInput method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.productinputs.ProductInput: + This resource represents input data you submit for a + product, not the processed product that you see in + Merchant Center, in Shopping ads, or across Google + surfaces. Product inputs, rules and supplemental data + source data are combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. + For more information, see `Manage + products `__. + + Required product input attributes to pass data + validation checks are primarily defined in the `Products + Data + Specification `__. + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding attribute + in the `Products Data + Specification `__ + with `some + exceptions `__. + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + + http_options = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_http_options() + + request, metadata = self._interceptor.pre_insert_product_input(request, metadata) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_transcoded_request(http_options, request) + + body = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_request_body_json(transcoded_request) + + # Jsonify the query params + query_params = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.InsertProductInput", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": "InsertProductInput", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductInputsServiceRestTransport._InsertProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = productinputs.ProductInput() + pb_resp = productinputs.ProductInput.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_insert_product_input(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_insert_product_input_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = productinputs.ProductInput.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.insert_product_input", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": "InsertProductInput", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _UpdateProductInput(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput, ProductInputsServiceRestStub): + def __hash__(self): + return hash("ProductInputsServiceRestTransport.UpdateProductInput") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__(self, + request: productinputs.UpdateProductInputRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> productinputs.ProductInput: + r"""Call the update product input method over HTTP. + + Args: + request (~.productinputs.UpdateProductInputRequest): + The request object. Request message for the + UpdateProductInput method. The product + (primary input) must exist for the + update to succeed. If the update is for + a primary product input, the existing + primary product input must be from the + same data source. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.productinputs.ProductInput: + This resource represents input data you submit for a + product, not the processed product that you see in + Merchant Center, in Shopping ads, or across Google + surfaces. Product inputs, rules and supplemental data + source data are combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. + For more information, see `Manage + products `__. + + Required product input attributes to pass data + validation checks are primarily defined in the `Products + Data + Specification `__. + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product input, + it may take several minutes before the processed product + can be retrieved. + + All fields in the product input and its sub-messages + match the English name of their corresponding attribute + in the `Products Data + Specification `__ + with `some + exceptions `__. + The following reference documentation lists the field + names in the **camelCase** casing style while the + Products Data Specification lists the names in the + **snake_case** casing style. + + """ + + http_options = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_http_options() + + request, metadata = self._interceptor.pre_update_product_input(request, metadata) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_transcoded_request(http_options, request) + + body = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_request_body_json(transcoded_request) + + # Jsonify the query params + query_params = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.UpdateProductInput", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": "UpdateProductInput", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductInputsServiceRestTransport._UpdateProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = productinputs.ProductInput() + pb_resp = productinputs.ProductInput.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_update_product_input(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_product_input_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = productinputs.ProductInput.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.update_product_input", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "rpcName": "UpdateProductInput", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + @property + def delete_product_input(self) -> Callable[ + [productinputs.DeleteProductInputRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteProductInput(self._session, self._host, self._interceptor) # type: ignore + + @property + def insert_product_input(self) -> Callable[ + [productinputs.InsertProductInputRequest], + productinputs.ProductInput]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._InsertProductInput(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_product_input(self) -> Callable[ + [productinputs.UpdateProductInputRequest], + productinputs.ProductInput]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateProductInput(self._session, self._host, self._interceptor) # type: ignore + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'ProductInputsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py new file mode 100644 index 000000000000..7518357fe1db --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py @@ -0,0 +1,223 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json # type: ignore +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union + + +from google.protobuf import empty_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import productinputs + + +class _BaseProductInputsServiceRestTransport(ProductInputsServiceTransport): + """Base REST backend transport for ProductInputsService. + + Note: This class is not meant to be used directly. Use its sync and + async sub-classes instead. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[Any]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + + class _BaseDeleteProductInput: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/products/v1beta/{name=accounts/*/productInputs/*}', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = productinputs.DeleteProductInputRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseInsertProductInput: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/products/v1beta/{parent=accounts/*}/productInputs:insert', + 'body': 'product_input', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = productinputs.InsertProductInputRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + use_integers_for_enums=True + ) + return body + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseUpdateProductInput: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/products/v1beta/{product_input.name=accounts/*/productInputs/*}', + 'body': 'product_input', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = productinputs.UpdateProductInputRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + use_integers_for_enums=True + ) + return body + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + +__all__=( + '_BaseProductInputsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py new file mode 100644 index 000000000000..4513749ea12b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import ProductsServiceClient +from .async_client import ProductsServiceAsyncClient + +__all__ = ( + 'ProductsServiceClient', + 'ProductsServiceAsyncClient', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py new file mode 100644 index 000000000000..f3c4a4aa101a --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py @@ -0,0 +1,522 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging as std_logging +from collections import OrderedDict +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union + +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + + +try: + OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore + +from google.shopping.merchant_products_v1beta.services.products_service import pagers +from google.shopping.merchant_products_v1beta.types import products +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport +from .client import ProductsServiceClient + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +class ProductsServiceAsyncClient: + """Service to use Product resource.""" + + _client: ProductsServiceClient + + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = ProductsServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ProductsServiceClient._DEFAULT_UNIVERSE + + product_path = staticmethod(ProductsServiceClient.product_path) + parse_product_path = staticmethod(ProductsServiceClient.parse_product_path) + common_billing_account_path = staticmethod(ProductsServiceClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(ProductsServiceClient.parse_common_billing_account_path) + common_folder_path = staticmethod(ProductsServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(ProductsServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(ProductsServiceClient.common_organization_path) + parse_common_organization_path = staticmethod(ProductsServiceClient.parse_common_organization_path) + common_project_path = staticmethod(ProductsServiceClient.common_project_path) + parse_common_project_path = staticmethod(ProductsServiceClient.parse_common_project_path) + common_location_path = staticmethod(ProductsServiceClient.common_location_path) + parse_common_location_path = staticmethod(ProductsServiceClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceAsyncClient: The constructed client. + """ + return ProductsServiceClient.from_service_account_info.__func__(ProductsServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceAsyncClient: The constructed client. + """ + return ProductsServiceClient.from_service_account_file.__func__(ProductsServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ProductsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> ProductsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductsServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._client._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used + by the client instance. + """ + return self._client._universe_domain + + get_transport_class = ProductsServiceClient.get_transport_class + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the products service async client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductsServiceTransport,Callable[..., ProductsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport to use. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = ProductsServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1beta.ProductsServiceAsyncClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._client._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "credentialsType": None, + } + ) + + async def get_product(self, + request: Optional[Union[products.GetProductRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: + r"""Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + async def sample_get_product(): + # Create a client + client = merchant_products_v1beta.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1beta.types.GetProductRequest, dict]]): + The request object. Request message for the GetProduct + method. + name (:class:`str`): + Required. The name of the product to retrieve. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example + for product name is + ``accounts/123/products/online~en~US~sku123`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.types.Product: + The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] + after applying rules and supplemental data sources. + This processed product matches what is shown in your + Merchant Center account. Each product is built from + exactly one primary data source product input, and + multiple supplemental data source inputs. After + inserting, updating, or deleting a product input, it + may take several minutes before the updated processed + product can be retrieved. + + All fields in the processed product and its + sub-messages match the name of their corresponding + attribute in the [Product data + specification](\ https://support.google.com/merchants/answer/7052112) + with some exceptions. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.GetProductRequest): + request = products.GetProductRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.get_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_products(self, + request: Optional[Union[products.ListProductsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListProductsAsyncPager: + r"""Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + async def sample_list_products(): + # Create a client + client = merchant_products_v1beta.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.shopping.merchant_products_v1beta.types.ListProductsRequest, dict]]): + The request object. Request message for the ListProducts + method. + parent (:class:`str`): + Required. The account to list processed products for. + Format: ``accounts/{account}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsAsyncPager: + Response message for the ListProducts + method. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.ListProductsRequest): + request = products.ListProductsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[self._client._transport.list_products] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListProductsAsyncPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self) -> "ProductsServiceAsyncClient": + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +__all__ = ( + "ProductsServiceAsyncClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py new file mode 100644 index 000000000000..cea09df43fbe --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py @@ -0,0 +1,881 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from http import HTTPStatus +import json +import logging as std_logging +import os +import re +from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast +import warnings + +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + +from google.shopping.merchant_products_v1beta.services.products_service import pagers +from google.shopping.merchant_products_v1beta.types import products +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types +from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ProductsServiceGrpcTransport +from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport +from .transports.rest import ProductsServiceRestTransport + + +class ProductsServiceClientMeta(type): + """Metaclass for the ProductsService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] + _transport_registry["grpc"] = ProductsServiceGrpcTransport + _transport_registry["grpc_asyncio"] = ProductsServiceGrpcAsyncIOTransport + _transport_registry["rest"] = ProductsServiceRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[ProductsServiceTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class ProductsServiceClient(metaclass=ProductsServiceClientMeta): + """Service to use Product resource.""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. + DEFAULT_ENDPOINT = "merchantapi.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + _DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.{UNIVERSE_DOMAIN}" + _DEFAULT_UNIVERSE = "googleapis.com" + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + ProductsServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ProductsServiceTransport: + """Returns the transport used by the client instance. + + Returns: + ProductsServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def product_path(account: str,product: str,) -> str: + """Returns a fully-qualified product string.""" + return "accounts/{account}/products/{product}".format(account=account, product=product, ) + + @staticmethod + def parse_product_path(path: str) -> Dict[str,str]: + """Parses a product path into its component segments.""" + m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Deprecated. Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + + warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning) + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + @staticmethod + def _read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + + @staticmethod + def _get_client_cert_source(provided_cert_source, use_cert_flag): + """Return the client cert source to be used by the client. + + Args: + provided_cert_source (bytes): The client certificate source provided. + use_cert_flag (bool): A flag indicating whether to use the client certificate. + + Returns: + bytes or None: The client cert source to be used by the client. + """ + client_cert_source = None + if use_cert_flag: + if provided_cert_source: + client_cert_source = provided_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + return client_cert_source + + @staticmethod + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + """Return the API endpoint used by the client. + + Args: + api_override (str): The API endpoint override. If specified, this is always + the return value of this function and the other arguments are not used. + client_cert_source (bytes): The client certificate source used by the client. + universe_domain (str): The universe domain used by the client. + use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. + Possible values are "always", "auto", or "never". + + Returns: + str: The API endpoint to be used by the client. + """ + if api_override is not None: + api_endpoint = api_override + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + _default_universe = ProductsServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") + api_endpoint = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) + return api_endpoint + + @staticmethod + def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: + """Return the universe domain used by the client. + + Args: + client_universe_domain (Optional[str]): The universe domain configured via the client options. + universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. + + Returns: + str: The universe domain to be used by the client. + + Raises: + ValueError: If the universe domain is an empty string. + """ + universe_domain = ProductsServiceClient._DEFAULT_UNIVERSE + if client_universe_domain is not None: + universe_domain = client_universe_domain + elif universe_domain_env is not None: + universe_domain = universe_domain_env + if len(universe_domain.strip()) == 0: + raise ValueError("Universe Domain cannot be an empty string.") + return universe_domain + + def _validate_universe_domain(self): + """Validates client's and credentials' universe domains are consistent. + + Returns: + bool: True iff the configured universe domain is valid. + + Raises: + ValueError: If the configured universe domain is not valid. + """ + + # NOTE (b/349488459): universe validation is disabled until further notice. + return True + + def _add_cred_info_for_auth_errors( + self, + error: core_exceptions.GoogleAPICallError + ) -> None: + """Adds credential info string to error details for 401/403/404 errors. + + Args: + error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. + """ + if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: + return + + cred = self._transport._credentials + + # get_cred_info is only available in google-auth>=2.35.0 + if not hasattr(cred, "get_cred_info"): + return + + # ignore the type check since pypy test fails when get_cred_info + # is not available + cred_info = cred.get_cred_info() # type: ignore + if cred_info and hasattr(error._details, "append"): + error._details.append(json.dumps(cred_info)) + + @property + def api_endpoint(self): + """Return the API endpoint used by the client instance. + + Returns: + str: The API endpoint used by the client instance. + """ + return self._api_endpoint + + @property + def universe_domain(self) -> str: + """Return the universe domain used by the client instance. + + Returns: + str: The universe domain used by the client instance. + """ + return self._universe_domain + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the products service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Optional[Union[str,ProductsServiceTransport,Callable[..., ProductsServiceTransport]]]): + The transport to use, or a Callable that constructs and returns a new transport. + If a Callable is given, it will be called with the same set of initialization + arguments as used in the ProductsServiceTransport constructor. + If set to None, a transport is chosen automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): + Custom options for the client. + + 1. The ``api_endpoint`` property can be used to override the + default endpoint provided by the client when ``transport`` is + not explicitly provided. Only if this property is not set and + ``transport`` was not explicitly provided, the endpoint is + determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment + variable, which have one of the following values: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto-switch to the + default mTLS endpoint if client certificate is present; this is + the default value). + + 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide a client certificate for mTLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + 3. The ``universe_domain`` property can be used to override the + default "googleapis.com" universe. Note that the ``api_endpoint`` + property still takes precedence; and ``universe_domain`` is + currently not supported for mTLS. + + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client_options = client_options + if isinstance(self._client_options, dict): + self._client_options = client_options_lib.from_dict(self._client_options) + if self._client_options is None: + self._client_options = client_options_lib.ClientOptions() + self._client_options = cast(client_options_lib.ClientOptions, self._client_options) + + universe_domain_opt = getattr(self._client_options, 'universe_domain', None) + + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductsServiceClient._read_environment_variables() + self._client_cert_source = ProductsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) + self._universe_domain = ProductsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False + + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + + api_key_value = getattr(self._client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + transport_provided = isinstance(transport, ProductsServiceTransport) + if transport_provided: + # transport is a ProductsServiceTransport instance. + if credentials or self._client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if self._client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = cast(ProductsServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = (self._api_endpoint or + ProductsServiceClient._get_api_endpoint( + self._client_options.api_endpoint, + self._client_cert_source, + self._universe_domain, + self._use_mtls_endpoint)) + + if not transport_provided: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + transport_init: Union[Type[ProductsServiceTransport], Callable[..., ProductsServiceTransport]] = ( + ProductsServiceClient.get_transport_class(transport) + if isinstance(transport, str) or transport is None + else cast(Callable[..., ProductsServiceTransport], transport) + ) + # initialize with the provided callable or the passed in class + self._transport = transport_init( + credentials=credentials, + credentials_file=self._client_options.credentials_file, + host=self._api_endpoint, + scopes=self._client_options.scopes, + client_cert_source_for_mtls=self._client_cert_source, + quota_project_id=self._client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=self._client_options.api_audience, + ) + + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.shopping.merchant.products_v1beta.ProductsServiceClient`.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + } if hasattr(self._transport, "_credentials") else { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "credentialsType": None, + } + ) + + def get_product(self, + request: Optional[Union[products.GetProductRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: + r"""Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + def sample_get_product(): + # Create a client + client = merchant_products_v1beta.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1beta.types.GetProductRequest, dict]): + The request object. Request message for the GetProduct + method. + name (str): + Required. The name of the product to retrieve. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example + for product name is + ``accounts/123/products/online~en~US~sku123`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.types.Product: + The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] + after applying rules and supplemental data sources. + This processed product matches what is shown in your + Merchant Center account. Each product is built from + exactly one primary data source product input, and + multiple supplemental data source inputs. After + inserting, updating, or deleting a product input, it + may take several minutes before the updated processed + product can be retrieved. + + All fields in the processed product and its + sub-messages match the name of their corresponding + attribute in the [Product data + specification](\ https://support.google.com/merchants/answer/7052112) + with some exceptions. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [name] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.GetProductRequest): + request = products.GetProductRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_product] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_products(self, + request: Optional[Union[products.ListProductsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListProductsPager: + r"""Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.shopping import merchant_products_v1beta + + def sample_list_products(): + # Create a client + client = merchant_products_v1beta.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.shopping.merchant_products_v1beta.types.ListProductsRequest, dict]): + The request object. Request message for the ListProducts + method. + parent (str): + Required. The account to list processed products for. + Format: ``accounts/{account}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsPager: + Response message for the ListProducts + method. + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + flattened_params = [parent] + has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, products.ListProductsRequest): + request = products.ListProductsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_products] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListProductsPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self) -> "ProductsServiceClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + +__all__ = ( + "ProductsServiceClient", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py new file mode 100644 index 000000000000..f5b22754278b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import retry_async as retries_async +from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator, Union +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] + OptionalAsyncRetry = Union[retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore + +from google.shopping.merchant_products_v1beta.types import products + + +class ListProductsPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., products.ListProductsResponse], + request: products.ListProductsRequest, + response: products.ListProductsResponse, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.shopping.merchant_products_v1beta.types.ListProductsRequest): + The initial request object. + response (google.shopping.merchant_products_v1beta.types.ListProductsResponse): + The initial response object. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + self._method = method + self._request = products.ListProductsRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[products.ListProductsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[products.Product]: + for page in self.pages: + yield from page.products + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListProductsAsyncPager: + """A pager for iterating through ``list_products`` requests. + + This class thinly wraps an initial + :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``products`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListProducts`` requests and continue to iterate + through the ``products`` field on the + corresponding responses. + + All the usual :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[products.ListProductsResponse]], + request: products.ListProductsRequest, + response: products.ListProductsResponse, + *, + retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.shopping.merchant_products_v1beta.types.ListProductsRequest): + The initial request object. + response (google.shopping.merchant_products_v1beta.types.ListProductsResponse): + The initial response object. + retry (google.api_core.retry.AsyncRetry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + self._method = method + self._request = products.ListProductsRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[products.ListProductsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[products.Product]: + async def async_generator(): + async for page in self.pages: + for response in page.products: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst new file mode 100644 index 000000000000..c1cbe3d98697 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst @@ -0,0 +1,9 @@ + +transport inheritance structure +_______________________________ + +`ProductsServiceTransport` is the ABC for all transports. +- public child `ProductsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). +- public child `ProductsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). +- private child `_BaseProductsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). +- public child `ProductsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py new file mode 100644 index 000000000000..29d073519076 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import ProductsServiceTransport +from .grpc import ProductsServiceGrpcTransport +from .grpc_asyncio import ProductsServiceGrpcAsyncIOTransport +from .rest import ProductsServiceRestTransport +from .rest import ProductsServiceRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] +_transport_registry['grpc'] = ProductsServiceGrpcTransport +_transport_registry['grpc_asyncio'] = ProductsServiceGrpcAsyncIOTransport +_transport_registry['rest'] = ProductsServiceRestTransport + +__all__ = ( + 'ProductsServiceTransport', + 'ProductsServiceGrpcTransport', + 'ProductsServiceGrpcAsyncIOTransport', + 'ProductsServiceRestTransport', + 'ProductsServiceRestInterceptor', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py new file mode 100644 index 000000000000..6fa077ce7155 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py @@ -0,0 +1,173 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.shopping.merchant_products_v1beta import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +import google.protobuf + +from google.shopping.merchant_products_v1beta.types import products + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductsServiceTransport(abc.ABC): + """Abstract transport class for ProductsService.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/content', + ) + + DEFAULT_HOST: str = 'merchantapi.googleapis.com' + + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + if not hasattr(self, "_ignore_credentials"): + self._ignore_credentials: bool = False + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None and not self._ignore_credentials: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + @property + def host(self): + return self._host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.get_product: gapic_v1.method.wrap_method( + self.get_product, + default_timeout=None, + client_info=client_info, + ), + self.list_products: gapic_v1.method.wrap_method( + self.list_products, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + Union[ + products.Product, + Awaitable[products.Product] + ]]: + raise NotImplementedError() + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + Union[ + products.ListProductsResponse, + Awaitable[products.ListProductsResponse] + ]]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'ProductsServiceTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py new file mode 100644 index 000000000000..628a7d22acfd --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py @@ -0,0 +1,383 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json +import logging as std_logging +import pickle +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore + +from google.shopping.merchant_products_v1beta.types import products +from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER + def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = response.result() + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response for {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": client_call_details.method, + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductsServiceGrpcTransport(ProductsServiceTransport): + """gRPC backend transport for ProductsService. + + Service to use Product resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if a ``channel`` instance is provided. + channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, grpc.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientInterceptor() + self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) + + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + products.Product]: + r"""Return a callable for the get product method over gRPC. + + Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + Returns: + Callable[[~.GetProductRequest], + ~.Product]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_product' not in self._stubs: + self._stubs['get_product'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductsService/GetProduct', + request_serializer=products.GetProductRequest.serialize, + response_deserializer=products.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + products.ListProductsResponse]: + r"""Return a callable for the list products method over gRPC. + + Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + Returns: + Callable[[~.ListProductsRequest], + ~.ListProductsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_products' not in self._stubs: + self._stubs['list_products'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductsService/ListProducts', + request_serializer=products.ListProductsRequest.serialize, + response_deserializer=products.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + def close(self): + self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'ProductsServiceGrpcTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py new file mode 100644 index 000000000000..cff684bcb9f2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py @@ -0,0 +1,409 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import inspect +import json +import pickle +import logging as std_logging +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import exceptions as core_exceptions +from google.api_core import retry_async as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf.json_format import MessageToJson +import google.protobuf.message + +import grpc # type: ignore +import proto # type: ignore +from grpc.experimental import aio # type: ignore + +from google.shopping.merchant_products_v1beta.types import products +from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import ProductsServiceGrpcTransport + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + + +class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER + async def intercept_unary_unary(self, continuation, client_call_details, request): + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + if logging_enabled: # pragma: NO COVER + request_metadata = client_call_details.metadata + if isinstance(request, proto.Message): + request_payload = type(request).to_json(request) + elif isinstance(request, google.protobuf.message.Message): + request_payload = MessageToJson(request) + else: + request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + + request_metadata = { + key: value.decode("utf-8") if isinstance(value, bytes) else value + for key, value in request_metadata + } + grpc_request = { + "payload": request_payload, + "requestMethod": "grpc", + "metadata": dict(request_metadata), + } + _LOGGER.debug( + f"Sending request for {client_call_details.method}", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": str(client_call_details.method), + "request": grpc_request, + "metadata": grpc_request["metadata"], + }, + ) + response = await continuation(client_call_details, request) + if logging_enabled: # pragma: NO COVER + response_metadata = await response.trailing_metadata() + # Convert gRPC metadata `` to list of tuples + metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + result = await response + if isinstance(result, proto.Message): + response_payload = type(result).to_json(result) + elif isinstance(result, google.protobuf.message.Message): + response_payload = MessageToJson(result) + else: + response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + grpc_response = { + "payload": response_payload, + "metadata": metadata, + "status": "OK", + } + _LOGGER.debug( + f"Received response to rpc {client_call_details.method}.", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": str(client_call_details.method), + "response": grpc_response, + "metadata": grpc_response["metadata"], + }, + ) + return response + + +class ProductsServiceGrpcAsyncIOTransport(ProductsServiceTransport): + """gRPC AsyncIO backend transport for ProductsService. + + Service to use Product resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if a ``channel`` instance is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if a ``channel`` instance is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): + A ``Channel`` instance through which to make calls, or a Callable + that constructs and returns one. If set to None, ``self.create_channel`` + is used to create the channel. If a Callable is given, it will be called + with the same arguments as used in ``self.create_channel``. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if a ``channel`` instance is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if isinstance(channel, aio.Channel): + # Ignore credentials if a channel was passed. + credentials = None + self._ignore_credentials = True + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + # initialize with the provided callable or the default channel + channel_init = channel or type(self).create_channel + self._grpc_channel = channel_init( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + self._interceptor = _LoggingClientAIOInterceptor() + self._grpc_channel._unary_unary_interceptors.append(self._interceptor) + self._logged_channel = self._grpc_channel + self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + # Wrap messages. This must be done after self._logged_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + Awaitable[products.Product]]: + r"""Return a callable for the get product method over gRPC. + + Retrieves the processed product from your Merchant + Center account. + After inserting, updating, or deleting a product input, + it may take several minutes before the updated final + product can be retrieved. + + Returns: + Callable[[~.GetProductRequest], + Awaitable[~.Product]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_product' not in self._stubs: + self._stubs['get_product'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductsService/GetProduct', + request_serializer=products.GetProductRequest.serialize, + response_deserializer=products.Product.deserialize, + ) + return self._stubs['get_product'] + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + Awaitable[products.ListProductsResponse]]: + r"""Return a callable for the list products method over gRPC. + + Lists the processed products in your Merchant Center account. + The response might contain fewer items than specified by + ``pageSize``. Rely on ``pageToken`` to determine if there are + more items to be requested. + + After inserting, updating, or deleting a product input, it may + take several minutes before the updated processed product can be + retrieved. + + Returns: + Callable[[~.ListProductsRequest], + Awaitable[~.ListProductsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_products' not in self._stubs: + self._stubs['list_products'] = self._logged_channel.unary_unary( + '/google.shopping.merchant.products.v1beta.ProductsService/ListProducts', + request_serializer=products.ListProductsRequest.serialize, + response_deserializer=products.ListProductsResponse.deserialize, + ) + return self._stubs['list_products'] + + def _prep_wrapped_messages(self, client_info): + """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + self._wrapped_methods = { + self.get_product: self._wrap_method( + self.get_product, + default_timeout=None, + client_info=client_info, + ), + self.list_products: self._wrap_method( + self.list_products, + default_timeout=None, + client_info=client_info, + ), + } + + def _wrap_method(self, func, *args, **kwargs): + if self._wrap_with_kind: # pragma: NO COVER + kwargs["kind"] = self.kind + return gapic_v1.method_async.wrap_method(func, *args, **kwargs) + + def close(self): + return self._logged_channel.close() + + @property + def kind(self) -> str: + return "grpc_asyncio" + + +__all__ = ( + 'ProductsServiceGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py new file mode 100644 index 000000000000..ec18bf51f534 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py @@ -0,0 +1,542 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import logging +import json # type: ignore + +from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import gapic_v1 +import google.protobuf + +from google.protobuf import json_format + +from requests import __version__ as requests_version +import dataclasses +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + + +from google.shopping.merchant_products_v1beta.types import products + + +from .rest_base import _BaseProductsServiceRestTransport +from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=f"requests@{requests_version}", +) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + + +class ProductsServiceRestInterceptor: + """Interceptor for ProductsService. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the ProductsServiceRestTransport. + + .. code-block:: python + class MyCustomProductsServiceInterceptor(ProductsServiceRestInterceptor): + def pre_get_product(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_product(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_products(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_products(self, response): + logging.log(f"Received response: {response}") + return response + + transport = ProductsServiceRestTransport(interceptor=MyCustomProductsServiceInterceptor()) + client = ProductsServiceClient(transport=transport) + + + """ + def pre_get_product(self, request: products.GetProductRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.GetProductRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for get_product + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductsService server. + """ + return request, metadata + + def post_get_product(self, response: products.Product) -> products.Product: + """Post-rpc interceptor for get_product + + DEPRECATED. Please use the `post_get_product_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductsService server but before + it is returned to user code. This `post_get_product` interceptor runs + before the `post_get_product_with_metadata` interceptor. + """ + return response + + def post_get_product_with_metadata(self, response: products.Product, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.Product, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_product + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductsService server but before it is returned to user code. + + We recommend only using this `post_get_product_with_metadata` + interceptor in new development instead of the `post_get_product` interceptor. + When both interceptors are used, this `post_get_product_with_metadata` interceptor runs after the + `post_get_product` interceptor. The (possibly modified) response returned by + `post_get_product` will be passed to + `post_get_product_with_metadata`. + """ + return response, metadata + + def pre_list_products(self, request: products.ListProductsRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + """Pre-rpc interceptor for list_products + + Override in a subclass to manipulate the request or metadata + before they are sent to the ProductsService server. + """ + return request, metadata + + def post_list_products(self, response: products.ListProductsResponse) -> products.ListProductsResponse: + """Post-rpc interceptor for list_products + + DEPRECATED. Please use the `post_list_products_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the ProductsService server but before + it is returned to user code. This `post_list_products` interceptor runs + before the `post_list_products_with_metadata` interceptor. + """ + return response + + def post_list_products_with_metadata(self, response: products.ListProductsResponse, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsResponse, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for list_products + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the ProductsService server but before it is returned to user code. + + We recommend only using this `post_list_products_with_metadata` + interceptor in new development instead of the `post_list_products` interceptor. + When both interceptors are used, this `post_list_products_with_metadata` interceptor runs after the + `post_list_products` interceptor. The (possibly modified) response returned by + `post_list_products` will be passed to + `post_list_products_with_metadata`. + """ + return response, metadata + + +@dataclasses.dataclass +class ProductsServiceRestStub: + _session: AuthorizedSession + _host: str + _interceptor: ProductsServiceRestInterceptor + + +class ProductsServiceRestTransport(_BaseProductsServiceRestTransport): + """REST backend synchronous transport for ProductsService. + + Service to use Product resource. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[ProductsServiceRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + url_scheme=url_scheme, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or ProductsServiceRestInterceptor() + self._prep_wrapped_messages(client_info) + + class _GetProduct(_BaseProductsServiceRestTransport._BaseGetProduct, ProductsServiceRestStub): + def __hash__(self): + return hash("ProductsServiceRestTransport.GetProduct") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__(self, + request: products.GetProductRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> products.Product: + r"""Call the get product method over HTTP. + + Args: + request (~.products.GetProductRequest): + The request object. Request message for the GetProduct + method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.products.Product: + The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] + after applying rules and supplemental data sources. This + processed product matches what is shown in your Merchant + Center account. Each product is built from exactly one + primary data source product input, and multiple + supplemental data source inputs. After inserting, + updating, or deleting a product input, it may take + several minutes before the updated processed product can + be retrieved. + + All fields in the processed product and its sub-messages + match the name of their corresponding attribute in the + `Product data + specification `__ + with some exceptions. + + """ + + http_options = _BaseProductsServiceRestTransport._BaseGetProduct._get_http_options() + + request, metadata = self._interceptor.pre_get_product(request, metadata) + transcoded_request = _BaseProductsServiceRestTransport._BaseGetProduct._get_transcoded_request(http_options, request) + + # Jsonify the query params + query_params = _BaseProductsServiceRestTransport._BaseGetProduct._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1beta.ProductsServiceClient.GetProduct", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": "GetProduct", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductsServiceRestTransport._GetProduct._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = products.Product() + pb_resp = products.Product.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_get_product(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_product_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = products.Product.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1beta.ProductsServiceClient.get_product", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": "GetProduct", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _ListProducts(_BaseProductsServiceRestTransport._BaseListProducts, ProductsServiceRestStub): + def __hash__(self): + return hash("ProductsServiceRestTransport.ListProducts") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None): + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__(self, + request: products.ListProductsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), + ) -> products.ListProductsResponse: + r"""Call the list products method over HTTP. + + Args: + request (~.products.ListProductsRequest): + The request object. Request message for the ListProducts + method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.products.ListProductsResponse: + Response message for the ListProducts + method. + + """ + + http_options = _BaseProductsServiceRestTransport._BaseListProducts._get_http_options() + + request, metadata = self._interceptor.pre_list_products(request, metadata) + transcoded_request = _BaseProductsServiceRestTransport._BaseListProducts._get_transcoded_request(http_options, request) + + # Jsonify the query params + query_params = _BaseProductsServiceRestTransport._BaseListProducts._get_query_params_json(transcoded_request) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) + method = transcoded_request['method'] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.shopping.merchant.products_v1beta.ProductsServiceClient.ListProducts", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": "ListProducts", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ProductsServiceRestTransport._ListProducts._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = products.ListProductsResponse() + pb_resp = products.ListProductsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_list_products(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_products_with_metadata(resp, response_metadata) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + try: + response_payload = products.ListProductsResponse.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.shopping.merchant.products_v1beta.ProductsServiceClient.list_products", + extra = { + "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", + "rpcName": "ListProducts", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + @property + def get_product(self) -> Callable[ + [products.GetProductRequest], + products.Product]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetProduct(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_products(self) -> Callable[ + [products.ListProductsRequest], + products.ListProductsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListProducts(self._session, self._host, self._interceptor) # type: ignore + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'ProductsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py new file mode 100644 index 000000000000..069cfe69d8b9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json # type: ignore +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union + + +from google.shopping.merchant_products_v1beta.types import products + + +class _BaseProductsServiceRestTransport(ProductsServiceTransport): + """Base REST backend transport for ProductsService. + + Note: This class is not meant to be used directly. Use its sync and + async sub-classes instead. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__(self, *, + host: str = 'merchantapi.googleapis.com', + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + Args: + host (Optional[str]): + The hostname to connect to (default: 'merchantapi.googleapis.com'). + credentials (Optional[Any]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + + class _BaseGetProduct: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/products/v1beta/{name=accounts/*/products/*}', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = products.GetProductRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductsServiceRestTransport._BaseGetProduct._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListProducts: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/products/v1beta/{parent=accounts/*}/products', + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = products.ListProductsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + use_integers_for_enums=True, + )) + query_params.update(_BaseProductsServiceRestTransport._BaseListProducts._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + +__all__=( + '_BaseProductsServiceRestTransport', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py new file mode 100644 index 000000000000..3d7f862c5cd3 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .productinputs import ( + DeleteProductInputRequest, + InsertProductInputRequest, + ProductInput, + UpdateProductInputRequest, +) +from .products import ( + GetProductRequest, + ListProductsRequest, + ListProductsResponse, + Product, +) +from .products_common import ( + Attributes, + AutomatedDiscounts, + Certification, + CloudExportAdditionalProperties, + FreeShippingThreshold, + Installment, + LoyaltyPoints, + LoyaltyProgram, + ProductDetail, + ProductDimension, + ProductStatus, + ProductStructuredDescription, + ProductStructuredTitle, + ProductSustainabilityIncentive, + ProductWeight, + Shipping, + ShippingDimension, + ShippingWeight, + SubscriptionCost, + Tax, + UnitPricingBaseMeasure, + UnitPricingMeasure, + SubscriptionPeriod, +) + +__all__ = ( + 'DeleteProductInputRequest', + 'InsertProductInputRequest', + 'ProductInput', + 'UpdateProductInputRequest', + 'GetProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + 'Product', + 'Attributes', + 'AutomatedDiscounts', + 'Certification', + 'CloudExportAdditionalProperties', + 'FreeShippingThreshold', + 'Installment', + 'LoyaltyPoints', + 'LoyaltyProgram', + 'ProductDetail', + 'ProductDimension', + 'ProductStatus', + 'ProductStructuredDescription', + 'ProductStructuredTitle', + 'ProductSustainabilityIncentive', + 'ProductWeight', + 'Shipping', + 'ShippingDimension', + 'ShippingWeight', + 'SubscriptionCost', + 'Tax', + 'UnitPricingBaseMeasure', + 'UnitPricingMeasure', + 'SubscriptionPeriod', +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py new file mode 100644 index 000000000000..723010bf9c61 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py @@ -0,0 +1,305 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import field_mask_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types + + +__protobuf__ = proto.module( + package='google.shopping.merchant.products.v1beta', + manifest={ + 'ProductInput', + 'InsertProductInputRequest', + 'UpdateProductInputRequest', + 'DeleteProductInputRequest', + }, +) + + +class ProductInput(proto.Message): + r"""This resource represents input data you submit for a product, not + the processed product that you see in Merchant Center, in Shopping + ads, or across Google surfaces. Product inputs, rules and + supplemental data source data are combined to create the processed + [Product][google.shopping.merchant.products.v1beta.Product]. For + more information, see `Manage + products `__. + + Required product input attributes to pass data validation checks are + primarily defined in the `Products Data + Specification `__. + + The following attributes are required: + [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], + [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] + and + [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. + + After inserting, updating, or deleting a product input, it may take + several minutes before the processed product can be retrieved. + + All fields in the product input and its sub-messages match the + English name of their corresponding attribute in the `Products Data + Specification `__ + with `some + exceptions `__. + The following reference documentation lists the field names in the + **camelCase** casing style while the Products Data Specification + lists the names in the **snake_case** casing style. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + name (str): + Identifier. The name of the product input. Format: + ``accounts/{account}/productInputs/{productinput}`` where + the last section ``productinput`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example for + product input name is + ``accounts/123/productInputs/online~en~US~sku123`` + product (str): + Output only. The name of the processed product. Format: + ``accounts/{account}/products/{product}`` + channel (google.shopping.type.types.Channel.ChannelEnum): + Immutable. The + `channel `__ + of the product. + offer_id (str): + Required. Immutable. Your unique identifier for the product. + This is the same for the product input and processed + product. Leading and trailing whitespaces are stripped and + multiple whitespaces are replaced by a single whitespace + upon submission. See the `products data + specification `__ + for details. + content_language (str): + Required. Immutable. The two-letter `ISO + 639-1 `__ language + code for the product. + feed_label (str): + Required. Immutable. The label that lets you categorize and + identify your products. The maximum allowed characters are + 20, and the supported characters are ``A-Z``, ``0-9``, + hyphen, and underscore. The feed label must not include any + spaces. For more information, see `Using feed + labels `__. + version_number (int): + Optional. Immutable. Represents the existing version + (freshness) of the product, which can be used to preserve + the right order when multiple updates are done at the same + time. + + If set, the insertion is prevented when version number is + lower than the current version number of the existing + product. Re-insertion (for example, product refresh after 30 + days) can be performed with the current ``version_number``. + + Only supported for insertions into primary data sources. Do + not set this field for updates. Do not set this field for + insertions into supplemental data sources. + + If the operation is prevented, the aborted exception will be + thrown. + + This field is a member of `oneof`_ ``_version_number``. + attributes (google.shopping.merchant_products_v1beta.types.Attributes): + Optional. A list of product attributes. + custom_attributes (MutableSequence[google.shopping.type.types.CustomAttribute]): + Optional. A list of custom (merchant-provided) attributes. + It can also be used for submitting any attribute of the data + specification in its generic form (for example, + ``{ "name": "size type", "value": "regular" }``). This is + useful for submitting attributes not explicitly exposed by + the API. Maximum allowed number of characters for each + custom attribute is 10240 (represents sum of characters for + name and value). Maximum 2500 custom attributes can be set + per product, with total size of 102.4kB. Underscores in + custom attribute names are replaced by spaces upon + insertion. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + product: str = proto.Field( + proto.STRING, + number=2, + ) + channel: types.Channel.ChannelEnum = proto.Field( + proto.ENUM, + number=3, + enum=types.Channel.ChannelEnum, + ) + offer_id: str = proto.Field( + proto.STRING, + number=4, + ) + content_language: str = proto.Field( + proto.STRING, + number=5, + ) + feed_label: str = proto.Field( + proto.STRING, + number=6, + ) + version_number: int = proto.Field( + proto.INT64, + number=7, + optional=True, + ) + attributes: products_common.Attributes = proto.Field( + proto.MESSAGE, + number=8, + message=products_common.Attributes, + ) + custom_attributes: MutableSequence[types.CustomAttribute] = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=types.CustomAttribute, + ) + + +class InsertProductInputRequest(proto.Message): + r"""Request message for the InsertProductInput method. + + Attributes: + parent (str): + Required. The account where this product will be inserted. + Format: ``accounts/{account}`` + product_input (google.shopping.merchant_products_v1beta.types.ProductInput): + Required. The product input to insert. + data_source (str): + Required. The primary or supplemental product data source + name. If the product already exists and data source provided + is different, then the product will be moved to a new data + source. For more information, see `Overview of Data sources + sub-API `__. + + Only API data sources are supported. + + Format: ``accounts/{account}/dataSources/{datasource}``. For + example, ``accounts/123456/dataSources/104628``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + product_input: 'ProductInput' = proto.Field( + proto.MESSAGE, + number=2, + message='ProductInput', + ) + data_source: str = proto.Field( + proto.STRING, + number=3, + ) + + +class UpdateProductInputRequest(proto.Message): + r"""Request message for the UpdateProductInput method. + The product (primary input) must exist for the update to + succeed. If the update is for a primary product input, the + existing primary product input must be from the same data + source. + + Attributes: + product_input (google.shopping.merchant_products_v1beta.types.ProductInput): + Required. The product input resource to + update. Information you submit will be applied + to the processed product as well. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. The list of product attributes to be updated. + + If the update mask is omitted, then it is treated as implied + field mask equivalent to all fields that are populated (have + a non-empty value). + + Attributes specified in the update mask without a value + specified in the body will be deleted from the product. + + Update mask can only be specified for top level fields in + attributes and custom attributes. + + To specify the update mask for custom attributes you need to + add the ``custom_attribute.`` prefix. + + Providing special "*" value for full product replacement is + not supported. + data_source (str): + Required. The primary or supplemental product data source + where ``data_source`` name identifies the product input to + be updated. + + Only API data sources are supported. + + Format: ``accounts/{account}/dataSources/{datasource}``. For + example, ``accounts/123456/dataSources/104628``. + """ + + product_input: 'ProductInput' = proto.Field( + proto.MESSAGE, + number=1, + message='ProductInput', + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + data_source: str = proto.Field( + proto.STRING, + number=3, + ) + + +class DeleteProductInputRequest(proto.Message): + r"""Request message for the DeleteProductInput method. + + Attributes: + name (str): + Required. The name of the product input resource to delete. + Format: ``accounts/{account}/productInputs/{product}`` where + the last section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example for + product name is + ``accounts/123/productInputs/online~en~US~sku123``. + data_source (str): + Required. The primary or supplemental data source from which + the product input should be deleted. Format: + ``accounts/{account}/dataSources/{datasource}``. For + example, ``accounts/123456/dataSources/104628``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + data_source: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py new file mode 100644 index 000000000000..6f066fa568f9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py @@ -0,0 +1,260 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types + + +__protobuf__ = proto.module( + package='google.shopping.merchant.products.v1beta', + manifest={ + 'Product', + 'GetProductRequest', + 'ListProductsRequest', + 'ListProductsResponse', + }, +) + + +class Product(proto.Message): + r"""The processed product, built from multiple [product + inputs][google.shopping.merchant.products.v1main.ProductInput] after + applying rules and supplemental data sources. This processed product + matches what is shown in your Merchant Center account. Each product + is built from exactly one primary data source product input, and + multiple supplemental data source inputs. After inserting, updating, + or deleting a product input, it may take several minutes before the + updated processed product can be retrieved. + + All fields in the processed product and its sub-messages match the + name of their corresponding attribute in the `Product data + specification `__ + with some exceptions. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + name (str): + The name of the product. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example for + product name is + ``accounts/123/products/online~en~US~sku123`` + channel (google.shopping.type.types.Channel.ChannelEnum): + Output only. The + `channel `__ + of the product. + offer_id (str): + Output only. Your unique identifier for the product. This is + the same for the product input and processed product. + Leading and trailing whitespaces are stripped and multiple + whitespaces are replaced by a single whitespace upon + submission. See the `product data + specification `__ + for details. + content_language (str): + Output only. The two-letter `ISO + 639-1 `__ language + code for the product. + feed_label (str): + Output only. The feed label lets you categorize and identify + your products. The maximum allowed characters is 20 and the + supported characters are\ ``A-Z``, ``0-9``, hyphen and + underscore. The feed label must not include any spaces. For + more information, see `Using feed + labels `__ + data_source (str): + Output only. The primary data source of the + product. + version_number (int): + Output only. Represents the existing version (freshness) of + the product, which can be used to preserve the right order + when multiple updates are done at the same time. + + If set, the insertion is prevented when version number is + lower than the current version number of the existing + product. Re-insertion (for example, product refresh after 30 + days) can be performed with the current ``version_number``. + + Only supported for insertions into primary data sources. + + If the operation is prevented, the aborted exception will be + thrown. + + This field is a member of `oneof`_ ``_version_number``. + attributes (google.shopping.merchant_products_v1beta.types.Attributes): + Output only. A list of product attributes. + custom_attributes (MutableSequence[google.shopping.type.types.CustomAttribute]): + Output only. A list of custom (merchant-provided) + attributes. It can also be used to submit any attribute of + the data specification in its generic form (for example, + ``{ "name": "size type", "value": "regular" }``). This is + useful for submitting attributes not explicitly exposed by + the API, such as additional attributes used for Buy on + Google. + product_status (google.shopping.merchant_products_v1beta.types.ProductStatus): + Output only. The status of a product, data + validation issues, that is, information about a + product computed asynchronously. + automated_discounts (google.shopping.merchant_products_v1beta.types.AutomatedDiscounts): + Output only. The automated discounts + information for the product. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + channel: types.Channel.ChannelEnum = proto.Field( + proto.ENUM, + number=2, + enum=types.Channel.ChannelEnum, + ) + offer_id: str = proto.Field( + proto.STRING, + number=3, + ) + content_language: str = proto.Field( + proto.STRING, + number=4, + ) + feed_label: str = proto.Field( + proto.STRING, + number=5, + ) + data_source: str = proto.Field( + proto.STRING, + number=6, + ) + version_number: int = proto.Field( + proto.INT64, + number=7, + optional=True, + ) + attributes: products_common.Attributes = proto.Field( + proto.MESSAGE, + number=8, + message=products_common.Attributes, + ) + custom_attributes: MutableSequence[types.CustomAttribute] = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=types.CustomAttribute, + ) + product_status: products_common.ProductStatus = proto.Field( + proto.MESSAGE, + number=10, + message=products_common.ProductStatus, + ) + automated_discounts: products_common.AutomatedDiscounts = proto.Field( + proto.MESSAGE, + number=12, + message=products_common.AutomatedDiscounts, + ) + + +class GetProductRequest(proto.Message): + r"""Request message for the GetProduct method. + + Attributes: + name (str): + Required. The name of the product to retrieve. Format: + ``accounts/{account}/products/{product}`` where the last + section ``product`` consists of 4 parts: + ``channel~content_language~feed_label~offer_id`` example for + product name is + ``accounts/123/products/online~en~US~sku123`` + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ListProductsRequest(proto.Message): + r"""Request message for the ListProducts method. + + Attributes: + parent (str): + Required. The account to list processed products for. + Format: ``accounts/{account}`` + page_size (int): + The maximum number of products to return. The + service may return fewer than this value. + The maximum value is 1000; values above 1000 + will be coerced to 1000. If unspecified, the + maximum number of products will be returned. + page_token (str): + A page token, received from a previous ``ListProducts`` + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListProducts`` must match the call that provided the page + token. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListProductsResponse(proto.Message): + r"""Response message for the ListProducts method. + + Attributes: + products (MutableSequence[google.shopping.merchant_products_v1beta.types.Product]): + The processed products from the specified + account. These are your processed products after + applying rules and supplemental data sources. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + """ + + @property + def raw_page(self): + return self + + products: MutableSequence['Product'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Product', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py new file mode 100644 index 000000000000..ceb744ff33fa --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py @@ -0,0 +1,2109 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore +from google.shopping.type.types import types +from google.type import interval_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.shopping.merchant.products.v1beta', + manifest={ + 'SubscriptionPeriod', + 'Attributes', + 'Tax', + 'ShippingWeight', + 'ShippingDimension', + 'UnitPricingBaseMeasure', + 'UnitPricingMeasure', + 'SubscriptionCost', + 'Installment', + 'LoyaltyPoints', + 'LoyaltyProgram', + 'Shipping', + 'FreeShippingThreshold', + 'ProductDetail', + 'Certification', + 'ProductStructuredTitle', + 'ProductStructuredDescription', + 'ProductDimension', + 'ProductWeight', + 'ProductStatus', + 'CloudExportAdditionalProperties', + 'ProductSustainabilityIncentive', + 'AutomatedDiscounts', + }, +) + + +class SubscriptionPeriod(proto.Enum): + r"""The subscription period of the product. + + Values: + SUBSCRIPTION_PERIOD_UNSPECIFIED (0): + Indicates that the subscription period is + unspecified. + MONTH (1): + Indicates that the subscription period is + month. + YEAR (2): + Indicates that the subscription period is + year. + """ + SUBSCRIPTION_PERIOD_UNSPECIFIED = 0 + MONTH = 1 + YEAR = 2 + + +class Attributes(proto.Message): + r"""Attributes. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + identifier_exists (bool): + Set this value to false when the item does + not have unique product identifiers appropriate + to its category, such as GTIN, MPN, and brand. + Defaults to true, if not provided. + + This field is a member of `oneof`_ ``_identifier_exists``. + is_bundle (bool): + Whether the item is a business-defined sub-API. A [sub-API] + (https://support.google.com/merchants/answer/6324449) is a + custom grouping of different products sold by a business for + a single price. + + This field is a member of `oneof`_ ``_is_bundle``. + title (str): + Title of the item. + + This field is a member of `oneof`_ ``_title``. + description (str): + Description of the item. + + This field is a member of `oneof`_ ``_description``. + link (str): + URL directly linking to your item's page on + your online store. + + This field is a member of `oneof`_ ``_link``. + mobile_link (str): + URL for the mobile-optimized version of your + item's landing page. + + This field is a member of `oneof`_ ``_mobile_link``. + canonical_link (str): + URL for the canonical version of your item's + landing page. + + This field is a member of `oneof`_ ``_canonical_link``. + image_link (str): + URL of an image of the item. + + This field is a member of `oneof`_ ``_image_link``. + additional_image_links (MutableSequence[str]): + Additional URLs of images of the item. + expiration_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item should expire, as specified upon + insertion, in `ISO + 8601 `__ format. The + actual expiration date is exposed in ``productstatuses`` as + `googleExpirationDate `__ + and might be earlier if ``expirationDate`` is too far in the + future. + disclosure_date (google.protobuf.timestamp_pb2.Timestamp): + The date time when an offer becomes visible in search + results across Google’s YouTube surfaces, in `ISO + 8601 `__ format. See + `Disclosure + date `__ + for more information. + adult (bool): + Set to true if the item is targeted towards + adults. + + This field is a member of `oneof`_ ``_adult``. + age_group (str): + Target `age + group `__ + of the item. + + This field is a member of `oneof`_ ``_age_group``. + availability (str): + `Availability `__ + status of the item. For example, "in_stock" or + "out_of_stock". + + This field is a member of `oneof`_ ``_availability``. + availability_date (google.protobuf.timestamp_pb2.Timestamp): + The day a pre-ordered product becomes available for + delivery, in `ISO + 8601 `__ format. + brand (str): + `Brand `__ + of the item. For example, "Google". + + This field is a member of `oneof`_ ``_brand``. + color (str): + `Color `__ + of the item. For example, "red". + + This field is a member of `oneof`_ ``_color``. + condition (str): + `Condition `__ + or state of the item. For example, "new" or "used". + + This field is a member of `oneof`_ ``_condition``. + gender (str): + Target + `gender `__ + of the item. For example, "male" or "female". + + This field is a member of `oneof`_ ``_gender``. + google_product_category (str): + Google's category of the item (see `Google product + taxonomy `__). + When querying products, this field will contain the user + provided value. There is currently no way to get back the + auto assigned google product categories through the API. + + This field is a member of `oneof`_ ``_google_product_category``. + gtin (MutableSequence[str]): + Global Trade Item Numbers + (`GTIN `__) + of the item. You can provide up to 10 GTINs. + + Deprecated: Use ``gtins`` instead. + gtins (MutableSequence[str]): + Global Trade Item Numbers + (`GTIN `__) + of the item. You can provide up to 10 GTINs. + item_group_id (str): + Shared identifier for all variants of the + same product. + + This field is a member of `oneof`_ ``_item_group_id``. + material (str): + The + `material `__ + of which the item is made. For example, "Leather" or + "Cotton". + + This field is a member of `oneof`_ ``_material``. + mpn (str): + Manufacturer Part Number + (`MPN `__) + of the item. + + This field is a member of `oneof`_ ``_mpn``. + pattern (str): + The item's + `pattern `__. + For example, polka dots. + + This field is a member of `oneof`_ ``_pattern``. + price (google.shopping.type.types.Price): + Price of the item. + maximum_retail_price (google.shopping.type.types.Price): + Maximum retail price (MRP) of the item. + Applicable to India only. + installment (google.shopping.merchant_products_v1beta.types.Installment): + Number and amount of installments to pay for + an item. + subscription_cost (google.shopping.merchant_products_v1beta.types.SubscriptionCost): + Number of periods (months or years) and + amount of payment per period for an item with an + associated subscription contract. + loyalty_points (google.shopping.merchant_products_v1beta.types.LoyaltyPoints): + Loyalty points that users receive after + purchasing the item. Japan only. + loyalty_programs (MutableSequence[google.shopping.merchant_products_v1beta.types.LoyaltyProgram]): + A list of loyalty program information that is + used to surface loyalty benefits (for example, + better pricing, points, etc) to the user of this + item. + product_types (MutableSequence[str]): + Categories of the item (formatted as in `product data + specification `__). + sale_price (google.shopping.type.types.Price): + Advertised sale price of the item. + sale_price_effective_date (google.type.interval_pb2.Interval): + Date range during which the item is on sale, see `product + data + specification `__. + sell_on_google_quantity (int): + The quantity of the product that is available + for selling on Google. Supported only for online + products. + + This field is a member of `oneof`_ ``_sell_on_google_quantity``. + product_height (google.shopping.merchant_products_v1beta.types.ProductDimension): + The height of the product in the units + provided. The value must be between + 0 (exclusive) and 3000 (inclusive). + product_length (google.shopping.merchant_products_v1beta.types.ProductDimension): + The length of the product in the units + provided. The value must be between 0 + (exclusive) and 3000 (inclusive). + product_width (google.shopping.merchant_products_v1beta.types.ProductDimension): + The width of the product in the units + provided. The value must be between 0 + (exclusive) and 3000 (inclusive). + product_weight (google.shopping.merchant_products_v1beta.types.ProductWeight): + The weight of the product in the units + provided. The value must be between 0 + (exclusive) and 2000 (inclusive). + shipping (MutableSequence[google.shopping.merchant_products_v1beta.types.Shipping]): + Shipping rules. + free_shipping_threshold (MutableSequence[google.shopping.merchant_products_v1beta.types.FreeShippingThreshold]): + Conditions to be met for a product to have + free shipping. + shipping_weight (google.shopping.merchant_products_v1beta.types.ShippingWeight): + Weight of the item for shipping. + shipping_length (google.shopping.merchant_products_v1beta.types.ShippingDimension): + Length of the item for shipping. + shipping_width (google.shopping.merchant_products_v1beta.types.ShippingDimension): + Width of the item for shipping. + shipping_height (google.shopping.merchant_products_v1beta.types.ShippingDimension): + Height of the item for shipping. + max_handling_time (int): + Maximal product handling time (in business + days). + + This field is a member of `oneof`_ ``_max_handling_time``. + min_handling_time (int): + Minimal product handling time (in business + days). + + This field is a member of `oneof`_ ``_min_handling_time``. + shipping_label (str): + The shipping label of the product, used to + group product in account-level shipping rules. + + This field is a member of `oneof`_ ``_shipping_label``. + transit_time_label (str): + The transit time label of the product, used + to group product in account-level transit time + tables. + + This field is a member of `oneof`_ ``_transit_time_label``. + size (str): + Size of the item. Only one value is allowed. For variants + with different sizes, insert a separate product for each + size with the same ``itemGroupId`` value, see + `Size `__. + + This field is a member of `oneof`_ ``_size``. + size_system (str): + System in which the size is specified. Recommended for + apparel items. For example, "US", "UK", "DE". For more + information, see `Size + system `__. + + This field is a member of `oneof`_ ``_size_system``. + size_types (MutableSequence[str]): + The cut of the item. It can be used to represent combined + size types for apparel items. Maximum two of size types can + be provided, see `Size + type `__. + For example, "petite", "plus size". + taxes (MutableSequence[google.shopping.merchant_products_v1beta.types.Tax]): + Tax information. + tax_category (str): + The `tax + category `__ + of the product. + + This field is a member of `oneof`_ ``_tax_category``. + energy_efficiency_class (str): + The energy efficiency class as defined in EU + directive 2010/30/EU. + + This field is a member of `oneof`_ ``_energy_efficiency_class``. + min_energy_efficiency_class (str): + The energy efficiency class as defined in EU + directive 2010/30/EU. + + This field is a member of `oneof`_ ``_min_energy_efficiency_class``. + max_energy_efficiency_class (str): + The energy efficiency class as defined in EU + directive 2010/30/EU. + + This field is a member of `oneof`_ ``_max_energy_efficiency_class``. + unit_pricing_measure (google.shopping.merchant_products_v1beta.types.UnitPricingMeasure): + The measure and dimension of an item. + unit_pricing_base_measure (google.shopping.merchant_products_v1beta.types.UnitPricingBaseMeasure): + The preference of the denominator of the unit + price. + multipack (int): + The number of identical products in a + business-defined multipack. + + This field is a member of `oneof`_ ``_multipack``. + ads_grouping (str): + Used to group items in an arbitrary way. Only for CPA%, + discouraged otherwise. For more information, see `Display + ads + attribute `__. + + This field is a member of `oneof`_ ``_ads_grouping``. + ads_labels (MutableSequence[str]): + Similar to ads_grouping, but only works on CPC. + ads_redirect (str): + Allows advertisers to override the item URL + when the product is shown within the context of + Product ads. + + This field is a member of `oneof`_ ``_ads_redirect``. + cost_of_goods_sold (google.shopping.type.types.Price): + Cost of goods sold. Used for gross profit + reporting. + product_details (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductDetail]): + Technical specification or additional product + details. + product_highlights (MutableSequence[str]): + Bullet points describing the most relevant `product + highlights `__. + display_ads_id (str): + An identifier for an item for dynamic + remarketing campaigns. + + This field is a member of `oneof`_ ``_display_ads_id``. + display_ads_similar_ids (MutableSequence[str]): + Advertiser-specified recommendations. For more information, + see `Display ads attribute + specification `__. + display_ads_title (str): + Title of an item for dynamic remarketing + campaigns. + + This field is a member of `oneof`_ ``_display_ads_title``. + display_ads_link (str): + URL directly to your item's landing page for + dynamic remarketing campaigns. + + This field is a member of `oneof`_ ``_display_ads_link``. + display_ads_value (float): + Offer margin for dynamic remarketing campaigns. For more + information, see `Display ads + attribute `__. + + This field is a member of `oneof`_ ``_display_ads_value``. + promotion_ids (MutableSequence[str]): + The unique ID of a promotion. + pickup_method (str): + The + `pickup `__ + option for the item. + + This field is a member of `oneof`_ ``_pickup_method``. + pickup_sla (str): + Item store pickup timeline. For more information, see + `Pickup + SLA `__. + + This field is a member of `oneof`_ ``_pickup_sla``. + link_template (str): + `Link + template `__ + for business hosted local storefront. + + This field is a member of `oneof`_ ``_link_template``. + mobile_link_template (str): + `Link + template `__ + for business hosted local storefront optimized for mobile + devices. + + This field is a member of `oneof`_ ``_mobile_link_template``. + custom_label_0 (str): + `Custom label + 0 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_0``. + custom_label_1 (str): + `Custom label + 1 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_1``. + custom_label_2 (str): + `Custom label + 2 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_2``. + custom_label_3 (str): + `Custom label + 3 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_3``. + custom_label_4 (str): + `Custom label + 4 `__ + for custom grouping of items in a Shopping campaign. + + This field is a member of `oneof`_ ``_custom_label_4``. + included_destinations (MutableSequence[str]): + The list of destinations to include for this target + (corresponds to checked check boxes in Merchant Center). + Default destinations are always included unless provided in + ``excludedDestinations``. + + For more information, see `Included + destination `__. + + Note: We recommend setting destinations on datasources level + for most use cases. Use this field within products to only + setup exceptions. + excluded_destinations (MutableSequence[str]): + The list of destinations to exclude for this target + (corresponds to unchecked check boxes in Merchant Center). + + For more information, see `Excluded + destination `__. + + Note: We recommend setting destinations on datasources level + for most use cases. Use this field within products to only + setup exceptions. + shopping_ads_excluded_countries (MutableSequence[str]): + List of country codes `(ISO 3166-1 + alpha-2) `__ + to exclude the offer from Shopping Ads destination. + Countries from this list are removed from countries + configured in data source settings. + external_seller_id (str): + Required for multi-seller accounts. Use this + attribute if you're a marketplace uploading + products for various sellers to your + multi-seller account. + + This field is a member of `oneof`_ ``_external_seller_id``. + pause (str): + Publication of this item will be temporarily + `paused `__. + + This field is a member of `oneof`_ ``_pause``. + lifestyle_image_links (MutableSequence[str]): + Additional URLs of lifestyle images of the item, used to + explicitly identify images that showcase your item in a + real-world context. See the `Help Center + article `__ + for more information. + cloud_export_additional_properties (MutableSequence[google.shopping.merchant_products_v1beta.types.CloudExportAdditionalProperties]): + Extra fields to export to the Cloud Retail + program. + virtual_model_link (str): + URL of the 3D image of the item. See the `Help Center + article `__ + for more information. + + This field is a member of `oneof`_ ``_virtual_model_link``. + certifications (MutableSequence[google.shopping.merchant_products_v1beta.types.Certification]): + Product Certifications, for example for energy efficiency + labeling of products recorded in the `EU + EPREL `__ database. + See the `Help + Center `__ + article for more information. + structured_title (google.shopping.merchant_products_v1beta.types.ProductStructuredTitle): + Structured title, for algorithmically + (AI)-generated titles. + + This field is a member of `oneof`_ ``_structured_title``. + structured_description (google.shopping.merchant_products_v1beta.types.ProductStructuredDescription): + Structured description, for algorithmically + (AI)-generated descriptions. + + This field is a member of `oneof`_ ``_structured_description``. + auto_pricing_min_price (google.shopping.type.types.Price): + A safeguard in the [automated discounts] + (https://support.google.com/merchants/answer/10295759) and + "Dynamic Promotions" + (https://support.google.com/merchants/answer/13949249) + projects, ensuring that discounts on business offers do not + fall below this value, thereby preserving the offer's value + and profitability. + sustainability_incentives (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductSustainabilityIncentive]): + The list of sustainability incentive + programs. + """ + + identifier_exists: bool = proto.Field( + proto.BOOL, + number=4, + optional=True, + ) + is_bundle: bool = proto.Field( + proto.BOOL, + number=5, + optional=True, + ) + title: str = proto.Field( + proto.STRING, + number=6, + optional=True, + ) + description: str = proto.Field( + proto.STRING, + number=7, + optional=True, + ) + link: str = proto.Field( + proto.STRING, + number=8, + optional=True, + ) + mobile_link: str = proto.Field( + proto.STRING, + number=9, + optional=True, + ) + canonical_link: str = proto.Field( + proto.STRING, + number=10, + optional=True, + ) + image_link: str = proto.Field( + proto.STRING, + number=11, + optional=True, + ) + additional_image_links: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=12, + ) + expiration_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=16, + message=timestamp_pb2.Timestamp, + ) + disclosure_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=79, + message=timestamp_pb2.Timestamp, + ) + adult: bool = proto.Field( + proto.BOOL, + number=17, + optional=True, + ) + age_group: str = proto.Field( + proto.STRING, + number=18, + optional=True, + ) + availability: str = proto.Field( + proto.STRING, + number=19, + optional=True, + ) + availability_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=20, + message=timestamp_pb2.Timestamp, + ) + brand: str = proto.Field( + proto.STRING, + number=21, + optional=True, + ) + color: str = proto.Field( + proto.STRING, + number=22, + optional=True, + ) + condition: str = proto.Field( + proto.STRING, + number=23, + optional=True, + ) + gender: str = proto.Field( + proto.STRING, + number=24, + optional=True, + ) + google_product_category: str = proto.Field( + proto.STRING, + number=25, + optional=True, + ) + gtin: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=26, + ) + gtins: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=140, + ) + item_group_id: str = proto.Field( + proto.STRING, + number=27, + optional=True, + ) + material: str = proto.Field( + proto.STRING, + number=28, + optional=True, + ) + mpn: str = proto.Field( + proto.STRING, + number=29, + optional=True, + ) + pattern: str = proto.Field( + proto.STRING, + number=30, + optional=True, + ) + price: types.Price = proto.Field( + proto.MESSAGE, + number=31, + message=types.Price, + ) + maximum_retail_price: types.Price = proto.Field( + proto.MESSAGE, + number=139, + message=types.Price, + ) + installment: 'Installment' = proto.Field( + proto.MESSAGE, + number=32, + message='Installment', + ) + subscription_cost: 'SubscriptionCost' = proto.Field( + proto.MESSAGE, + number=33, + message='SubscriptionCost', + ) + loyalty_points: 'LoyaltyPoints' = proto.Field( + proto.MESSAGE, + number=34, + message='LoyaltyPoints', + ) + loyalty_programs: MutableSequence['LoyaltyProgram'] = proto.RepeatedField( + proto.MESSAGE, + number=136, + message='LoyaltyProgram', + ) + product_types: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=35, + ) + sale_price: types.Price = proto.Field( + proto.MESSAGE, + number=36, + message=types.Price, + ) + sale_price_effective_date: interval_pb2.Interval = proto.Field( + proto.MESSAGE, + number=37, + message=interval_pb2.Interval, + ) + sell_on_google_quantity: int = proto.Field( + proto.INT64, + number=38, + optional=True, + ) + product_height: 'ProductDimension' = proto.Field( + proto.MESSAGE, + number=119, + message='ProductDimension', + ) + product_length: 'ProductDimension' = proto.Field( + proto.MESSAGE, + number=120, + message='ProductDimension', + ) + product_width: 'ProductDimension' = proto.Field( + proto.MESSAGE, + number=121, + message='ProductDimension', + ) + product_weight: 'ProductWeight' = proto.Field( + proto.MESSAGE, + number=122, + message='ProductWeight', + ) + shipping: MutableSequence['Shipping'] = proto.RepeatedField( + proto.MESSAGE, + number=39, + message='Shipping', + ) + free_shipping_threshold: MutableSequence['FreeShippingThreshold'] = proto.RepeatedField( + proto.MESSAGE, + number=135, + message='FreeShippingThreshold', + ) + shipping_weight: 'ShippingWeight' = proto.Field( + proto.MESSAGE, + number=40, + message='ShippingWeight', + ) + shipping_length: 'ShippingDimension' = proto.Field( + proto.MESSAGE, + number=41, + message='ShippingDimension', + ) + shipping_width: 'ShippingDimension' = proto.Field( + proto.MESSAGE, + number=42, + message='ShippingDimension', + ) + shipping_height: 'ShippingDimension' = proto.Field( + proto.MESSAGE, + number=43, + message='ShippingDimension', + ) + max_handling_time: int = proto.Field( + proto.INT64, + number=44, + optional=True, + ) + min_handling_time: int = proto.Field( + proto.INT64, + number=45, + optional=True, + ) + shipping_label: str = proto.Field( + proto.STRING, + number=46, + optional=True, + ) + transit_time_label: str = proto.Field( + proto.STRING, + number=47, + optional=True, + ) + size: str = proto.Field( + proto.STRING, + number=48, + optional=True, + ) + size_system: str = proto.Field( + proto.STRING, + number=49, + optional=True, + ) + size_types: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=50, + ) + taxes: MutableSequence['Tax'] = proto.RepeatedField( + proto.MESSAGE, + number=51, + message='Tax', + ) + tax_category: str = proto.Field( + proto.STRING, + number=52, + optional=True, + ) + energy_efficiency_class: str = proto.Field( + proto.STRING, + number=53, + optional=True, + ) + min_energy_efficiency_class: str = proto.Field( + proto.STRING, + number=54, + optional=True, + ) + max_energy_efficiency_class: str = proto.Field( + proto.STRING, + number=55, + optional=True, + ) + unit_pricing_measure: 'UnitPricingMeasure' = proto.Field( + proto.MESSAGE, + number=56, + message='UnitPricingMeasure', + ) + unit_pricing_base_measure: 'UnitPricingBaseMeasure' = proto.Field( + proto.MESSAGE, + number=57, + message='UnitPricingBaseMeasure', + ) + multipack: int = proto.Field( + proto.INT64, + number=58, + optional=True, + ) + ads_grouping: str = proto.Field( + proto.STRING, + number=59, + optional=True, + ) + ads_labels: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=60, + ) + ads_redirect: str = proto.Field( + proto.STRING, + number=61, + optional=True, + ) + cost_of_goods_sold: types.Price = proto.Field( + proto.MESSAGE, + number=62, + message=types.Price, + ) + product_details: MutableSequence['ProductDetail'] = proto.RepeatedField( + proto.MESSAGE, + number=63, + message='ProductDetail', + ) + product_highlights: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=64, + ) + display_ads_id: str = proto.Field( + proto.STRING, + number=65, + optional=True, + ) + display_ads_similar_ids: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=66, + ) + display_ads_title: str = proto.Field( + proto.STRING, + number=67, + optional=True, + ) + display_ads_link: str = proto.Field( + proto.STRING, + number=68, + optional=True, + ) + display_ads_value: float = proto.Field( + proto.DOUBLE, + number=69, + optional=True, + ) + promotion_ids: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=70, + ) + pickup_method: str = proto.Field( + proto.STRING, + number=80, + optional=True, + ) + pickup_sla: str = proto.Field( + proto.STRING, + number=81, + optional=True, + ) + link_template: str = proto.Field( + proto.STRING, + number=82, + optional=True, + ) + mobile_link_template: str = proto.Field( + proto.STRING, + number=83, + optional=True, + ) + custom_label_0: str = proto.Field( + proto.STRING, + number=71, + optional=True, + ) + custom_label_1: str = proto.Field( + proto.STRING, + number=72, + optional=True, + ) + custom_label_2: str = proto.Field( + proto.STRING, + number=73, + optional=True, + ) + custom_label_3: str = proto.Field( + proto.STRING, + number=74, + optional=True, + ) + custom_label_4: str = proto.Field( + proto.STRING, + number=75, + optional=True, + ) + included_destinations: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=76, + ) + excluded_destinations: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=77, + ) + shopping_ads_excluded_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=78, + ) + external_seller_id: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + pause: str = proto.Field( + proto.STRING, + number=13, + optional=True, + ) + lifestyle_image_links: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=14, + ) + cloud_export_additional_properties: MutableSequence['CloudExportAdditionalProperties'] = proto.RepeatedField( + proto.MESSAGE, + number=84, + message='CloudExportAdditionalProperties', + ) + virtual_model_link: str = proto.Field( + proto.STRING, + number=130, + optional=True, + ) + certifications: MutableSequence['Certification'] = proto.RepeatedField( + proto.MESSAGE, + number=123, + message='Certification', + ) + structured_title: 'ProductStructuredTitle' = proto.Field( + proto.MESSAGE, + number=132, + optional=True, + message='ProductStructuredTitle', + ) + structured_description: 'ProductStructuredDescription' = proto.Field( + proto.MESSAGE, + number=133, + optional=True, + message='ProductStructuredDescription', + ) + auto_pricing_min_price: types.Price = proto.Field( + proto.MESSAGE, + number=124, + message=types.Price, + ) + sustainability_incentives: MutableSequence['ProductSustainabilityIncentive'] = proto.RepeatedField( + proto.MESSAGE, + number=138, + message='ProductSustainabilityIncentive', + ) + + +class Tax(proto.Message): + r"""The Tax of the product. + + Attributes: + rate (float): + The percentage of tax rate that applies to + the item price. + country (str): + The country within which the item is taxed, specified as a + `CLDR territory + code `__. + region (str): + The geographic region to which the tax rate + applies. + tax_ship (bool): + Set to true if tax is charged on shipping. + location_id (int): + The numeric ID of a location that the tax rate applies to as + defined in the `AdWords + API `__. + postal_code (str): + The postal code range that the tax rate applies to, + represented by a ZIP code, a ZIP code prefix using \* + wildcard, a range between two ZIP codes or two ZIP code + prefixes of equal length. Examples: 94114, 94*, 94002-95460, + 94*-95*. + """ + + rate: float = proto.Field( + proto.DOUBLE, + number=1, + ) + country: str = proto.Field( + proto.STRING, + number=2, + ) + region: str = proto.Field( + proto.STRING, + number=3, + ) + tax_ship: bool = proto.Field( + proto.BOOL, + number=4, + ) + location_id: int = proto.Field( + proto.INT64, + number=5, + ) + postal_code: str = proto.Field( + proto.STRING, + number=6, + ) + + +class ShippingWeight(proto.Message): + r"""The ShippingWeight of the product. + + Attributes: + value (float): + The weight of the product used to calculate + the shipping cost of the item. + unit (str): + The unit of value. + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ShippingDimension(proto.Message): + r"""The ShippingDimension of the product. + + Attributes: + value (float): + The dimension of the product used to + calculate the shipping cost of the item. + unit (str): + The unit of value. + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class UnitPricingBaseMeasure(proto.Message): + r"""The UnitPricingBaseMeasure of the product. + + Attributes: + value (int): + The denominator of the unit price. + unit (str): + The unit of the denominator. + """ + + value: int = proto.Field( + proto.INT64, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class UnitPricingMeasure(proto.Message): + r"""The UnitPricingMeasure of the product. + + Attributes: + value (float): + The measure of an item. + unit (str): + The unit of the measure. + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class SubscriptionCost(proto.Message): + r"""The SubscriptionCost of the product. + + Attributes: + period (google.shopping.merchant_products_v1beta.types.SubscriptionPeriod): + The type of subscription period. Supported values are: + + - "``month``" + - "``year``". + period_length (int): + The number of subscription periods the buyer + has to pay. + amount (google.shopping.type.types.Price): + The amount the buyer has to pay per + subscription period. + """ + + period: 'SubscriptionPeriod' = proto.Field( + proto.ENUM, + number=1, + enum='SubscriptionPeriod', + ) + period_length: int = proto.Field( + proto.INT64, + number=2, + ) + amount: types.Price = proto.Field( + proto.MESSAGE, + number=3, + message=types.Price, + ) + + +class Installment(proto.Message): + r"""A message that represents installment. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + months (int): + The number of installments the buyer has to + pay. + amount (google.shopping.type.types.Price): + The amount the buyer has to pay per month. + downpayment (google.shopping.type.types.Price): + The up-front down payment amount the buyer + has to pay. + + This field is a member of `oneof`_ ``_downpayment``. + credit_type (str): + Type of installment payments. Supported values are: + + - "``finance``" + - "``lease``". + + This field is a member of `oneof`_ ``_credit_type``. + """ + + months: int = proto.Field( + proto.INT64, + number=1, + ) + amount: types.Price = proto.Field( + proto.MESSAGE, + number=2, + message=types.Price, + ) + downpayment: types.Price = proto.Field( + proto.MESSAGE, + number=3, + optional=True, + message=types.Price, + ) + credit_type: str = proto.Field( + proto.STRING, + number=4, + optional=True, + ) + + +class LoyaltyPoints(proto.Message): + r"""A message that represents loyalty points. + + Attributes: + name (str): + Name of loyalty points program. It is + recommended to limit the name to 12 full-width + characters or 24 Roman characters. + points_value (int): + The retailer's loyalty points in absolute + value. + ratio (float): + The ratio of a point when converted to + currency. Google assumes currency based on + Merchant Center settings. If ratio is left out, + it defaults to 1.0. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + points_value: int = proto.Field( + proto.INT64, + number=2, + ) + ratio: float = proto.Field( + proto.DOUBLE, + number=3, + ) + + +class LoyaltyProgram(proto.Message): + r"""A message that represents loyalty program. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + program_label (str): + The label of the loyalty program. This is an + internal label that uniquely identifies the + relationship between a business entity and a + loyalty program entity. The label must be + provided so that the system can associate the + assets below (for example, price and points) + with a business. The corresponding program must + be linked to the Merchant Center account. + + This field is a member of `oneof`_ ``_program_label``. + tier_label (str): + The label of the tier within the loyalty + program. Must match one of the labels within the + program. + + This field is a member of `oneof`_ ``_tier_label``. + price (google.shopping.type.types.Price): + The price for members of the given tier, that + is, the instant discount price. Must be smaller + or equal to the regular price. + + This field is a member of `oneof`_ ``_price``. + cashback_for_future_use (google.shopping.type.types.Price): + The cashback that can be used for future + purchases. + + This field is a member of `oneof`_ ``_cashback_for_future_use``. + loyalty_points (int): + The amount of loyalty points earned on a + purchase. + + This field is a member of `oneof`_ ``_loyalty_points``. + member_price_effective_date (google.type.interval_pb2.Interval): + A date range during which the item is + eligible for member price. If not specified, the + member price is always applicable. The date + range is represented by a pair of ISO 8601 dates + separated by a space, comma, or slash. + + This field is a member of `oneof`_ ``_member_price_effective_date``. + shipping_label (str): + The label of the shipping benefit. If the + field has value, this offer has loyalty shipping + benefit. If the field value isn't provided, the + item is not eligible for loyalty shipping for + the given loyalty tier. + + This field is a member of `oneof`_ ``_shipping_label``. + """ + + program_label: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + tier_label: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + price: types.Price = proto.Field( + proto.MESSAGE, + number=3, + optional=True, + message=types.Price, + ) + cashback_for_future_use: types.Price = proto.Field( + proto.MESSAGE, + number=4, + optional=True, + message=types.Price, + ) + loyalty_points: int = proto.Field( + proto.INT64, + number=5, + optional=True, + ) + member_price_effective_date: interval_pb2.Interval = proto.Field( + proto.MESSAGE, + number=6, + optional=True, + message=interval_pb2.Interval, + ) + shipping_label: str = proto.Field( + proto.STRING, + number=7, + optional=True, + ) + + +class Shipping(proto.Message): + r"""The Shipping of the product. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + price (google.shopping.type.types.Price): + Fixed shipping price, represented as a + number. + country (str): + The `CLDR territory + code `__ + of the country to which an item will ship. + region (str): + The geographic region to which a shipping rate applies. See + `region `__ + for more information. + service (str): + A free-form description of the service class + or delivery speed. + location_id (int): + The numeric ID of a location that the shipping rate applies + to as defined in the `AdWords + API `__. + location_group_name (str): + The location where the shipping is + applicable, represented by a location group + name. + postal_code (str): + The postal code range that the shipping rate applies to, + represented by a postal code, a postal code prefix followed + by a \* wildcard, a range between two postal codes or two + postal code prefixes of equal length. + min_handling_time (int): + Minimum handling time (inclusive) between when the order is + received and shipped in business days. 0 means that the + order is shipped on the same day as it is received if it + happens before the cut-off time. + [minHandlingTime][google.shopping.merchant.products.v1beta.Shipping.min_handling_time] + can only be present together with + [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time]; + but it is not required if + [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] + is present. + + This field is a member of `oneof`_ ``_min_handling_time``. + max_handling_time (int): + Maximum handling time (inclusive) between when the order is + received and shipped in business days. 0 means that the + order is shipped on the same day as it is received if it + happens before the cut-off time. Both + [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] + and + [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] + are required if providing shipping speeds. + [minHandlingTime][google.shopping.merchant.products.v1beta.Shipping.min_handling_time] + is optional if + [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] + is present. + + This field is a member of `oneof`_ ``_max_handling_time``. + min_transit_time (int): + Minimum transit time (inclusive) between when the order has + shipped and when it is delivered in business days. 0 means + that the order is delivered on the same day as it ships. + [minTransitTime][google.shopping.merchant.products.v1beta.Shipping.min_transit_time] + can only be present together with + [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time]; + but it is not required if + [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] + is present. + + This field is a member of `oneof`_ ``_min_transit_time``. + max_transit_time (int): + Maximum transit time (inclusive) between when the order has + shipped and when it is delivered in business days. 0 means + that the order is delivered on the same day as it ships. + Both + [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] + and + [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] + are required if providing shipping speeds. + [minTransitTime][google.shopping.merchant.products.v1beta.Shipping.min_transit_time] + is optional if + [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] + is present. + + This field is a member of `oneof`_ ``_max_transit_time``. + """ + + price: types.Price = proto.Field( + proto.MESSAGE, + number=1, + message=types.Price, + ) + country: str = proto.Field( + proto.STRING, + number=2, + ) + region: str = proto.Field( + proto.STRING, + number=3, + ) + service: str = proto.Field( + proto.STRING, + number=4, + ) + location_id: int = proto.Field( + proto.INT64, + number=5, + ) + location_group_name: str = proto.Field( + proto.STRING, + number=6, + ) + postal_code: str = proto.Field( + proto.STRING, + number=7, + ) + min_handling_time: int = proto.Field( + proto.INT64, + number=8, + optional=True, + ) + max_handling_time: int = proto.Field( + proto.INT64, + number=9, + optional=True, + ) + min_transit_time: int = proto.Field( + proto.INT64, + number=10, + optional=True, + ) + max_transit_time: int = proto.Field( + proto.INT64, + number=11, + optional=True, + ) + + +class FreeShippingThreshold(proto.Message): + r"""Conditions to be met for a product to have free shipping. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + country (str): + The `CLDR territory + code `__ + of the country to which an item will ship. + + This field is a member of `oneof`_ ``_country``. + price_threshold (google.shopping.type.types.Price): + The minimum product price for the shipping + cost to become free. Represented as a number. + + This field is a member of `oneof`_ ``_price_threshold``. + """ + + country: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + price_threshold: types.Price = proto.Field( + proto.MESSAGE, + number=2, + optional=True, + message=types.Price, + ) + + +class ProductDetail(proto.Message): + r"""The product details. + + Attributes: + section_name (str): + The section header used to group a set of + product details. + attribute_name (str): + The name of the product detail. + attribute_value (str): + The value of the product detail. + """ + + section_name: str = proto.Field( + proto.STRING, + number=1, + ) + attribute_name: str = proto.Field( + proto.STRING, + number=2, + ) + attribute_value: str = proto.Field( + proto.STRING, + number=3, + ) + + +class Certification(proto.Message): + r"""Product + `certification `__, + initially introduced for EU energy efficiency labeling compliance + using the EU EPREL database. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + certification_authority (str): + The certification authority, for example + "European_Commission". Maximum length is 2000 characters. + + This field is a member of `oneof`_ ``_certification_authority``. + certification_name (str): + The name of the certification, for example + "EPREL". Maximum length is 2000 characters. + + This field is a member of `oneof`_ ``_certification_name``. + certification_code (str): + The certification code. + Maximum length is 2000 characters. + + This field is a member of `oneof`_ ``_certification_code``. + certification_value (str): + The certification value (also known as class, + level or grade), for example "A+", "C", "gold". + Maximum length is 2000 characters. + + This field is a member of `oneof`_ ``_certification_value``. + """ + + certification_authority: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + certification_name: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + certification_code: str = proto.Field( + proto.STRING, + number=3, + optional=True, + ) + certification_value: str = proto.Field( + proto.STRING, + number=4, + optional=True, + ) + + +class ProductStructuredTitle(proto.Message): + r"""Structured title, for algorithmically (AI)-generated titles. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + digital_source_type (str): + The digital source type, for example + "trained_algorithmic_media". Following + `IPTC `__. + Maximum length is 40 characters. + + This field is a member of `oneof`_ ``_digital_source_type``. + content (str): + The title text + Maximum length is 150 characters + + This field is a member of `oneof`_ ``_content``. + """ + + digital_source_type: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + content: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + + +class ProductStructuredDescription(proto.Message): + r"""Structured description, for algorithmically (AI)-generated + descriptions. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + digital_source_type (str): + The digital source type, for example + "trained_algorithmic_media". Following + `IPTC `__. + Maximum length is 40 characters. + + This field is a member of `oneof`_ ``_digital_source_type``. + content (str): + The description text + Maximum length is 5000 characters + + This field is a member of `oneof`_ ``_content``. + """ + + digital_source_type: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + content: str = proto.Field( + proto.STRING, + number=2, + optional=True, + ) + + +class ProductDimension(proto.Message): + r"""The dimension of the product. + + Attributes: + value (float): + Required. The dimension value represented as + a number. The value can have a maximum precision + of four decimal places. + unit (str): + Required. The dimension units. Acceptable values are: + + - "``in``" + - "``cm``". + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ProductWeight(proto.Message): + r"""The weight of the product. + + Attributes: + value (float): + Required. The weight represented as a number. + The weight can have a maximum precision of four + decimal places. + unit (str): + Required. The weight unit. Acceptable values are: + + - "``g``" + - "``kg``" + - "``oz``" + - "``lb``". + """ + + value: float = proto.Field( + proto.DOUBLE, + number=1, + ) + unit: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ProductStatus(proto.Message): + r"""The status of a product, data validation issues, that is, + information about a product computed asynchronously. + + Attributes: + destination_statuses (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductStatus.DestinationStatus]): + The intended destinations for the product. + item_level_issues (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductStatus.ItemLevelIssue]): + A list of all issues associated with the + product. + creation_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item has been created, in `ISO + 8601 `__ format. + last_update_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item has been last updated, in `ISO + 8601 `__ format. + google_expiration_date (google.protobuf.timestamp_pb2.Timestamp): + Date on which the item expires, in `ISO + 8601 `__ format. + """ + + class DestinationStatus(proto.Message): + r"""The destination status of the product status. + + Attributes: + reporting_context (google.shopping.type.types.ReportingContext.ReportingContextEnum): + The name of the reporting context. + approved_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where the offer is approved. + pending_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where the offer is pending approval. + disapproved_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where the offer is disapproved. + """ + + reporting_context: types.ReportingContext.ReportingContextEnum = proto.Field( + proto.ENUM, + number=1, + enum=types.ReportingContext.ReportingContextEnum, + ) + approved_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + pending_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=3, + ) + disapproved_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=4, + ) + + class ItemLevelIssue(proto.Message): + r"""The ItemLevelIssue of the product status. + + Attributes: + code (str): + The error code of the issue. + severity (google.shopping.merchant_products_v1beta.types.ProductStatus.ItemLevelIssue.Severity): + How this issue affects serving of the offer. + resolution (str): + Whether the issue can be resolved by the + business. + attribute (str): + The attribute's name, if the issue is caused + by a single attribute. + reporting_context (google.shopping.type.types.ReportingContext.ReportingContextEnum): + The reporting context the issue applies to. + description (str): + A short issue description in English. + detail (str): + A detailed issue description in English. + documentation (str): + The URL of a web page to help with resolving + this issue. + applicable_countries (MutableSequence[str]): + List of country codes (ISO 3166-1 alpha-2) + where issue applies to the offer. + """ + class Severity(proto.Enum): + r"""How the issue affects the serving of the product. + + Values: + SEVERITY_UNSPECIFIED (0): + Not specified. + NOT_IMPACTED (1): + This issue represents a warning and does not + have a direct affect on the product. + DEMOTED (2): + The product is demoted and most likely have + limited performance in search results + DISAPPROVED (3): + Issue disapproves the product. + """ + SEVERITY_UNSPECIFIED = 0 + NOT_IMPACTED = 1 + DEMOTED = 2 + DISAPPROVED = 3 + + code: str = proto.Field( + proto.STRING, + number=1, + ) + severity: 'ProductStatus.ItemLevelIssue.Severity' = proto.Field( + proto.ENUM, + number=2, + enum='ProductStatus.ItemLevelIssue.Severity', + ) + resolution: str = proto.Field( + proto.STRING, + number=3, + ) + attribute: str = proto.Field( + proto.STRING, + number=4, + ) + reporting_context: types.ReportingContext.ReportingContextEnum = proto.Field( + proto.ENUM, + number=5, + enum=types.ReportingContext.ReportingContextEnum, + ) + description: str = proto.Field( + proto.STRING, + number=6, + ) + detail: str = proto.Field( + proto.STRING, + number=7, + ) + documentation: str = proto.Field( + proto.STRING, + number=8, + ) + applicable_countries: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=9, + ) + + destination_statuses: MutableSequence[DestinationStatus] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=DestinationStatus, + ) + item_level_issues: MutableSequence[ItemLevelIssue] = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=ItemLevelIssue, + ) + creation_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + last_update_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + google_expiration_date: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + + +class CloudExportAdditionalProperties(proto.Message): + r"""Product property for the Cloud Retail API. + For example, properties for a TV product could be + "Screen-Resolution" or "Screen-Size". + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + property_name (str): + Name of the given property. For example, + "Screen-Resolution" for a TV product. Maximum + string size is 256 characters. + + This field is a member of `oneof`_ ``_property_name``. + text_value (MutableSequence[str]): + Text value of the given property. For + example, "8K(UHD)" could be a text value for a + TV product. Maximum repeatedness of this value + is 400. Values are stored in an arbitrary but + consistent order. Maximum string size is 256 + characters. + bool_value (bool): + Boolean value of the given property. For + example for a TV product, "True" or "False" if + the screen is UHD. + + This field is a member of `oneof`_ ``_bool_value``. + int_value (MutableSequence[int]): + Integer values of the given property. For + example, 1080 for a TV product's Screen + Resolution. Maximum repeatedness of this value + is 400. Values are stored in an arbitrary but + consistent order. + float_value (MutableSequence[float]): + Float values of the given property. For + example for a TV product 1.2345. Maximum + repeatedness of this value is 400. Values are + stored in an arbitrary but consistent order. + min_value (float): + Minimum float value of the given property. + For example for a TV product 1.00. + + This field is a member of `oneof`_ ``_min_value``. + max_value (float): + Maximum float value of the given property. + For example for a TV product 100.00. + + This field is a member of `oneof`_ ``_max_value``. + unit_code (str): + Unit of the given property. For example, + "Pixels" for a TV product. Maximum string size + is 256B. + + This field is a member of `oneof`_ ``_unit_code``. + """ + + property_name: str = proto.Field( + proto.STRING, + number=1, + optional=True, + ) + text_value: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + bool_value: bool = proto.Field( + proto.BOOL, + number=3, + optional=True, + ) + int_value: MutableSequence[int] = proto.RepeatedField( + proto.INT64, + number=4, + ) + float_value: MutableSequence[float] = proto.RepeatedField( + proto.FLOAT, + number=5, + ) + min_value: float = proto.Field( + proto.FLOAT, + number=6, + optional=True, + ) + max_value: float = proto.Field( + proto.FLOAT, + number=7, + optional=True, + ) + unit_code: str = proto.Field( + proto.STRING, + number=8, + optional=True, + ) + + +class ProductSustainabilityIncentive(proto.Message): + r"""Information regarding sustainability-related incentive + programs such as rebates or tax relief. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + amount (google.shopping.type.types.Price): + The fixed amount of the incentive. + + This field is a member of `oneof`_ ``value``. + percentage (float): + The percentage of the sale price that the + incentive is applied to. + + This field is a member of `oneof`_ ``value``. + type_ (google.shopping.merchant_products_v1beta.types.ProductSustainabilityIncentive.Type): + Sustainability incentive program. + + This field is a member of `oneof`_ ``_type``. + """ + class Type(proto.Enum): + r"""Types of supported sustainability incentive programs. + + Values: + TYPE_UNSPECIFIED (0): + Unspecified or unknown sustainability + incentive type. + EV_TAX_CREDIT (1): + Program offering tax liability reductions for + electric vehicles and, in some countries, + plug-in hybrids. These reductions can be based + on a specific amount or a percentage of the sale + price. + EV_PRICE_DISCOUNT (2): + A subsidy program, often called an + environmental bonus, provides a purchase grant + for electric vehicles and, in some countries, + plug-in hybrids. The grant amount may be a fixed + sum or a percentage of the sale price. + """ + TYPE_UNSPECIFIED = 0 + EV_TAX_CREDIT = 1 + EV_PRICE_DISCOUNT = 2 + + amount: types.Price = proto.Field( + proto.MESSAGE, + number=2, + oneof='value', + message=types.Price, + ) + percentage: float = proto.Field( + proto.DOUBLE, + number=3, + oneof='value', + ) + type_: Type = proto.Field( + proto.ENUM, + number=1, + optional=True, + enum=Type, + ) + + +class AutomatedDiscounts(proto.Message): + r"""Information regarding Automated Discounts. + + Attributes: + prior_price (google.shopping.type.types.Price): + The price prior to the application of the + first price reduction. Absent if the information + about the prior price of the product is not + available. + prior_price_progressive (google.shopping.type.types.Price): + The price prior to the application of + consecutive price reductions. Absent if the + information about the prior price of the product + is not available. + gad_price (google.shopping.type.types.Price): + The current sale price for products with a price optimized + using Google Automated Discounts (GAD). Absent if the + information about the GAD_price of the product is not + available. + """ + + prior_price: types.Price = proto.Field( + proto.MESSAGE, + number=1, + message=types.Price, + ) + prior_price_progressive: types.Price = proto.Field( + proto.MESSAGE, + number=2, + message=types.Price, + ) + gad_price: types.Price = proto.Field( + proto.MESSAGE, + number=3, + message=types.Price, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini b/owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini new file mode 100644 index 000000000000..574c5aed394b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.7 +namespace_packages = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py new file mode 100644 index 000000000000..317670e1652b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py @@ -0,0 +1,591 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import re +import shutil + +from typing import Dict, List +import warnings + +import nox + +BLACK_VERSION = "black[jupyter]==23.7.0" +ISORT_VERSION = "isort==5.11.0" + +LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] + +ALL_PYTHON = [ + "3.7", + "3.8", + "3.9", + "3.10", + "3.11", + "3.12", + "3.13", +] + +DEFAULT_PYTHON_VERSION = ALL_PYTHON[-1] + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = "google-shopping-merchant-products" + +UNIT_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", +] +UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] +UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] +UNIT_TEST_DEPENDENCIES: List[str] = [] +UNIT_TEST_EXTRAS: List[str] = [] +UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} + +SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "pytest", + "google-cloud-testutils", +] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [] +SYSTEM_TEST_DEPENDENCIES: List[str] = [] +SYSTEM_TEST_EXTRAS: List[str] = [] +SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} + +nox.options.sessions = [ + "unit", + "system", + "cover", + "lint", + "lint_setup_py", + "blacken", + "docs", +] + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + + +@nox.session(python=ALL_PYTHON) +def mypy(session): + """Run the type checker.""" + session.install( + "mypy", + "types-requests", + "types-protobuf", + ) + session.install(".") + session.run( + "mypy", + "-p", + "google", + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install("google-cloud-testutils") + session.install(".") + + session.run( + "lower-bound-checker", + "update", + "--package-name", + PACKAGE_NAME, + "--constraints-file", + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install("google-cloud-testutils") + session.install(".") + + session.run( + "lower-bound-checker", + "check", + "--package-name", + PACKAGE_NAME, + "--constraints-file", + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint(session): + """Run linters. + + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", BLACK_VERSION) + session.run( + "black", + "--check", + *LINT_PATHS, + ) + + session.run("flake8", "google", "tests") + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def blacken(session): + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + session.run( + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def format(session): + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run( + "isort", + "--fss", + *LINT_PATHS, + ) + session.run( + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install("setuptools", "docutils", "pygments") + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") + + +def install_unittest_dependencies(session, *constraints): + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, *constraints) + + if UNIT_TEST_EXTERNAL_DEPENDENCIES: + warnings.warn( + "'unit_test_external_dependencies' is deprecated. Instead, please " + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", + DeprecationWarning, + ) + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_LOCAL_DEPENDENCIES: + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_EXTRAS_BY_PYTHON: + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif UNIT_TEST_EXTRAS: + extras = UNIT_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + +@nox.session(python=ALL_PYTHON) +@nox.parametrize( + "protobuf_implementation", + ["python", "upb", "cpp"], +) +def unit(session, protobuf_implementation): + # Install all test dependencies, then install this package in-place. + + if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): + session.skip("cpp implementation is not supported in python 3.11+") + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + install_unittest_dependencies(session, "-c", constraints_path) + + # TODO(https://github.com/googleapis/synthtool/issues/1976): + # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. + # The 'cpp' implementation requires Protobuf<4. + if protobuf_implementation == "cpp": + session.install("protobuf<4") + + # Run py.test against the unit tests. + session.run( + "py.test", + "--quiet", + f"--junitxml=unit_{session.python}_sponge_log.xml", + "--cov=google", + "--cov=tests/unit", + "--cov-append", + "--cov-config=.coveragerc", + "--cov-report=", + "--cov-fail-under=0", + os.path.join("tests", "unit"), + *session.posargs, + env={ + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, + }, + ) + + +def install_systemtest_dependencies(session, *constraints): + session.install("--pre", "grpcio") + + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_LOCAL_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTRAS_BY_PYTHON: + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif SYSTEM_TEST_EXTRAS: + extras = SYSTEM_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + +@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) +def system(session): + """Run the system test suite.""" + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + system_test_path = os.path.join("tests", "system.py") + system_test_folder_path = os.path.join("tests", "system") + + # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. + if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": + session.skip("RUN_SYSTEM_TESTS is set to false, skipping") + # Install pyopenssl for mTLS testing. + if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": + session.install("pyopenssl") + + system_test_exists = os.path.exists(system_test_path) + system_test_folder_exists = os.path.exists(system_test_folder_path) + # Sanity check: only run tests if found. + if not system_test_exists and not system_test_folder_exists: + session.skip("System tests were not found") + + install_systemtest_dependencies(session, "-c", constraints_path) + + # Run py.test against the system tests. + if system_test_exists: + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_path, + *session.posargs, + ) + if system_test_folder_exists: + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_folder_path, + *session.posargs, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def cover(session): + """Run the final coverage report. + + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python="3.10") +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", + "sphinx==4.5.0", + "alabaster", + "recommonmark", + ) + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python="3.10") +def docfx(session): + """Build the docfx yaml files for this library.""" + + session.install("-e", ".") + session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", + "gcp-sphinx-docfx-yaml", + "alabaster", + "recommonmark", + ) + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-T", # show full traceback on exception + "-N", # no colors + "-D", + ( + "extensions=sphinx.ext.autodoc," + "sphinx.ext.autosummary," + "docfx_yaml.extension," + "sphinx.ext.intersphinx," + "sphinx.ext.coverage," + "sphinx.ext.napoleon," + "sphinx.ext.todo," + "sphinx.ext.viewcode," + "recommonmark" + ), + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +@nox.parametrize( + "protobuf_implementation", + ["python", "upb", "cpp"], +) +def prerelease_deps(session, protobuf_implementation): + """ + Run all tests with pre-release versions of dependencies installed + rather than the standard non pre-release versions. + Pre-release versions can be installed using + `pip install --pre `. + """ + + if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): + session.skip("cpp implementation is not supported in python 3.11+") + + # Install all dependencies + session.install("-e", ".") + + # Install dependencies for the unit test environment + unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES + session.install(*unit_deps_all) + + # Install dependencies for the system test environment + system_deps_all = ( + SYSTEM_TEST_STANDARD_DEPENDENCIES + + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + + SYSTEM_TEST_EXTRAS + ) + session.install(*system_deps_all) + + # Because we test minimum dependency versions on the minimum Python + # version, the first version we test with in the unit tests sessions has a + # constraints file containing all dependencies and extras. + with open( + CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", + encoding="utf-8", + ) as constraints_file: + constraints_text = constraints_file.read() + + # Ignore leading whitespace and comment lines. + constraints_deps = [ + match.group(1) + for match in re.finditer( + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE + ) + ] + + # Install dependencies specified in `testing/constraints-X.txt`. + session.install(*constraints_deps) + + # Note: If a dependency is added to the `prerel_deps` list, + # the `core_dependencies_from_source` list in the `core_deps_from_source` + # nox session should also be updated. + prerel_deps = [ + "googleapis-common-protos", + "google-api-core", + "google-auth", + "grpc-google-iam-v1", + "grpcio", + "grpcio-status", + "protobuf", + "proto-plus", + ] + + for dep in prerel_deps: + session.install("--pre", "--no-deps", "--ignore-installed", dep) + # TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status`` + # to the dictionary below once this bug is fixed. + # TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add + # `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below + # once this bug is fixed. + package_namespaces = { + "google-api-core": "google.api_core", + "google-auth": "google.auth", + "grpcio": "grpc", + "protobuf": "google.protobuf", + "proto-plus": "proto", + } + + version_namespace = package_namespaces.get(dep) + + print(f"Installed {dep}") + if version_namespace: + session.run( + "python", + "-c", + f"import {version_namespace}; print({version_namespace}.__version__)", + ) + + session.run( + "py.test", + "tests/unit", + env={ + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, + }, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +@nox.parametrize( + "protobuf_implementation", + ["python", "upb"], +) +def core_deps_from_source(session, protobuf_implementation): + """Run all tests with core dependencies installed from source + rather than pulling the dependencies from PyPI. + """ + + # Install all dependencies + session.install("-e", ".") + + # Install dependencies for the unit test environment + unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES + session.install(*unit_deps_all) + + # Install dependencies for the system test environment + system_deps_all = ( + SYSTEM_TEST_STANDARD_DEPENDENCIES + + SYSTEM_TEST_EXTERNAL_DEPENDENCIES + + SYSTEM_TEST_EXTRAS + ) + session.install(*system_deps_all) + + # Because we test minimum dependency versions on the minimum Python + # version, the first version we test with in the unit tests sessions has a + # constraints file containing all dependencies and extras. + with open( + CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", + encoding="utf-8", + ) as constraints_file: + constraints_text = constraints_file.read() + + # Ignore leading whitespace and comment lines. + constraints_deps = [ + match.group(1) + for match in re.finditer( + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE + ) + ] + + # Install dependencies specified in `testing/constraints-X.txt`. + session.install(*constraints_deps) + + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and + # `grpcio-status` should be added to the list below so that they are installed from source, + # rather than PyPI. + # TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be + # added to the list below so that it is installed from source, rather than PyPI + # Note: If a dependency is added to the `core_dependencies_from_source` list, + # the `prerel_deps` list in the `prerelease_deps` nox session should also be updated. + core_dependencies_from_source = [ + "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", + "google-api-core @ git+https://github.com/googleapis/python-api-core.git", + "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", + "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", + "proto-plus @ git+https://github.com/googleapis/proto-plus-python.git", + ] + + for dep in core_dependencies_from_source: + session.install(dep, "--no-deps", "--ignore-installed") + print(f"Installed {dep}") + + session.run( + "py.test", + "tests/unit", + env={ + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, + }, + ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py new file mode 100644 index 000000000000..c15d4c99af6a --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +async def sample_delete_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + await client.delete_product_input(request=request) + + +# [END merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py new file mode 100644 index 000000000000..f2b45d69798d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +def sample_delete_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.DeleteProductInputRequest( + name="name_value", + data_source="data_source_value", + ) + + # Make the request + client.delete_product_input(request=request) + + +# [END merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py new file mode 100644 index 000000000000..2e9351bac625 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for InsertProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +async def sample_insert_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.insert_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py new file mode 100644 index 000000000000..df9c682279da --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for InsertProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +def sample_insert_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.InsertProductInputRequest( + parent="parent_value", + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.insert_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py new file mode 100644 index 000000000000..f7b557927349 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +async def sample_update_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceAsyncClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = await client.update_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py new file mode 100644 index 000000000000..74f753bd83a7 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateProductInput +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +def sample_update_product_input(): + # Create a client + client = merchant_products_v1beta.ProductInputsServiceClient() + + # Initialize request argument(s) + product_input = merchant_products_v1beta.ProductInput() + product_input.offer_id = "offer_id_value" + product_input.content_language = "content_language_value" + product_input.feed_label = "feed_label_value" + + request = merchant_products_v1beta.UpdateProductInputRequest( + product_input=product_input, + data_source="data_source_value", + ) + + # Make the request + response = client.update_product_input(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py new file mode 100644 index 000000000000..8d9ac7b3e0d9 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductsService_GetProduct_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +async def sample_get_product(): + # Create a client + client = merchant_products_v1beta.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.GetProductRequest( + name="name_value", + ) + + # Make the request + response = await client.get_product(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1beta_generated_ProductsService_GetProduct_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py new file mode 100644 index 000000000000..d0d027b7dfb5 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetProduct +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductsService_GetProduct_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +def sample_get_product(): + # Create a client + client = merchant_products_v1beta.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.GetProductRequest( + name="name_value", + ) + + # Make the request + response = client.get_product(request=request) + + # Handle the response + print(response) + +# [END merchantapi_v1beta_generated_ProductsService_GetProduct_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py new file mode 100644 index 000000000000..eb1af0879bf7 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductsService_ListProducts_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +async def sample_list_products(): + # Create a client + client = merchant_products_v1beta.ProductsServiceAsyncClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END merchantapi_v1beta_generated_ProductsService_ListProducts_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py new file mode 100644 index 000000000000..d1b651ca0555 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListProducts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-shopping-merchant-products + + +# [START merchantapi_v1beta_generated_ProductsService_ListProducts_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.shopping import merchant_products_v1beta + + +def sample_list_products(): + # Create a client + client = merchant_products_v1beta.ProductsServiceClient() + + # Initialize request argument(s) + request = merchant_products_v1beta.ListProductsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_products(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END merchantapi_v1beta_generated_ProductsService_ListProducts_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json new file mode 100644 index 000000000000..efc245a8341b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json @@ -0,0 +1,814 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.shopping.merchant.products.v1beta", + "version": "v1beta" + } + ], + "language": "PYTHON", + "name": "google-shopping-merchant-products", + "version": "0.1.0" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient", + "shortName": "ProductInputsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient.delete_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.DeleteProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "DeleteProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "shortName": "delete_product_input" + }, + "description": "Sample for DeleteProductInput", + "file": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient", + "shortName": "ProductInputsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient.delete_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.DeleteProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "DeleteProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "shortName": "delete_product_input" + }, + "description": "Sample for DeleteProductInput", + "file": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient", + "shortName": "ProductInputsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient.insert_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.InsertProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "InsertProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.InsertProductInputRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", + "shortName": "insert_product_input" + }, + "description": "Sample for InsertProductInput", + "file": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_async", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 52, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 53, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient", + "shortName": "ProductInputsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient.insert_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.InsertProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "InsertProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.InsertProductInputRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", + "shortName": "insert_product_input" + }, + "description": "Sample for InsertProductInput", + "file": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_sync", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 52, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 53, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient", + "shortName": "ProductInputsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient.update_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.UpdateProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "UpdateProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest" + }, + { + "name": "product_input", + "type": "google.shopping.merchant_products_v1beta.types.ProductInput" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", + "shortName": "update_product_input" + }, + "description": "Sample for UpdateProductInput", + "file": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_async", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient", + "shortName": "ProductInputsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient.update_product_input", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.UpdateProductInput", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", + "shortName": "ProductInputsService" + }, + "shortName": "UpdateProductInput" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest" + }, + { + "name": "product_input", + "type": "google.shopping.merchant_products_v1beta.types.ProductInput" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", + "shortName": "update_product_input" + }, + "description": "Sample for UpdateProductInput", + "file": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_sync", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient", + "shortName": "ProductsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient.get_product", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService.GetProduct", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "GetProduct" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.GetProductRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.types.Product", + "shortName": "get_product" + }, + "description": "Sample for GetProduct", + "file": "merchantapi_v1beta_generated_products_service_get_product_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductsService_GetProduct_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_products_service_get_product_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient", + "shortName": "ProductsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient.get_product", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService.GetProduct", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "GetProduct" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.GetProductRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.types.Product", + "shortName": "get_product" + }, + "description": "Sample for GetProduct", + "file": "merchantapi_v1beta_generated_products_service_get_product_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductsService_GetProduct_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_products_service_get_product_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient", + "shortName": "ProductsServiceAsyncClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient.list_products", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService.ListProducts", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "ListProducts" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.ListProductsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsAsyncPager", + "shortName": "list_products" + }, + "description": "Sample for ListProducts", + "file": "merchantapi_v1beta_generated_products_service_list_products_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductsService_ListProducts_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_products_service_list_products_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient", + "shortName": "ProductsServiceClient" + }, + "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient.list_products", + "method": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService.ListProducts", + "service": { + "fullName": "google.shopping.merchant.products.v1beta.ProductsService", + "shortName": "ProductsService" + }, + "shortName": "ListProducts" + }, + "parameters": [ + { + "name": "request", + "type": "google.shopping.merchant_products_v1beta.types.ListProductsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, Union[str, bytes]]]" + } + ], + "resultType": "google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsPager", + "shortName": "list_products" + }, + "description": "Sample for ListProducts", + "file": "merchantapi_v1beta_generated_products_service_list_products_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "merchantapi_v1beta_generated_ProductsService_ListProducts_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "merchantapi_v1beta_generated_products_service_list_products_sync.py" + } + ] +} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py new file mode 100644 index 000000000000..da63187314ee --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py @@ -0,0 +1,180 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class merchant_productsCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'delete_product_input': ('name', 'data_source', ), + 'get_product': ('name', ), + 'insert_product_input': ('parent', 'product_input', 'data_source', ), + 'list_products': ('parent', 'page_size', 'page_token', ), + 'update_product_input': ('product_input', 'data_source', 'update_mask', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: a.keyword.value not in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=merchant_productsCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the merchant_products client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py new file mode 100644 index 000000000000..d1544a0a16b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os +import re + +import setuptools # type: ignore + +package_root = os.path.abspath(os.path.dirname(__file__)) + +name = 'google-shopping-merchant-products' + + +description = "Google Shopping Merchant Products API client library" + +version = None + +with open(os.path.join(package_root, 'google/shopping/merchant_products/gapic_version.py')) as fp: + version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read()) + assert (len(version_candidates) == 1) + version = version_candidates[0] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + +dependencies = [ + "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + # Exclude incompatible versions of `google-auth` + # See https://github.com/googleapis/google-cloud-python/issues/12364 + "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", + "proto-plus >= 1.22.3, <2.0.0", + "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", + "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "google-shopping-type >= 0.1.6, <1.0.0", +] +extras = { +} +url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-shopping-merchant-products" + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, "README.rst") +with io.open(readme_filename, encoding="utf-8") as readme_file: + readme = readme_file.read() + +packages = [ + package + for package in setuptools.find_namespace_packages() + if package.startswith("google") +] + +setuptools.setup( + name=name, + version=version, + description=description, + long_description=readme, + author="Google LLC", + author_email="googleapis-packages@google.com", + license="Apache 2.0", + url=url, + classifiers=[ + release_status, + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Operating System :: OS Independent", + "Topic :: Internet", + ], + platforms="Posix; MacOS X; Windows", + packages=packages, + python_requires=">=3.7", + install_requires=dependencies, + extras_require=extras, + include_package_data=True, + zip_safe=False, +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt new file mode 100644 index 000000000000..0112695e5bbb --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt @@ -0,0 +1,12 @@ +# We use the constraints file for the latest Python version +# (currently this file) to check that the latest +# major versions of dependencies are supported in setup.py. +# List all library dependencies and extras in this file. +# Require the latest major version be installed for each dependency. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# Then this file should have google-cloud-foo>=1 +google-api-core>=2 +google-auth>=2 +proto-plus>=1 +protobuf>=6 +google-shopping-type>=0 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt new file mode 100644 index 000000000000..2af887ec8ba0 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt @@ -0,0 +1,11 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file. +# Pin the version to the lower bound. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.1 +google-auth==2.14.1 +proto-plus==1.22.3 +protobuf==3.20.2 +google-shopping-type==0.1.6 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt new file mode 100644 index 000000000000..4cae520d02b2 --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py new file mode 100644 index 000000000000..191773d5572d --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py new file mode 100644 index 000000000000..58270681dd0b --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py @@ -0,0 +1,3573 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable, AsyncIterable +from google.protobuf import json_format +import json +import math +import pytest +from google.api_core import api_core_version +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +try: + from google.auth.aio import credentials as ga_credentials_async + HAS_GOOGLE_AUTH_AIO = True +except ImportError: # pragma: NO COVER + HAS_GOOGLE_AUTH_AIO = False + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.shopping.merchant_products_v1beta.services.product_inputs_service import ProductInputsServiceAsyncClient +from google.shopping.merchant_products_v1beta.services.product_inputs_service import ProductInputsServiceClient +from google.shopping.merchant_products_v1beta.services.product_inputs_service import transports +from google.shopping.merchant_products_v1beta.types import productinputs +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types +from google.type import interval_pb2 # type: ignore +import google.auth + + + +CRED_INFO_JSON = { + "credential_source": "/path/to/file", + "credential_type": "service account credentials", + "principal": "service-account@example.com", +} +CRED_INFO_STRING = json.dumps(CRED_INFO_JSON) + + +async def mock_async_gen(data, chunk_size=1): + for i in range(0, len(data)): # pragma: NO COVER + chunk = data[i : i + chunk_size] + yield chunk.encode("utf-8") + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + +# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. +# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. +def async_anonymous_credentials(): + if HAS_GOOGLE_AUTH_AIO: + return ga_credentials_async.AnonymousCredentials() + return ga_credentials.AnonymousCredentials() + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + +# If default endpoint template is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint template so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint_template(client): + return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert ProductInputsServiceClient._get_default_mtls_endpoint(None) is None + assert ProductInputsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductInputsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + +def test__read_environment_variables(): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ProductInputsServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + ProductInputsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductInputsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): + assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", "foo.com") + +def test__get_client_cert_source(): + mock_provided_cert_source = mock.Mock() + mock_default_cert_source = mock.Mock() + + assert ProductInputsServiceClient._get_client_cert_source(None, False) is None + assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None + assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source + + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): + assert ProductInputsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source + assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source + +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + assert ProductInputsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override + assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint + assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductInputsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint + assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint + + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") + assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." + + +def test__get_universe_domain(): + client_universe_domain = "foo.com" + universe_domain_env = "bar.com" + + assert ProductInputsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain + assert ProductInputsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env + assert ProductInputsServiceClient._get_universe_domain(None, None) == ProductInputsServiceClient._DEFAULT_UNIVERSE + + with pytest.raises(ValueError) as excinfo: + ProductInputsServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + +@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ + (401, CRED_INFO_JSON, True), + (403, CRED_INFO_JSON, True), + (404, CRED_INFO_JSON, True), + (500, CRED_INFO_JSON, False), + (401, None, False), + (403, None, False), + (404, None, False), + (500, None, False) +]) +def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): + cred = mock.Mock(["get_cred_info"]) + cred.get_cred_info = mock.Mock(return_value=cred_info_json) + client = ProductInputsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=["foo"]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + if show_cred_info: + assert error.details == ["foo", CRED_INFO_STRING] + else: + assert error.details == ["foo"] + +@pytest.mark.parametrize("error_code", [401,403,404,500]) +def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): + cred = mock.Mock([]) + assert not hasattr(cred, "get_cred_info") + client = ProductInputsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=[]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + assert error.details == [] + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductInputsServiceClient, "grpc"), + (ProductInputsServiceAsyncClient, "grpc_asyncio"), + (ProductInputsServiceClient, "rest"), +]) +def test_product_inputs_service_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductInputsServiceGrpcTransport, "grpc"), + (transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.ProductInputsServiceRestTransport, "rest"), +]) +def test_product_inputs_service_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductInputsServiceClient, "grpc"), + (ProductInputsServiceAsyncClient, "grpc_asyncio"), + (ProductInputsServiceClient, "rest"), +]) +def test_product_inputs_service_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +def test_product_inputs_service_client_get_transport_class(): + transport = ProductInputsServiceClient.get_transport_class() + available_transports = [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceRestTransport, + ] + assert transport in available_transports + + transport = ProductInputsServiceClient.get_transport_class("grpc") + assert transport == transports.ProductInputsServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), +]) +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +def test_product_inputs_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "true"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "false"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "true"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "false"), +]) +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_product_inputs_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + ProductInputsServiceClient, ProductInputsServiceAsyncClient +]) +@mock.patch.object(ProductInputsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceAsyncClient)) +def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + +@pytest.mark.parametrize("client_class", [ + ProductInputsServiceClient, ProductInputsServiceAsyncClient +]) +@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) +@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +def test_product_inputs_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", + # use ClientOptions.api_endpoint as the api endpoint regardless. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == api_override + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", + # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + + # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), + # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, + # and ClientOptions.universe_domain="bar.com", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. + options = client_options.ClientOptions() + universe_exists = hasattr(options, "universe_domain") + if universe_exists: + options = client_options.ClientOptions(universe_domain=mock_universe) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + else: + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) + assert client.universe_domain == (mock_universe if universe_exists else default_universe) + + # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + options = client_options.ClientOptions() + if hasattr(options, "universe_domain"): + delattr(options, "universe_domain") + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), +]) +def test_product_inputs_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", None), +]) +def test_product_inputs_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_product_inputs_service_client_client_options_from_dict(): + with mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductInputsServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_product_inputs_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=None, + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + productinputs.InsertProductInputRequest, + dict, +]) +def test_insert_product_input(request_type, transport: str = 'grpc'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + response = client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = productinputs.InsertProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +def test_insert_product_input_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = productinputs.InsertProductInputRequest( + parent='parent_value', + data_source='data_source_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.insert_product_input(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == productinputs.InsertProductInputRequest( + parent='parent_value', + data_source='data_source_value', + ) + +def test_insert_product_input_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.insert_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc + request = {} + client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.insert_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_insert_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.insert_product_input in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.insert_product_input] = mock_rpc + + request = {} + await client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.insert_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_insert_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.InsertProductInputRequest): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + response = await client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = productinputs.InsertProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.asyncio +async def test_insert_product_input_async_from_dict(): + await test_insert_product_input_async(request_type=dict) + +def test_insert_product_input_field_headers(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.InsertProductInputRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_insert_product_input_field_headers_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.InsertProductInputRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + await client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + productinputs.UpdateProductInputRequest, + dict, +]) +def test_update_product_input(request_type, transport: str = 'grpc'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + response = client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = productinputs.UpdateProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +def test_update_product_input_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = productinputs.UpdateProductInputRequest( + data_source='data_source_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.update_product_input(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == productinputs.UpdateProductInputRequest( + data_source='data_source_value', + ) + +def test_update_product_input_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc + request = {} + client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.update_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_update_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.update_product_input in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.update_product_input] = mock_rpc + + request = {} + await client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.update_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_update_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.UpdateProductInputRequest): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + response = await client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = productinputs.UpdateProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.asyncio +async def test_update_product_input_async_from_dict(): + await test_update_product_input_async(request_type=dict) + +def test_update_product_input_field_headers(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.UpdateProductInputRequest() + + request.product_input.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'product_input.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_product_input_field_headers_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.UpdateProductInputRequest() + + request.product_input.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + await client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'product_input.name=name_value', + ) in kw['metadata'] + + +def test_update_product_input_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_product_input( + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].product_input + mock_val = productinputs.ProductInput(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + + +def test_update_product_input_flattened_error(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_product_input( + productinputs.UpdateProductInputRequest(), + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + +@pytest.mark.asyncio +async def test_update_product_input_flattened_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = productinputs.ProductInput() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_product_input( + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].product_input + mock_val = productinputs.ProductInput(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_product_input_flattened_error_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_product_input( + productinputs.UpdateProductInputRequest(), + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.parametrize("request_type", [ + productinputs.DeleteProductInputRequest, + dict, +]) +def test_delete_product_input(request_type, transport: str = 'grpc'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = productinputs.DeleteProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_product_input_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = productinputs.DeleteProductInputRequest( + name='name_value', + data_source='data_source_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.delete_product_input(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == productinputs.DeleteProductInputRequest( + name='name_value', + data_source='data_source_value', + ) + +def test_delete_product_input_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc + request = {} + client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.delete_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_delete_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.delete_product_input in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.delete_product_input] = mock_rpc + + request = {} + await client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.delete_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_delete_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.DeleteProductInputRequest): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = productinputs.DeleteProductInputRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_product_input_async_from_dict(): + await test_delete_product_input_async(request_type=dict) + +def test_delete_product_input_field_headers(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.DeleteProductInputRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value = None + client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_product_input_field_headers_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = productinputs.DeleteProductInputRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_delete_product_input_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_product_input( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_delete_product_input_flattened_error(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_product_input( + productinputs.DeleteProductInputRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_delete_product_input_flattened_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_product_input( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_delete_product_input_flattened_error_async(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_product_input( + productinputs.DeleteProductInputRequest(), + name='name_value', + ) + + +def test_insert_product_input_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.insert_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc + + request = {} + client.insert_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.insert_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_insert_product_input_rest_required_fields(request_type=productinputs.InsertProductInputRequest): + transport_class = transports.ProductInputsServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["data_source"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "dataSource" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == request_init["data_source"] + + jsonified_request["parent"] = 'parent_value' + jsonified_request["dataSource"] = 'data_source_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("data_source", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == 'data_source_value' + + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.insert_product_input(request) + + expected_params = [ + ( + "dataSource", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_insert_product_input_rest_unset_required_fields(): + transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.insert_product_input._get_unset_required_fields({}) + assert set(unset_fields) == (set(("dataSource", )) & set(("parent", "productInput", "dataSource", ))) + + +def test_update_product_input_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc + + request = {} + client.update_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.update_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_update_product_input_rest_required_fields(request_type=productinputs.UpdateProductInputRequest): + transport_class = transports.ProductInputsServiceRestTransport + + request_init = {} + request_init["data_source"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "dataSource" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == request_init["data_source"] + + jsonified_request["dataSource"] = 'data_source_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("data_source", "update_mask", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == 'data_source_value' + + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_product_input(request) + + expected_params = [ + ( + "dataSource", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_product_input_rest_unset_required_fields(): + transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_product_input._get_unset_required_fields({}) + assert set(unset_fields) == (set(("dataSource", "updateMask", )) & set(("productInput", "dataSource", ))) + + +def test_update_product_input_rest_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput() + + # get arguments that satisfy an http rule for this method + sample_request = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + + # get truthy value for each flattened field + mock_args = dict( + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_product_input(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1beta/{product_input.name=accounts/*/productInputs/*}" % client.transport._host, args[1]) + + +def test_update_product_input_rest_flattened_error(transport: str = 'rest'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_product_input( + productinputs.UpdateProductInputRequest(), + product_input=productinputs.ProductInput(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_delete_product_input_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_product_input in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc + + request = {} + client.delete_product_input(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.delete_product_input(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_product_input_rest_required_fields(request_type=productinputs.DeleteProductInputRequest): + transport_class = transports.ProductInputsServiceRestTransport + + request_init = {} + request_init["name"] = "" + request_init["data_source"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "dataSource" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == request_init["data_source"] + + jsonified_request["name"] = 'name_value' + jsonified_request["dataSource"] = 'data_source_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("data_source", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + assert "dataSource" in jsonified_request + assert jsonified_request["dataSource"] == 'data_source_value' + + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_product_input(request) + + expected_params = [ + ( + "dataSource", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_delete_product_input_rest_unset_required_fields(): + transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.delete_product_input._get_unset_required_fields({}) + assert set(unset_fields) == (set(("dataSource", )) & set(("name", "dataSource", ))) + + +def test_delete_product_input_rest_flattened(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'accounts/sample1/productInputs/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_product_input(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1beta/{name=accounts/*/productInputs/*}" % client.transport._host, args[1]) + + +def test_delete_product_input_rest_flattened_error(transport: str = 'rest'): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_product_input( + productinputs.DeleteProductInputRequest(), + name='name_value', + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductInputsServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductInputsServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductInputsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductInputsServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + transports.ProductInputsServiceRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_kind_grpc(): + transport = ProductInputsServiceClient.get_transport_class("grpc")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "grpc" + + +def test_initialize_client_w_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_insert_product_input_empty_call_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.insert_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.InsertProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_product_input_empty_call_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + call.return_value = productinputs.ProductInput() + client.update_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.UpdateProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_product_input_empty_call_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + call.return_value = None + client.delete_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.DeleteProductInputRequest() + + assert args[0] == request_msg + + +def test_transport_kind_grpc_asyncio(): + transport = ProductInputsServiceAsyncClient.get_transport_class("grpc_asyncio")( + credentials=async_anonymous_credentials() + ) + assert transport.kind == "grpc_asyncio" + + +def test_initialize_client_w_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_insert_product_input_empty_call_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + await client.insert_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.InsertProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_product_input_empty_call_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + )) + await client.update_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.UpdateProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_product_input_empty_call_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.DeleteProductInputRequest() + + assert args[0] == request_msg + + +def test_transport_kind_rest(): + transport = ProductInputsServiceClient.get_transport_class("rest")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "rest" + + +def test_insert_product_input_rest_bad_request(request_type=productinputs.InsertProductInputRequest): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.insert_product_input(request) + + +@pytest.mark.parametrize("request_type", [ + productinputs.InsertProductInputRequest, + dict, +]) +def test_insert_product_input_rest_call_success(request_type): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request_init["product_input"] = {'name': 'name_value', 'product': 'product_value', 'channel': 1, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 'age_group_value', 'availability': 'availability_value', 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 'condition_value', 'gender': 'gender_value', 'google_product_category': 'google_product_category_value', 'gtin': ['gtin_value1', 'gtin_value2'], 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 'credit_type_value'}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 'size_system_value', 'size_types': ['size_types_value1', 'size_types_value2'], 'taxes': [{'rate': 0.428, 'country': 'country_value', 'region': 'region_value', 'tax_ship': True, 'location_id': 1157, 'postal_code': 'postal_code_value'}], 'tax_category': 'tax_category_value', 'energy_efficiency_class': 'energy_efficiency_class_value', 'min_energy_efficiency_class': 'min_energy_efficiency_class_value', 'max_energy_efficiency_class': 'max_energy_efficiency_class_value', 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 'pickup_method_value', 'pickup_sla': 'pickup_sla_value', 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': ['included_destinations_value1', 'included_destinations_value2'], 'excluded_destinations': ['excluded_destinations_value1', 'excluded_destinations_value2'], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 'pause_value', 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 'certification_authority_value', 'certification_name': 'certification_name_value', 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'structured_description': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = productinputs.InsertProductInputRequest.meta.fields["product_input"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["product_input"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + {"field": field, "subfield": subfield, "is_repeated": is_repeated} + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["product_input"][field])): + del request_init["product_input"][field][i][subfield] + else: + del request_init["product_input"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.insert_product_input(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_insert_product_input_rest_interceptors(null_interceptor): + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), + ) + client = ProductInputsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input") as post, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_insert_product_input") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = productinputs.InsertProductInputRequest.pb(productinputs.InsertProductInputRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = productinputs.ProductInput.to_json(productinputs.ProductInput()) + req.return_value.content = return_value + + request = productinputs.InsertProductInputRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = productinputs.ProductInput() + post_with_metadata.return_value = productinputs.ProductInput(), metadata + + client.insert_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_update_product_input_rest_bad_request(request_type=productinputs.UpdateProductInputRequest): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_product_input(request) + + +@pytest.mark.parametrize("request_type", [ + productinputs.UpdateProductInputRequest, + dict, +]) +def test_update_product_input_rest_call_success(request_type): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + request_init["product_input"] = {'name': 'accounts/sample1/productInputs/sample2', 'product': 'product_value', 'channel': 1, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 'age_group_value', 'availability': 'availability_value', 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 'condition_value', 'gender': 'gender_value', 'google_product_category': 'google_product_category_value', 'gtin': ['gtin_value1', 'gtin_value2'], 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 'credit_type_value'}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 'size_system_value', 'size_types': ['size_types_value1', 'size_types_value2'], 'taxes': [{'rate': 0.428, 'country': 'country_value', 'region': 'region_value', 'tax_ship': True, 'location_id': 1157, 'postal_code': 'postal_code_value'}], 'tax_category': 'tax_category_value', 'energy_efficiency_class': 'energy_efficiency_class_value', 'min_energy_efficiency_class': 'min_energy_efficiency_class_value', 'max_energy_efficiency_class': 'max_energy_efficiency_class_value', 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 'pickup_method_value', 'pickup_sla': 'pickup_sla_value', 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': ['included_destinations_value1', 'included_destinations_value2'], 'excluded_destinations': ['excluded_destinations_value1', 'excluded_destinations_value2'], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 'pause_value', 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 'certification_authority_value', 'certification_name': 'certification_name_value', 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'structured_description': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = productinputs.UpdateProductInputRequest.meta.fields["product_input"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["product_input"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + {"field": field, "subfield": subfield, "is_repeated": is_repeated} + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["product_input"][field])): + del request_init["product_input"][field][i][subfield] + else: + del request_init["product_input"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = productinputs.ProductInput( + name='name_value', + product='product_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + version_number=1518, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = productinputs.ProductInput.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_product_input(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, productinputs.ProductInput) + assert response.name == 'name_value' + assert response.product == 'product_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.version_number == 1518 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_product_input_rest_interceptors(null_interceptor): + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), + ) + client = ProductInputsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input") as post, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_update_product_input") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = productinputs.UpdateProductInputRequest.pb(productinputs.UpdateProductInputRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = productinputs.ProductInput.to_json(productinputs.ProductInput()) + req.return_value.content = return_value + + request = productinputs.UpdateProductInputRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = productinputs.ProductInput() + post_with_metadata.return_value = productinputs.ProductInput(), metadata + + client.update_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_delete_product_input_rest_bad_request(request_type=productinputs.DeleteProductInputRequest): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/productInputs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_product_input(request) + + +@pytest.mark.parametrize("request_type", [ + productinputs.DeleteProductInputRequest, + dict, +]) +def test_delete_product_input_rest_call_success(request_type): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/productInputs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = '' + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_product_input(request) + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_product_input_rest_interceptors(null_interceptor): + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), + ) + client = ProductInputsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_delete_product_input") as pre: + pre.assert_not_called() + pb_message = productinputs.DeleteProductInputRequest.pb(productinputs.DeleteProductInputRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + request = productinputs.DeleteProductInputRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + +def test_initialize_client_w_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_insert_product_input_empty_call_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.insert_product_input), + '__call__') as call: + client.insert_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.InsertProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_product_input_empty_call_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_product_input), + '__call__') as call: + client.update_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.UpdateProductInputRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_product_input_empty_call_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_product_input), + '__call__') as call: + client.delete_product_input(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = productinputs.DeleteProductInputRequest() + + assert args[0] == request_msg + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductInputsServiceGrpcTransport, + ) + +def test_product_inputs_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductInputsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_product_inputs_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductInputsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'insert_product_input', + 'update_product_input', + 'delete_product_input', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_product_inputs_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductInputsServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id="octopus", + ) + + +def test_product_inputs_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductInputsServiceTransport() + adc.assert_called_once() + + +def test_product_inputs_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ProductInputsServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + ], +) +def test_product_inputs_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/content',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + transports.ProductInputsServiceRestTransport, + ], +) +def test_product_inputs_service_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductInputsServiceGrpcTransport, grpc_helpers), + (transports.ProductInputsServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_product_inputs_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=["1", "2"], + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +def test_product_inputs_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_product_inputs_service_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.ProductInputsServiceRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_product_inputs_service_host_no_port(transport_name): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_product_inputs_service_host_with_port(transport_name): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_product_inputs_service_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = ProductInputsServiceClient( + credentials=creds1, + transport=transport_name, + ) + client2 = ProductInputsServiceClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.insert_product_input._session + session2 = client2.transport.insert_product_input._session + assert session1 != session2 + session1 = client1.transport.update_product_input._session + session2 = client2.transport.update_product_input._session + assert session1 != session2 + session1 = client1.transport.delete_product_input._session + session2 = client2.transport.delete_product_input._session + assert session1 != session2 +def test_product_inputs_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductInputsServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_product_inputs_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductInputsServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +def test_product_inputs_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +def test_product_inputs_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_product_path(): + account = "squid" + product = "clam" + expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) + actual = ProductInputsServiceClient.product_path(account, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "account": "whelk", + "product": "octopus", + } + path = ProductInputsServiceClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_product_path(path) + assert expected == actual + +def test_product_input_path(): + account = "oyster" + productinput = "nudibranch" + expected = "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) + actual = ProductInputsServiceClient.product_input_path(account, productinput) + assert expected == actual + + +def test_parse_product_input_path(): + expected = { + "account": "cuttlefish", + "productinput": "mussel", + } + path = ProductInputsServiceClient.product_input_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_product_input_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductInputsServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = ProductInputsServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductInputsServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = ProductInputsServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductInputsServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = ProductInputsServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format(project=project, ) + actual = ProductInputsServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = ProductInputsServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductInputsServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = ProductInputsServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductInputsServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductInputsServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +def test_transport_close_grpc(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +@pytest.mark.asyncio +async def test_transport_close_grpc_asyncio(): + client = ProductInputsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close_rest(): + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = ProductInputsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport), + (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py new file mode 100644 index 000000000000..767ed2b7bcca --- /dev/null +++ b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py @@ -0,0 +1,3099 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable, AsyncIterable +from google.protobuf import json_format +import json +import math +import pytest +from google.api_core import api_core_version +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +try: + from google.auth.aio import credentials as ga_credentials_async + HAS_GOOGLE_AUTH_AIO = True +except ImportError: # pragma: NO COVER + HAS_GOOGLE_AUTH_AIO = False + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.oauth2 import service_account +from google.shopping.merchant_products_v1beta.services.products_service import ProductsServiceAsyncClient +from google.shopping.merchant_products_v1beta.services.products_service import ProductsServiceClient +from google.shopping.merchant_products_v1beta.services.products_service import pagers +from google.shopping.merchant_products_v1beta.services.products_service import transports +from google.shopping.merchant_products_v1beta.types import products +from google.shopping.merchant_products_v1beta.types import products_common +from google.shopping.type.types import types +import google.auth + + + +CRED_INFO_JSON = { + "credential_source": "/path/to/file", + "credential_type": "service account credentials", + "principal": "service-account@example.com", +} +CRED_INFO_STRING = json.dumps(CRED_INFO_JSON) + + +async def mock_async_gen(data, chunk_size=1): + for i in range(0, len(data)): # pragma: NO COVER + chunk = data[i : i + chunk_size] + yield chunk.encode("utf-8") + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + +# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. +# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. +def async_anonymous_credentials(): + if HAS_GOOGLE_AUTH_AIO: + return ga_credentials_async.AnonymousCredentials() + return ga_credentials.AnonymousCredentials() + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + +# If default endpoint template is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint template so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint_template(client): + return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert ProductsServiceClient._get_default_mtls_endpoint(None) is None + assert ProductsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert ProductsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + +def test__read_environment_variables(): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ProductsServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + ProductsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + assert ProductsServiceClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ProductsServiceClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductsServiceClient._read_environment_variables() + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): + assert ProductsServiceClient._read_environment_variables() == (False, "auto", "foo.com") + +def test__get_client_cert_source(): + mock_provided_cert_source = mock.Mock() + mock_default_cert_source = mock.Mock() + + assert ProductsServiceClient._get_client_cert_source(None, False) is None + assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None + assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source + + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): + assert ProductsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source + assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source + +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ProductsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + assert ProductsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override + assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint + assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + assert ProductsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint + assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint + + with pytest.raises(MutualTLSChannelError) as excinfo: + ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") + assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." + + +def test__get_universe_domain(): + client_universe_domain = "foo.com" + universe_domain_env = "bar.com" + + assert ProductsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain + assert ProductsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env + assert ProductsServiceClient._get_universe_domain(None, None) == ProductsServiceClient._DEFAULT_UNIVERSE + + with pytest.raises(ValueError) as excinfo: + ProductsServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + +@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ + (401, CRED_INFO_JSON, True), + (403, CRED_INFO_JSON, True), + (404, CRED_INFO_JSON, True), + (500, CRED_INFO_JSON, False), + (401, None, False), + (403, None, False), + (404, None, False), + (500, None, False) +]) +def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): + cred = mock.Mock(["get_cred_info"]) + cred.get_cred_info = mock.Mock(return_value=cred_info_json) + client = ProductsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=["foo"]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + if show_cred_info: + assert error.details == ["foo", CRED_INFO_STRING] + else: + assert error.details == ["foo"] + +@pytest.mark.parametrize("error_code", [401,403,404,500]) +def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): + cred = mock.Mock([]) + assert not hasattr(cred, "get_cred_info") + client = ProductsServiceClient(credentials=cred) + client._transport._credentials = cred + + error = core_exceptions.GoogleAPICallError("message", details=[]) + error.code = error_code + + client._add_cred_info_for_auth_errors(error) + assert error.details == [] + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductsServiceClient, "grpc"), + (ProductsServiceAsyncClient, "grpc_asyncio"), + (ProductsServiceClient, "rest"), +]) +def test_products_service_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.ProductsServiceGrpcTransport, "grpc"), + (transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.ProductsServiceRestTransport, "rest"), +]) +def test_products_service_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (ProductsServiceClient, "grpc"), + (ProductsServiceAsyncClient, "grpc_asyncio"), + (ProductsServiceClient, "rest"), +]) +def test_products_service_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://merchantapi.googleapis.com' + ) + + +def test_products_service_client_get_transport_class(): + transport = ProductsServiceClient.get_transport_class() + available_transports = [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceRestTransport, + ] + assert transport in available_transports + + transport = ProductsServiceClient.get_transport_class("grpc") + assert transport == transports.ProductsServiceGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), +]) +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +def test_products_service_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client = client_class(transport=transport_name) + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "true"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "false"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "true"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "false"), +]) +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_products_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + ProductsServiceClient, ProductsServiceAsyncClient +]) +@mock.patch.object(ProductsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceAsyncClient)) +def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError) as excinfo: + client_class.get_mtls_endpoint_and_cert_source() + + assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + +@pytest.mark.parametrize("client_class", [ + ProductsServiceClient, ProductsServiceAsyncClient +]) +@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) +@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +def test_products_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ProductsServiceClient._DEFAULT_UNIVERSE + default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + mock_universe = "bar.com" + mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + + # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", + # use ClientOptions.api_endpoint as the api endpoint regardless. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == api_override + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", + # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + client = client_class(credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + + # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), + # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, + # and ClientOptions.universe_domain="bar.com", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. + options = client_options.ClientOptions() + universe_exists = hasattr(options, "universe_domain") + if universe_exists: + options = client_options.ClientOptions(universe_domain=mock_universe) + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + else: + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) + assert client.universe_domain == (mock_universe if universe_exists else default_universe) + + # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", + # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. + options = client_options.ClientOptions() + if hasattr(options, "universe_domain"): + delattr(options, "universe_domain") + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + assert client.api_endpoint == default_endpoint + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), +]) +def test_products_service_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", None), +]) +def test_products_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_products_service_client_client_options_from_dict(): + with mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = ProductsServiceClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_products_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=None, + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + products.GetProductRequest, + dict, +]) +def test_get_product(request_type, transport: str = 'grpc'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.Product( + name='name_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + ) + response = client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = products.GetProductRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, products.Product) + assert response.name == 'name_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.data_source == 'data_source_value' + assert response.version_number == 1518 + + +def test_get_product_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = products.GetProductRequest( + name='name_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.get_product(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == products.GetProductRequest( + name='name_value', + ) + +def test_get_product_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_product in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.get_product] = mock_rpc + request = {} + client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_product(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_get_product_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.get_product in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.get_product] = mock_rpc + + request = {} + await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.get_product(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=products.GetProductRequest): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.Product( + name='name_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + )) + response = await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = products.GetProductRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, products.Product) + assert response.name == 'name_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.data_source == 'data_source_value' + assert response.version_number == 1518 + + +@pytest.mark.asyncio +async def test_get_product_async_from_dict(): + await test_get_product_async(request_type=dict) + +def test_get_product_field_headers(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.GetProductRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = products.Product() + client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_product_field_headers_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.GetProductRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) + await client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_product_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.Product() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_product( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_product_flattened_error(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_product( + products.GetProductRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_product_flattened_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.Product() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_product( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_product_flattened_error_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_product( + products.GetProductRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + products.ListProductsRequest, + dict, +]) +def test_list_products(request_type, transport: str = 'grpc'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.ListProductsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = products.ListProductsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_products_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = products.ListProductsRequest( + parent='parent_value', + page_token='page_token_value', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client.list_products(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == products.ListProductsRequest( + parent='parent_value', + page_token='page_token_value', + ) + +def test_list_products_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_products in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.list_products] = mock_rpc + request = {} + client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_products(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_list_products_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._client._transport.list_products in client._client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[client._client._transport.list_products] = mock_rpc + + request = {} + await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.list_products(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + +@pytest.mark.asyncio +async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=products.ListProductsRequest): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = products.ListProductsRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_products_async_from_dict(): + await test_list_products_async(request_type=dict) + +def test_list_products_field_headers(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.ListProductsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = products.ListProductsResponse() + client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_products_field_headers_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = products.ListProductsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) + await client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_products_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.ListProductsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_products( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_products_flattened_error(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_products( + products.ListProductsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_products_flattened_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = products.ListProductsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_products( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_products_flattened_error_async(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_products( + products.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_pager(transport_name: str = "grpc"): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_products(request={}, retry=retry, timeout=timeout) + + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, products.Product) + for i in results) +def test_list_products_pages(transport_name: str = "grpc"): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + pages = list(client.list_products(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_products_async_pager(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_products(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, products.Product) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_products_async_pages(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_products(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +def test_get_product_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_product in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.get_product] = mock_rpc + + request = {} + client.get_product(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_product(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_product_rest_required_fields(request_type=products.GetProductRequest): + transport_class = transports.ProductsServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = products.Product() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.Product.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_product(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_product_rest_unset_required_fields(): + transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_product._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +def test_get_product_rest_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.Product() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'accounts/sample1/products/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = products.Product.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_product(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1beta/{name=accounts/*/products/*}" % client.transport._host, args[1]) + + +def test_get_product_rest_flattened_error(transport: str = 'rest'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_product( + products.GetProductRequest(), + name='name_value', + ) + + +def test_list_products_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_products in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + client._transport._wrapped_methods[client._transport.list_products] = mock_rpc + + request = {} + client.list_products(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_products(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_products_rest_required_fields(request_type=products.ListProductsRequest): + transport_class = transports.ProductsServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = products.ListProductsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.ListProductsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_products(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_products_rest_unset_required_fields(): + transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_products._get_unset_required_fields({}) + assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) + + +def test_list_products_rest_flattened(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.ListProductsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'accounts/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = products.ListProductsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_products(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/products/v1beta/{parent=accounts/*}/products" % client.transport._host, args[1]) + + +def test_list_products_rest_flattened_error(transport: str = 'rest'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_products( + products.ListProductsRequest(), + parent='parent_value', + ) + + +def test_list_products_rest_pager(transport: str = 'rest'): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + products.Product(), + ], + next_page_token='abc', + ), + products.ListProductsResponse( + products=[], + next_page_token='def', + ), + products.ListProductsResponse( + products=[ + products.Product(), + ], + next_page_token='ghi', + ), + products.ListProductsResponse( + products=[ + products.Product(), + products.Product(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(products.ListProductsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'accounts/sample1'} + + pager = client.list_products(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, products.Product) + for i in results) + + pages = list(client.list_products(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ProductsServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ProductsServiceClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ProductsServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ProductsServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + transports.ProductsServiceRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +def test_transport_kind_grpc(): + transport = ProductsServiceClient.get_transport_class("grpc")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "grpc" + + +def test_initialize_client_w_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_product_empty_call_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + call.return_value = products.Product() + client.get_product(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.GetProductRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_products_empty_call_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + call.return_value = products.ListProductsResponse() + client.list_products(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.ListProductsRequest() + + assert args[0] == request_msg + + +def test_transport_kind_grpc_asyncio(): + transport = ProductsServiceAsyncClient.get_transport_class("grpc_asyncio")( + credentials=async_anonymous_credentials() + ) + assert transport.kind == "grpc_asyncio" + + +def test_initialize_client_w_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_product_empty_call_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product( + name='name_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + )) + await client.get_product(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.GetProductRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_products_empty_call_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( + next_page_token='next_page_token_value', + )) + await client.list_products(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.ListProductsRequest() + + assert args[0] == request_msg + + +def test_transport_kind_rest(): + transport = ProductsServiceClient.get_transport_class("rest")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "rest" + + +def test_get_product_rest_bad_request(request_type=products.GetProductRequest): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/products/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_product(request) + + +@pytest.mark.parametrize("request_type", [ + products.GetProductRequest, + dict, +]) +def test_get_product_rest_call_success(request_type): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'accounts/sample1/products/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.Product( + name='name_value', + channel=types.Channel.ChannelEnum.ONLINE, + offer_id='offer_id_value', + content_language='content_language_value', + feed_label='feed_label_value', + data_source='data_source_value', + version_number=1518, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.Product.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_product(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, products.Product) + assert response.name == 'name_value' + assert response.channel == types.Channel.ChannelEnum.ONLINE + assert response.offer_id == 'offer_id_value' + assert response.content_language == 'content_language_value' + assert response.feed_label == 'feed_label_value' + assert response.data_source == 'data_source_value' + assert response.version_number == 1518 + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_product_rest_interceptors(null_interceptor): + transport = transports.ProductsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), + ) + client = ProductsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product") as post, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_get_product") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = products.GetProductRequest.pb(products.GetProductRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = products.Product.to_json(products.Product()) + req.return_value.content = return_value + + request = products.GetProductRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = products.Product() + post_with_metadata.return_value = products.Product(), metadata + + client.get_product(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_products_rest_bad_request(request_type=products.ListProductsRequest): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = '' + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_products(request) + + +@pytest.mark.parametrize("request_type", [ + products.ListProductsRequest, + dict, +]) +def test_list_products_rest_call_success(request_type): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'accounts/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = products.ListProductsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = products.ListProductsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode('UTF-8') + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_products(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListProductsPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_products_rest_interceptors(null_interceptor): + transport = transports.ProductsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), + ) + client = ProductsServiceClient(transport=transport) + + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products") as post, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products_with_metadata") as post_with_metadata, \ + mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_list_products") as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = products.ListProductsRequest.pb(products.ListProductsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = products.ListProductsResponse.to_json(products.ListProductsResponse()) + req.return_value.content = return_value + + request = products.ListProductsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = products.ListProductsResponse() + post_with_metadata.return_value = products.ListProductsResponse(), metadata + + client.list_products(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + +def test_initialize_client_w_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_product_empty_call_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_product), + '__call__') as call: + client.get_product(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.GetProductRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_products_empty_call_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_products), + '__call__') as call: + client.list_products(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = products.ListProductsRequest() + + assert args[0] == request_msg + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ProductsServiceGrpcTransport, + ) + +def test_products_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ProductsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_products_service_base_transport(): + # Instantiate the base transport. + with mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.ProductsServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'get_product', + 'list_products', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_products_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductsServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id="octopus", + ) + + +def test_products_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ProductsServiceTransport() + adc.assert_called_once() + + +def test_products_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ProductsServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + ], +) +def test_products_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/content',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + transports.ProductsServiceRestTransport, + ], +) +def test_products_service_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ProductsServiceGrpcTransport, grpc_helpers), + (transports.ProductsServiceGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_products_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "merchantapi.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/content', +), + scopes=["1", "2"], + default_host="merchantapi.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +def test_products_service_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_products_service_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.ProductsServiceRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_products_service_host_no_port(transport_name): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_products_service_host_with_port(transport_name): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'merchantapi.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://merchantapi.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_products_service_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = ProductsServiceClient( + credentials=creds1, + transport=transport_name, + ) + client2 = ProductsServiceClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.get_product._session + session2 = client2.transport.get_product._session + assert session1 != session2 + session1 = client1.transport.list_products._session + session2 = client2.transport.list_products._session + assert session1 != session2 +def test_products_service_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductsServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_products_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ProductsServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +def test_products_service_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +def test_products_service_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_product_path(): + account = "squid" + product = "clam" + expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) + actual = ProductsServiceClient.product_path(account, product) + assert expected == actual + + +def test_parse_product_path(): + expected = { + "account": "whelk", + "product": "octopus", + } + path = ProductsServiceClient.product_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_product_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "oyster" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = ProductsServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nudibranch", + } + path = ProductsServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "cuttlefish" + expected = "folders/{folder}".format(folder=folder, ) + actual = ProductsServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "mussel", + } + path = ProductsServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "winkle" + expected = "organizations/{organization}".format(organization=organization, ) + actual = ProductsServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nautilus", + } + path = ProductsServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "scallop" + expected = "projects/{project}".format(project=project, ) + actual = ProductsServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "abalone", + } + path = ProductsServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "squid" + location = "clam" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = ProductsServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "whelk", + "location": "octopus", + } + path = ProductsServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ProductsServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: + transport_class = ProductsServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +def test_transport_close_grpc(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +@pytest.mark.asyncio +async def test_transport_close_grpc_asyncio(): + client = ProductsServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio" + ) + with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close_rest(): + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest" + ) + with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = ProductsServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) From 7d389388e967932a1fa598e124da91187c34ed2e Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 5 Aug 2025 13:02:10 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../v1/.coveragerc | 13 - .../v1/.flake8 | 34 - .../v1/LICENSE | 202 - .../v1/MANIFEST.in | 20 - .../v1/README.rst | 143 - .../v1/docs/_static/custom.css | 20 - .../v1/docs/_templates/layout.html | 50 - .../v1/docs/conf.py | 385 -- .../v1/docs/index.rst | 10 - .../v1/docs/multiprocessing.rst | 7 - .../shopping/merchant_products/__init__.py | 119 - .../shopping/merchant_products_v1/__init__.py | 120 - .../merchant_products_v1/gapic_version.py | 16 - .../shopping/merchant_products_v1/py.typed | 2 - .../services/products_service/__init__.py | 22 - .../v1/mypy.ini | 3 - .../v1/noxfile.py | 591 --- .../v1/setup.py | 99 - .../v1/testing/constraints-3.10.txt | 7 - .../v1/testing/constraints-3.11.txt | 7 - .../v1/testing/constraints-3.12.txt | 7 - .../v1/testing/constraints-3.13.txt | 12 - .../v1/testing/constraints-3.7.txt | 11 - .../v1/testing/constraints-3.8.txt | 7 - .../v1/testing/constraints-3.9.txt | 7 - .../v1/tests/__init__.py | 16 - .../v1/tests/unit/__init__.py | 16 - .../v1/tests/unit/gapic/__init__.py | 16 - .../gapic/merchant_products_v1/__init__.py | 16 - .../v1beta/.coveragerc | 13 - .../v1beta/.flake8 | 34 - .../v1beta/LICENSE | 202 - .../v1beta/MANIFEST.in | 20 - .../v1beta/README.rst | 143 - .../v1beta/docs/_static/custom.css | 20 - .../v1beta/docs/_templates/layout.html | 50 - .../v1beta/docs/conf.py | 385 -- .../v1beta/docs/index.rst | 10 - .../product_inputs_service.rst | 6 - .../products_service.rst | 10 - .../merchant_products_v1beta/services_.rst | 7 - .../docs/merchant_products_v1beta/types_.rst | 6 - .../v1beta/docs/multiprocessing.rst | 7 - .../shopping/merchant_products/__init__.py | 93 - .../merchant_products/gapic_version.py | 16 - .../shopping/merchant_products/py.typed | 2 - .../merchant_products_v1beta/__init__.py | 94 - .../gapic_metadata.json | 122 - .../merchant_products_v1beta/gapic_version.py | 16 - .../merchant_products_v1beta/py.typed | 2 - .../product_inputs_service/__init__.py | 22 - .../product_inputs_service/async_client.py | 689 ---- .../services/product_inputs_service/client.py | 1057 ----- .../transports/README.rst | 9 - .../transports/__init__.py | 38 - .../product_inputs_service/transports/base.py | 188 - .../product_inputs_service/transports/grpc.py | 419 -- .../transports/grpc_asyncio.py | 450 --- .../product_inputs_service/transports/rest.py | 711 ---- .../transports/rest_base.py | 223 - .../services/products_service/async_client.py | 522 --- .../services/products_service/client.py | 881 ---- .../services/products_service/pagers.py | 166 - .../products_service/transports/README.rst | 9 - .../products_service/transports/__init__.py | 38 - .../products_service/transports/base.py | 173 - .../products_service/transports/grpc.py | 383 -- .../transports/grpc_asyncio.py | 409 -- .../products_service/transports/rest.py | 542 --- .../products_service/transports/rest_base.py | 165 - .../types/__init__.py | 86 - .../types/productinputs.py | 305 -- .../types/products.py | 260 -- .../types/products_common.py | 2109 ---------- .../v1beta/mypy.ini | 3 - .../v1beta/noxfile.py | 591 --- ...puts_service_delete_product_input_async.py | 51 - ...nputs_service_delete_product_input_sync.py | 51 - ...puts_service_insert_product_input_async.py | 59 - ...nputs_service_insert_product_input_sync.py | 59 - ...puts_service_update_product_input_async.py | 58 - ...nputs_service_update_product_input_sync.py | 58 - ...ated_products_service_get_product_async.py | 52 - ...rated_products_service_get_product_sync.py | 52 - ...ed_products_service_list_products_async.py | 53 - ...ted_products_service_list_products_sync.py | 53 - ...gle.shopping.merchant.products.v1beta.json | 814 ---- ...fixup_merchant_products_v1beta_keywords.py | 180 - .../v1beta/setup.py | 99 - .../v1beta/testing/constraints-3.10.txt | 7 - .../v1beta/testing/constraints-3.11.txt | 7 - .../v1beta/testing/constraints-3.12.txt | 7 - .../v1beta/testing/constraints-3.13.txt | 12 - .../v1beta/testing/constraints-3.7.txt | 11 - .../v1beta/testing/constraints-3.8.txt | 7 - .../v1beta/testing/constraints-3.9.txt | 7 - .../v1beta/tests/__init__.py | 16 - .../v1beta/tests/unit/__init__.py | 16 - .../v1beta/tests/unit/gapic/__init__.py | 16 - .../merchant_products_v1beta/__init__.py | 16 - .../test_product_inputs_service.py | 3573 ----------------- .../test_products_service.py | 3099 -------------- .../docs/index.rst | 11 + .../product_inputs_service.rst | 0 .../merchant_products_v1/products_service.rst | 0 .../docs/merchant_products_v1/services_.rst | 0 .../docs/merchant_products_v1/types_.rst | 0 .../merchant_products/gapic_version.py | 2 +- .../shopping/merchant_products_v1/__init__.py | 126 + .../merchant_products_v1/gapic_metadata.json | 0 .../merchant_products_v1}/gapic_version.py | 0 .../shopping/merchant_products_v1}/py.typed | 0 .../merchant_products_v1/services/__init__.py | 0 .../product_inputs_service/__init__.py | 6 +- .../product_inputs_service/async_client.py | 220 +- .../services/product_inputs_service/client.py | 386 +- .../transports/README.rst | 0 .../transports/__init__.py | 24 +- .../product_inputs_service/transports/base.py | 118 +- .../product_inputs_service/transports/grpc.py | 136 +- .../transports/grpc_asyncio.py | 146 +- .../product_inputs_service/transports/rest.py | 418 +- .../transports/rest_base.py | 160 +- .../services/products_service/__init__.py | 6 +- .../services/products_service/async_client.py | 189 +- .../services/products_service/client.py | 346 +- .../services/products_service/pagers.py | 75 +- .../products_service/transports/README.rst | 0 .../products_service/transports/__init__.py | 20 +- .../products_service/transports/base.py | 104 +- .../products_service/transports/grpc.py | 114 +- .../transports/grpc_asyncio.py | 126 +- .../products_service/transports/rest.py | 282 +- .../products_service/transports/rest_base.py | 106 +- .../merchant_products_v1/types/__init__.py | 118 +- .../types/productinputs.py | 23 +- .../merchant_products_v1/types/products.py | 17 +- .../types/products_common.py | 262 +- .../merchant_products_v1beta/gapic_version.py | 2 +- ...puts_service_delete_product_input_async.py | 0 ...nputs_service_delete_product_input_sync.py | 0 ...puts_service_insert_product_input_async.py | 0 ...nputs_service_insert_product_input_sync.py | 0 ...puts_service_update_product_input_async.py | 0 ...nputs_service_update_product_input_sync.py | 0 ...ated_products_service_get_product_async.py | 0 ...rated_products_service_get_product_sync.py | 0 ...ed_products_service_list_products_async.py | 0 ...ted_products_service_list_products_sync.py | 0 ..._google.shopping.merchant.products.v1.json | 0 ...gle.shopping.merchant.products.v1beta.json | 2 +- .../fixup_merchant_products_v1_keywords.py | 0 .../gapic/merchant_products_v1}/__init__.py | 0 .../test_product_inputs_service.py | 2632 ++++++++---- .../test_products_service.py | 1859 ++++++--- 155 files changed, 5247 insertions(+), 24906 deletions(-) delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/.flake8 delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/LICENSE delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/README.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/setup.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py delete mode 100644 owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/docs/merchant_products_v1/product_inputs_service.rst (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/docs/merchant_products_v1/products_service.rst (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/docs/merchant_products_v1/services_.rst (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/docs/merchant_products_v1/types_.rst (100%) create mode 100644 packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/__init__.py rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/gapic_metadata.json (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products => packages/google-shopping-merchant-products/google/shopping/merchant_products_v1}/gapic_version.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products => packages/google-shopping-merchant-products/google/shopping/merchant_products_v1}/py.typed (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/__init__.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py (90%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py (84%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/client.py (81%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py (59%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py (67%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py (84%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py (83%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py (73%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py (61%) rename {owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta => packages/google-shopping-merchant-products/google/shopping/merchant_products_v1}/services/products_service/__init__.py (91%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/async_client.py (82%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/client.py (79%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/pagers.py (79%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/README.rst (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py (67%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/base.py (68%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py (85%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py (84%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/rest.py (75%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py (65%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/types/__init__.py (61%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/types/productinputs.py (97%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/types/products.py (97%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/google/shopping/merchant_products_v1/types/products_common.py (93%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/scripts/fixup_merchant_products_v1_keywords.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services => packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1}/__init__.py (100%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py (61%) rename {owl-bot-staging/google-shopping-merchant-products/v1 => packages/google-shopping-merchant-products}/tests/unit/gapic/merchant_products_v1/test_products_service.py (68%) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc b/owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc deleted file mode 100644 index 0d94c2da5109..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/.coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/shopping/merchant_products/__init__.py - google/shopping/merchant_products/gapic_version.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/.flake8 b/owl-bot-staging/google-shopping-merchant-products/v1/.flake8 deleted file mode 100644 index 90316de21489..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/.flake8 +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -[flake8] -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): -# Resolve flake8 lint issues -ignore = E203, E231, E266, E501, W503 -exclude = - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): - # Ensure that generated code passes flake8 lint - **/gapic/** - **/services/** - **/types/** - # Exclude Protobuf gencode - *_pb2.py - - # Standard linting exemptions. - **/.nox/** - __pycache__, - .git, - *.pyc, - conf.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/LICENSE b/owl-bot-staging/google-shopping-merchant-products/v1/LICENSE deleted file mode 100644 index d64569567334..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in b/owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in deleted file mode 100644 index dae249ec8976..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/MANIFEST.in +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -include README.rst LICENSE -recursive-include google *.py *.pyi *.json *.proto py.typed -recursive-include tests * -global-exclude *.py[co] -global-exclude __pycache__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1/README.rst deleted file mode 100644 index f80c16dfa082..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/README.rst +++ /dev/null @@ -1,143 +0,0 @@ -Python Client for Google Shopping Merchant Products API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Shopping Merchant Products API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library - - -Logging -------- - -This library uses the standard Python :code:`logging` functionality to log some RPC events that could be of interest for debugging and monitoring purposes. -Note the following: - -#. Logs may contain sensitive information. Take care to **restrict access to the logs** if they are saved, whether it be on local storage or on Google Cloud Logging. -#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**. -#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below. - - -Simple, environment-based configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -To enable logging for this library without any changes in your code, set the :code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to a valid Google -logging scope. This configures handling of logging events (at level :code:`logging.DEBUG` or higher) from this library in a default manner, emitting the logged -messages in a structured format. It does not currently allow customizing the logging levels captured nor the handlers, formatters, etc. used for any logging -event. - -A logging scope is a period-separated namespace that begins with :code:`google`, identifying the Python module or package to log. - -- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc. -- Invalid logging scopes: :code:`foo`, :code:`123`, etc. - -**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers. - - -Examples -^^^^^^^^ - -- Enabling the default handler for all Google-based loggers - -.. code-block:: console - - export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google - -- Enabling the default handler for a specific Google module (for a client library called :code:`library_v1`): - -.. code-block:: console - - export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1 - - -Advanced, code-based configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also configure a valid logging scope using Python's standard `logging` mechanism. - - -Examples -^^^^^^^^ - -- Configuring a handler for all Google-based loggers - -.. code-block:: python - - import logging - - from google.cloud.translate_v3 import translate - - base_logger = logging.getLogger("google") - base_logger.addHandler(logging.StreamHandler()) - base_logger.setLevel(logging.DEBUG) - -- Configuring a handler for a specific Google module (for a client library called :code:`library_v1`): - -.. code-block:: python - - import logging - - from google.cloud.translate_v3 import translate - - base_logger = logging.getLogger("google.cloud.library_v1") - base_logger.addHandler(logging.StreamHandler()) - base_logger.setLevel(logging.DEBUG) - - -Logging details -~~~~~~~~~~~~~~~ - -#. Regardless of which of the mechanisms above you use to configure logging for this library, by default logging events are not propagated up to the root - logger from the `google`-level logger. If you need the events to be propagated to the root logger, you must explicitly set - :code:`logging.getLogger("google").propagate = True` in your code. -#. You can mix the different logging configurations above for different Google modules. For example, you may want use a code-based logging configuration for - one library, but decide you need to also set up environment-based logging configuration for another library. - - #. If you attempt to use both code-based and environment-based configuration for the same module, the environment-based configuration will be ineffectual - if the code -based configuration gets applied first. - -#. The Google-specific logging configurations (default handlers for environment-based configuration; not propagating logging events to the root logger) get - executed the first time *any* client library is instantiated in your application, and only if the affected loggers have not been previously configured. - (This is the reason for 2.i. above.) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css b/owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css deleted file mode 100644 index b0a295464b23..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/docs/_static/custom.css +++ /dev/null @@ -1,20 +0,0 @@ -div#python2-eol { - border-color: red; - border-width: medium; -} - -/* Ensure minimum width for 'Parameters' / 'Returns' column */ -dl.field-list > dt { - min-width: 100px -} - -/* Insert space between methods for readability */ -dl.method { - padding-top: 10px; - padding-bottom: 10px -} - -/* Insert empty space between classes */ -dl.class { - padding-bottom: 50px -} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html b/owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html deleted file mode 100644 index 95e9c77fcfe1..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/docs/_templates/layout.html +++ /dev/null @@ -1,50 +0,0 @@ - -{% extends "!layout.html" %} -{%- block content %} -{%- if theme_fixed_sidebar|lower == 'true' %} -
- {{ sidebar() }} - {%- block document %} -
- {%- if render_sidebar %} -
- {%- endif %} - - {%- block relbar_top %} - {%- if theme_show_relbar_top|tobool %} - - {%- endif %} - {% endblock %} - -
-
- As of January 1, 2020 this library no longer supports Python 2 on the latest released version. - Library versions released prior to that date will continue to be available. For more information please - visit Python 2 support on Google Cloud. -
- {% block body %} {% endblock %} -
- - {%- block relbar_bottom %} - {%- if theme_show_relbar_bottom|tobool %} - - {%- endif %} - {% endblock %} - - {%- if render_sidebar %} -
- {%- endif %} -
- {%- endblock %} -
-
-{%- else %} -{{ super() }} -{%- endif %} -{%- endblock %} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py b/owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py deleted file mode 100644 index 302daf996542..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/docs/conf.py +++ /dev/null @@ -1,385 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-shopping-merchant-products documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -# For plugins that can not read conf.py. -# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 -sys.path.insert(0, os.path.abspath(".")) - -__version__ = "" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "4.5.0" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.doctest", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", - "recommonmark", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_options = {"members": True} -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# source_suffix = ['.rst', '.md'] -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The root toctree document. -root_doc = "index" - -# General information about the project. -project = u"google-shopping-merchant-products" -copyright = u"2025, Google, LLC" -author = u"Google APIs" - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = [ - "_build", - "**/.nox/**/*", - "samples/AUTHORING_GUIDE.md", - "samples/CONTRIBUTING.md", - "samples/snippets/README.rst", -] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Shopping Client Libraries for google-shopping-merchant-products", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-shopping-merchant-products-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - root_doc, - "google-shopping-merchant-products.tex", - u"google-shopping-merchant-products Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - root_doc, - "google-shopping-merchant-products", - "google-shopping-merchant-products Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - root_doc, - "google-shopping-merchant-products", - "google-shopping-merchant-products Documentation", - author, - "google-shopping-merchant-products", - "google-shopping-merchant-products Library", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("https://python.readthedocs.org/en/latest/", None), - "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ( - "https://googleapis.dev/python/google-api-core/latest/", - None, - ), - "grpc": ("https://grpc.github.io/grpc/python/", None), - "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst deleted file mode 100644 index a535ebfcdc18..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/docs/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -.. include:: multiprocessing.rst - - -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - merchant_products_v1/services_ - merchant_products_v1/types_ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst b/owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst deleted file mode 100644 index 536d17b2ea65..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/docs/multiprocessing.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. note:: - - Because this client uses :mod:`grpc` library, it is safe to - share instances across threads. In multiprocessing scenarios, the best - practice is to create client instances *after* the invocation of - :func:`os.fork` by :class:`multiprocessing.pool.Pool` or - :class:`multiprocessing.Process`. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py deleted file mode 100644 index 03a5b1c85c91..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/__init__.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.shopping.merchant_products import gapic_version as package_version - -__version__ = package_version.__version__ - - -from google.shopping.merchant_products_v1.services.product_inputs_service.client import ProductInputsServiceClient -from google.shopping.merchant_products_v1.services.product_inputs_service.async_client import ProductInputsServiceAsyncClient -from google.shopping.merchant_products_v1.services.products_service.client import ProductsServiceClient -from google.shopping.merchant_products_v1.services.products_service.async_client import ProductsServiceAsyncClient - -from google.shopping.merchant_products_v1.types.productinputs import DeleteProductInputRequest -from google.shopping.merchant_products_v1.types.productinputs import InsertProductInputRequest -from google.shopping.merchant_products_v1.types.productinputs import ProductInput -from google.shopping.merchant_products_v1.types.productinputs import UpdateProductInputRequest -from google.shopping.merchant_products_v1.types.products import GetProductRequest -from google.shopping.merchant_products_v1.types.products import ListProductsRequest -from google.shopping.merchant_products_v1.types.products import ListProductsResponse -from google.shopping.merchant_products_v1.types.products import Product -from google.shopping.merchant_products_v1.types.products_common import AutomatedDiscounts -from google.shopping.merchant_products_v1.types.products_common import CloudExportAdditionalProperties -from google.shopping.merchant_products_v1.types.products_common import FreeShippingThreshold -from google.shopping.merchant_products_v1.types.products_common import LoyaltyPoints -from google.shopping.merchant_products_v1.types.products_common import LoyaltyProgram -from google.shopping.merchant_products_v1.types.products_common import ProductAttributes -from google.shopping.merchant_products_v1.types.products_common import ProductCertification -from google.shopping.merchant_products_v1.types.products_common import ProductDetail -from google.shopping.merchant_products_v1.types.products_common import ProductDimension -from google.shopping.merchant_products_v1.types.products_common import ProductInstallment -from google.shopping.merchant_products_v1.types.products_common import ProductStatus -from google.shopping.merchant_products_v1.types.products_common import ProductSustainabilityIncentive -from google.shopping.merchant_products_v1.types.products_common import ProductWeight -from google.shopping.merchant_products_v1.types.products_common import Shipping -from google.shopping.merchant_products_v1.types.products_common import ShippingDimension -from google.shopping.merchant_products_v1.types.products_common import ShippingWeight -from google.shopping.merchant_products_v1.types.products_common import StructuredDescription -from google.shopping.merchant_products_v1.types.products_common import StructuredTitle -from google.shopping.merchant_products_v1.types.products_common import SubscriptionCost -from google.shopping.merchant_products_v1.types.products_common import UnitPricingBaseMeasure -from google.shopping.merchant_products_v1.types.products_common import UnitPricingMeasure -from google.shopping.merchant_products_v1.types.products_common import AgeGroup -from google.shopping.merchant_products_v1.types.products_common import Availability -from google.shopping.merchant_products_v1.types.products_common import CertificationAuthority -from google.shopping.merchant_products_v1.types.products_common import CertificationName -from google.shopping.merchant_products_v1.types.products_common import Condition -from google.shopping.merchant_products_v1.types.products_common import CreditType -from google.shopping.merchant_products_v1.types.products_common import DigitalSourceType -from google.shopping.merchant_products_v1.types.products_common import EnergyEfficiencyClass -from google.shopping.merchant_products_v1.types.products_common import Gender -from google.shopping.merchant_products_v1.types.products_common import Pause -from google.shopping.merchant_products_v1.types.products_common import PickupMethod -from google.shopping.merchant_products_v1.types.products_common import PickupSla -from google.shopping.merchant_products_v1.types.products_common import SizeSystem -from google.shopping.merchant_products_v1.types.products_common import SizeType -from google.shopping.merchant_products_v1.types.products_common import SubscriptionPeriod - -__all__ = ('ProductInputsServiceClient', - 'ProductInputsServiceAsyncClient', - 'ProductsServiceClient', - 'ProductsServiceAsyncClient', - 'DeleteProductInputRequest', - 'InsertProductInputRequest', - 'ProductInput', - 'UpdateProductInputRequest', - 'GetProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'Product', - 'AutomatedDiscounts', - 'CloudExportAdditionalProperties', - 'FreeShippingThreshold', - 'LoyaltyPoints', - 'LoyaltyProgram', - 'ProductAttributes', - 'ProductCertification', - 'ProductDetail', - 'ProductDimension', - 'ProductInstallment', - 'ProductStatus', - 'ProductSustainabilityIncentive', - 'ProductWeight', - 'Shipping', - 'ShippingDimension', - 'ShippingWeight', - 'StructuredDescription', - 'StructuredTitle', - 'SubscriptionCost', - 'UnitPricingBaseMeasure', - 'UnitPricingMeasure', - 'AgeGroup', - 'Availability', - 'CertificationAuthority', - 'CertificationName', - 'Condition', - 'CreditType', - 'DigitalSourceType', - 'EnergyEfficiencyClass', - 'Gender', - 'Pause', - 'PickupMethod', - 'PickupSla', - 'SizeSystem', - 'SizeType', - 'SubscriptionPeriod', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py deleted file mode 100644 index 9731eedadada..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/__init__.py +++ /dev/null @@ -1,120 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.shopping.merchant_products_v1 import gapic_version as package_version - -__version__ = package_version.__version__ - - -from .services.product_inputs_service import ProductInputsServiceClient -from .services.product_inputs_service import ProductInputsServiceAsyncClient -from .services.products_service import ProductsServiceClient -from .services.products_service import ProductsServiceAsyncClient - -from .types.productinputs import DeleteProductInputRequest -from .types.productinputs import InsertProductInputRequest -from .types.productinputs import ProductInput -from .types.productinputs import UpdateProductInputRequest -from .types.products import GetProductRequest -from .types.products import ListProductsRequest -from .types.products import ListProductsResponse -from .types.products import Product -from .types.products_common import AutomatedDiscounts -from .types.products_common import CloudExportAdditionalProperties -from .types.products_common import FreeShippingThreshold -from .types.products_common import LoyaltyPoints -from .types.products_common import LoyaltyProgram -from .types.products_common import ProductAttributes -from .types.products_common import ProductCertification -from .types.products_common import ProductDetail -from .types.products_common import ProductDimension -from .types.products_common import ProductInstallment -from .types.products_common import ProductStatus -from .types.products_common import ProductSustainabilityIncentive -from .types.products_common import ProductWeight -from .types.products_common import Shipping -from .types.products_common import ShippingDimension -from .types.products_common import ShippingWeight -from .types.products_common import StructuredDescription -from .types.products_common import StructuredTitle -from .types.products_common import SubscriptionCost -from .types.products_common import UnitPricingBaseMeasure -from .types.products_common import UnitPricingMeasure -from .types.products_common import AgeGroup -from .types.products_common import Availability -from .types.products_common import CertificationAuthority -from .types.products_common import CertificationName -from .types.products_common import Condition -from .types.products_common import CreditType -from .types.products_common import DigitalSourceType -from .types.products_common import EnergyEfficiencyClass -from .types.products_common import Gender -from .types.products_common import Pause -from .types.products_common import PickupMethod -from .types.products_common import PickupSla -from .types.products_common import SizeSystem -from .types.products_common import SizeType -from .types.products_common import SubscriptionPeriod - -__all__ = ( - 'ProductInputsServiceAsyncClient', - 'ProductsServiceAsyncClient', -'AgeGroup', -'AutomatedDiscounts', -'Availability', -'CertificationAuthority', -'CertificationName', -'CloudExportAdditionalProperties', -'Condition', -'CreditType', -'DeleteProductInputRequest', -'DigitalSourceType', -'EnergyEfficiencyClass', -'FreeShippingThreshold', -'Gender', -'GetProductRequest', -'InsertProductInputRequest', -'ListProductsRequest', -'ListProductsResponse', -'LoyaltyPoints', -'LoyaltyProgram', -'Pause', -'PickupMethod', -'PickupSla', -'Product', -'ProductAttributes', -'ProductCertification', -'ProductDetail', -'ProductDimension', -'ProductInput', -'ProductInputsServiceClient', -'ProductInstallment', -'ProductStatus', -'ProductSustainabilityIncentive', -'ProductWeight', -'ProductsServiceClient', -'Shipping', -'ShippingDimension', -'ShippingWeight', -'SizeSystem', -'SizeType', -'StructuredDescription', -'StructuredTitle', -'SubscriptionCost', -'SubscriptionPeriod', -'UnitPricingBaseMeasure', -'UnitPricingMeasure', -'UpdateProductInputRequest', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py deleted file mode 100644 index 20a9cd975b02..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed deleted file mode 100644 index 962817aecdcd..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py deleted file mode 100644 index 4513749ea12b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import ProductsServiceClient -from .async_client import ProductsServiceAsyncClient - -__all__ = ( - 'ProductsServiceClient', - 'ProductsServiceAsyncClient', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini b/owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini deleted file mode 100644 index 574c5aed394b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.7 -namespace_packages = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py b/owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py deleted file mode 100644 index 317670e1652b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/noxfile.py +++ /dev/null @@ -1,591 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import re -import shutil - -from typing import Dict, List -import warnings - -import nox - -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" - -LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] - -ALL_PYTHON = [ - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", - "3.12", - "3.13", -] - -DEFAULT_PYTHON_VERSION = ALL_PYTHON[-1] - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = "google-shopping-merchant-products" - -UNIT_TEST_STANDARD_DEPENDENCIES = [ - "mock", - "asyncmock", - "pytest", - "pytest-cov", - "pytest-asyncio", -] -UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] -UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] -UNIT_TEST_DEPENDENCIES: List[str] = [] -UNIT_TEST_EXTRAS: List[str] = [] -UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} - -SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] -SYSTEM_TEST_STANDARD_DEPENDENCIES = [ - "mock", - "pytest", - "google-cloud-testutils", -] -SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] -SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [] -SYSTEM_TEST_DEPENDENCIES: List[str] = [] -SYSTEM_TEST_EXTRAS: List[str] = [] -SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} - -nox.options.sessions = [ - "unit", - "system", - "cover", - "lint", - "lint_setup_py", - "blacken", - "docs", -] - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - - -@nox.session(python=ALL_PYTHON) -def mypy(session): - """Run the type checker.""" - session.install( - "mypy", - "types-requests", - "types-protobuf", - ) - session.install(".") - session.run( - "mypy", - "-p", - "google", - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install("google-cloud-testutils") - session.install(".") - - session.run( - "lower-bound-checker", - "update", - "--package-name", - PACKAGE_NAME, - "--constraints-file", - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install("google-cloud-testutils") - session.install(".") - - session.run( - "lower-bound-checker", - "check", - "--package-name", - PACKAGE_NAME, - "--constraints-file", - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) - - session.run("flake8", "google", "tests") - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def format(session): - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run( - "isort", - "--fss", - *LINT_PATHS, - ) - session.run( - "black", - *LINT_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install("setuptools", "docutils", "pygments") - session.run("python", "setup.py", "check", "--restructuredtext", "--strict") - - -def install_unittest_dependencies(session, *constraints): - standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES - session.install(*standard_deps, *constraints) - - if UNIT_TEST_EXTERNAL_DEPENDENCIES: - warnings.warn( - "'unit_test_external_dependencies' is deprecated. Instead, please " - "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", - DeprecationWarning, - ) - session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) - - if UNIT_TEST_LOCAL_DEPENDENCIES: - session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) - - if UNIT_TEST_EXTRAS_BY_PYTHON: - extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) - elif UNIT_TEST_EXTRAS: - extras = UNIT_TEST_EXTRAS - else: - extras = [] - - if extras: - session.install("-e", f".[{','.join(extras)}]", *constraints) - else: - session.install("-e", ".", *constraints) - - -@nox.session(python=ALL_PYTHON) -@nox.parametrize( - "protobuf_implementation", - ["python", "upb", "cpp"], -) -def unit(session, protobuf_implementation): - # Install all test dependencies, then install this package in-place. - - if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): - session.skip("cpp implementation is not supported in python 3.11+") - - constraints_path = str( - CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" - ) - install_unittest_dependencies(session, "-c", constraints_path) - - # TODO(https://github.com/googleapis/synthtool/issues/1976): - # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. - # The 'cpp' implementation requires Protobuf<4. - if protobuf_implementation == "cpp": - session.install("protobuf<4") - - # Run py.test against the unit tests. - session.run( - "py.test", - "--quiet", - f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google", - "--cov=tests/unit", - "--cov-append", - "--cov-config=.coveragerc", - "--cov-report=", - "--cov-fail-under=0", - os.path.join("tests", "unit"), - *session.posargs, - env={ - "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, - }, - ) - - -def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") - - session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: - session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_LOCAL_DEPENDENCIES: - session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_DEPENDENCIES: - session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_EXTRAS_BY_PYTHON: - extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) - elif SYSTEM_TEST_EXTRAS: - extras = SYSTEM_TEST_EXTRAS - else: - extras = [] - - if extras: - session.install("-e", f".[{','.join(extras)}]", *constraints) - else: - session.install("-e", ".", *constraints) - - -@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) -def system(session): - """Run the system test suite.""" - constraints_path = str( - CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" - ) - system_test_path = os.path.join("tests", "system.py") - system_test_folder_path = os.path.join("tests", "system") - - # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. - if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": - session.skip("RUN_SYSTEM_TESTS is set to false, skipping") - # Install pyopenssl for mTLS testing. - if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": - session.install("pyopenssl") - - system_test_exists = os.path.exists(system_test_path) - system_test_folder_exists = os.path.exists(system_test_folder_path) - # Sanity check: only run tests if found. - if not system_test_exists and not system_test_folder_exists: - session.skip("System tests were not found") - - install_systemtest_dependencies(session, "-c", constraints_path) - - # Run py.test against the system tests. - if system_test_exists: - session.run( - "py.test", - "--quiet", - f"--junitxml=system_{session.python}_sponge_log.xml", - system_test_path, - *session.posargs, - ) - if system_test_folder_exists: - session.run( - "py.test", - "--quiet", - f"--junitxml=system_{session.python}_sponge_log.xml", - system_test_folder_path, - *session.posargs, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def cover(session): - """Run the final coverage report. - - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python="3.10") -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install( - # We need to pin to specific versions of the `sphinxcontrib-*` packages - # which still support sphinx 4.x. - # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 - # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. - "sphinxcontrib-applehelp==1.0.4", - "sphinxcontrib-devhelp==1.0.2", - "sphinxcontrib-htmlhelp==2.0.1", - "sphinxcontrib-qthelp==1.0.3", - "sphinxcontrib-serializinghtml==1.1.5", - "sphinx==4.5.0", - "alabaster", - "recommonmark", - ) - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python="3.10") -def docfx(session): - """Build the docfx yaml files for this library.""" - - session.install("-e", ".") - session.install( - # We need to pin to specific versions of the `sphinxcontrib-*` packages - # which still support sphinx 4.x. - # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 - # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. - "sphinxcontrib-applehelp==1.0.4", - "sphinxcontrib-devhelp==1.0.2", - "sphinxcontrib-htmlhelp==2.0.1", - "sphinxcontrib-qthelp==1.0.3", - "sphinxcontrib-serializinghtml==1.1.5", - "gcp-sphinx-docfx-yaml", - "alabaster", - "recommonmark", - ) - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-T", # show full traceback on exception - "-N", # no colors - "-D", - ( - "extensions=sphinx.ext.autodoc," - "sphinx.ext.autosummary," - "docfx_yaml.extension," - "sphinx.ext.intersphinx," - "sphinx.ext.coverage," - "sphinx.ext.napoleon," - "sphinx.ext.todo," - "sphinx.ext.viewcode," - "recommonmark" - ), - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -@nox.parametrize( - "protobuf_implementation", - ["python", "upb", "cpp"], -) -def prerelease_deps(session, protobuf_implementation): - """ - Run all tests with pre-release versions of dependencies installed - rather than the standard non pre-release versions. - Pre-release versions can be installed using - `pip install --pre `. - """ - - if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): - session.skip("cpp implementation is not supported in python 3.11+") - - # Install all dependencies - session.install("-e", ".") - - # Install dependencies for the unit test environment - unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES - session.install(*unit_deps_all) - - # Install dependencies for the system test environment - system_deps_all = ( - SYSTEM_TEST_STANDARD_DEPENDENCIES - + SYSTEM_TEST_EXTERNAL_DEPENDENCIES - + SYSTEM_TEST_EXTRAS - ) - session.install(*system_deps_all) - - # Because we test minimum dependency versions on the minimum Python - # version, the first version we test with in the unit tests sessions has a - # constraints file containing all dependencies and extras. - with open( - CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", - encoding="utf-8", - ) as constraints_file: - constraints_text = constraints_file.read() - - # Ignore leading whitespace and comment lines. - constraints_deps = [ - match.group(1) - for match in re.finditer( - r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE - ) - ] - - # Install dependencies specified in `testing/constraints-X.txt`. - session.install(*constraints_deps) - - # Note: If a dependency is added to the `prerel_deps` list, - # the `core_dependencies_from_source` list in the `core_deps_from_source` - # nox session should also be updated. - prerel_deps = [ - "googleapis-common-protos", - "google-api-core", - "google-auth", - "grpc-google-iam-v1", - "grpcio", - "grpcio-status", - "protobuf", - "proto-plus", - ] - - for dep in prerel_deps: - session.install("--pre", "--no-deps", "--ignore-installed", dep) - # TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status`` - # to the dictionary below once this bug is fixed. - # TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add - # `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below - # once this bug is fixed. - package_namespaces = { - "google-api-core": "google.api_core", - "google-auth": "google.auth", - "grpcio": "grpc", - "protobuf": "google.protobuf", - "proto-plus": "proto", - } - - version_namespace = package_namespaces.get(dep) - - print(f"Installed {dep}") - if version_namespace: - session.run( - "python", - "-c", - f"import {version_namespace}; print({version_namespace}.__version__)", - ) - - session.run( - "py.test", - "tests/unit", - env={ - "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, - }, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -@nox.parametrize( - "protobuf_implementation", - ["python", "upb"], -) -def core_deps_from_source(session, protobuf_implementation): - """Run all tests with core dependencies installed from source - rather than pulling the dependencies from PyPI. - """ - - # Install all dependencies - session.install("-e", ".") - - # Install dependencies for the unit test environment - unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES - session.install(*unit_deps_all) - - # Install dependencies for the system test environment - system_deps_all = ( - SYSTEM_TEST_STANDARD_DEPENDENCIES - + SYSTEM_TEST_EXTERNAL_DEPENDENCIES - + SYSTEM_TEST_EXTRAS - ) - session.install(*system_deps_all) - - # Because we test minimum dependency versions on the minimum Python - # version, the first version we test with in the unit tests sessions has a - # constraints file containing all dependencies and extras. - with open( - CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", - encoding="utf-8", - ) as constraints_file: - constraints_text = constraints_file.read() - - # Ignore leading whitespace and comment lines. - constraints_deps = [ - match.group(1) - for match in re.finditer( - r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE - ) - ] - - # Install dependencies specified in `testing/constraints-X.txt`. - session.install(*constraints_deps) - - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and - # `grpcio-status` should be added to the list below so that they are installed from source, - # rather than PyPI. - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be - # added to the list below so that it is installed from source, rather than PyPI - # Note: If a dependency is added to the `core_dependencies_from_source` list, - # the `prerel_deps` list in the `prerelease_deps` nox session should also be updated. - core_dependencies_from_source = [ - "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", - "google-api-core @ git+https://github.com/googleapis/python-api-core.git", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", - "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", - "proto-plus @ git+https://github.com/googleapis/proto-plus-python.git", - ] - - for dep in core_dependencies_from_source: - session.install(dep, "--no-deps", "--ignore-installed") - print(f"Installed {dep}") - - session.run( - "py.test", - "tests/unit", - env={ - "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, - }, - ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/setup.py b/owl-bot-staging/google-shopping-merchant-products/v1/setup.py deleted file mode 100644 index d1544a0a16b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/setup.py +++ /dev/null @@ -1,99 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os -import re - -import setuptools # type: ignore - -package_root = os.path.abspath(os.path.dirname(__file__)) - -name = 'google-shopping-merchant-products' - - -description = "Google Shopping Merchant Products API client library" - -version = None - -with open(os.path.join(package_root, 'google/shopping/merchant_products/gapic_version.py')) as fp: - version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read()) - assert (len(version_candidates) == 1) - version = version_candidates[0] - -if version[0] == "0": - release_status = "Development Status :: 4 - Beta" -else: - release_status = "Development Status :: 5 - Production/Stable" - -dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", - # Exclude incompatible versions of `google-auth` - # See https://github.com/googleapis/google-cloud-python/issues/12364 - "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "proto-plus >= 1.22.3, <2.0.0", - "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", - "google-shopping-type >= 0.1.6, <1.0.0", -] -extras = { -} -url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-shopping-merchant-products" - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, "README.rst") -with io.open(readme_filename, encoding="utf-8") as readme_file: - readme = readme_file.read() - -packages = [ - package - for package in setuptools.find_namespace_packages() - if package.startswith("google") -] - -setuptools.setup( - name=name, - version=version, - description=description, - long_description=readme, - author="Google LLC", - author_email="googleapis-packages@google.com", - license="Apache 2.0", - url=url, - classifiers=[ - release_status, - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "Operating System :: OS Independent", - "Topic :: Internet", - ], - platforms="Posix; MacOS X; Windows", - packages=packages, - python_requires=">=3.7", - install_requires=dependencies, - extras_require=extras, - include_package_data=True, - zip_safe=False, -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.10.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.11.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.12.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt deleted file mode 100644 index 0112695e5bbb..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.13.txt +++ /dev/null @@ -1,12 +0,0 @@ -# We use the constraints file for the latest Python version -# (currently this file) to check that the latest -# major versions of dependencies are supported in setup.py. -# List all library dependencies and extras in this file. -# Require the latest major version be installed for each dependency. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo>=1 -google-api-core>=2 -google-auth>=2 -proto-plus>=1 -protobuf>=6 -google-shopping-type>=0 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt deleted file mode 100644 index 2af887ec8ba0..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.7.txt +++ /dev/null @@ -1,11 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -proto-plus==1.22.3 -protobuf==3.20.2 -google-shopping-type==0.1.6 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.8.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt b/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/testing/constraints-3.9.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc b/owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc deleted file mode 100644 index 0d94c2da5109..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/.coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/shopping/merchant_products/__init__.py - google/shopping/merchant_products/gapic_version.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 b/owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 deleted file mode 100644 index 90316de21489..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/.flake8 +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -[flake8] -# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): -# Resolve flake8 lint issues -ignore = E203, E231, E266, E501, W503 -exclude = - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2333): - # Ensure that generated code passes flake8 lint - **/gapic/** - **/services/** - **/types/** - # Exclude Protobuf gencode - *_pb2.py - - # Standard linting exemptions. - **/.nox/** - __pycache__, - .git, - *.pyc, - conf.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE b/owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE deleted file mode 100644 index d64569567334..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in b/owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in deleted file mode 100644 index dae249ec8976..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/MANIFEST.in +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -include README.rst LICENSE -recursive-include google *.py *.pyi *.json *.proto py.typed -recursive-include tests * -global-exclude *.py[co] -global-exclude __pycache__ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst deleted file mode 100644 index f80c16dfa082..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/README.rst +++ /dev/null @@ -1,143 +0,0 @@ -Python Client for Google Shopping Merchant Products API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Shopping Merchant Products API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library - - -Logging -------- - -This library uses the standard Python :code:`logging` functionality to log some RPC events that could be of interest for debugging and monitoring purposes. -Note the following: - -#. Logs may contain sensitive information. Take care to **restrict access to the logs** if they are saved, whether it be on local storage or on Google Cloud Logging. -#. Google may refine the occurrence, level, and content of various log messages in this library without flagging such changes as breaking. **Do not depend on immutability of the logging events**. -#. By default, the logging events from this library are not handled. You must **explicitly configure log handling** using one of the mechanisms below. - - -Simple, environment-based configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -To enable logging for this library without any changes in your code, set the :code:`GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to a valid Google -logging scope. This configures handling of logging events (at level :code:`logging.DEBUG` or higher) from this library in a default manner, emitting the logged -messages in a structured format. It does not currently allow customizing the logging levels captured nor the handlers, formatters, etc. used for any logging -event. - -A logging scope is a period-separated namespace that begins with :code:`google`, identifying the Python module or package to log. - -- Valid logging scopes: :code:`google`, :code:`google.cloud.asset.v1`, :code:`google.api`, :code:`google.auth`, etc. -- Invalid logging scopes: :code:`foo`, :code:`123`, etc. - -**NOTE**: If the logging scope is invalid, the library does not set up any logging handlers. - - -Examples -^^^^^^^^ - -- Enabling the default handler for all Google-based loggers - -.. code-block:: console - - export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google - -- Enabling the default handler for a specific Google module (for a client library called :code:`library_v1`): - -.. code-block:: console - - export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.cloud.library_v1 - - -Advanced, code-based configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also configure a valid logging scope using Python's standard `logging` mechanism. - - -Examples -^^^^^^^^ - -- Configuring a handler for all Google-based loggers - -.. code-block:: python - - import logging - - from google.cloud.translate_v3 import translate - - base_logger = logging.getLogger("google") - base_logger.addHandler(logging.StreamHandler()) - base_logger.setLevel(logging.DEBUG) - -- Configuring a handler for a specific Google module (for a client library called :code:`library_v1`): - -.. code-block:: python - - import logging - - from google.cloud.translate_v3 import translate - - base_logger = logging.getLogger("google.cloud.library_v1") - base_logger.addHandler(logging.StreamHandler()) - base_logger.setLevel(logging.DEBUG) - - -Logging details -~~~~~~~~~~~~~~~ - -#. Regardless of which of the mechanisms above you use to configure logging for this library, by default logging events are not propagated up to the root - logger from the `google`-level logger. If you need the events to be propagated to the root logger, you must explicitly set - :code:`logging.getLogger("google").propagate = True` in your code. -#. You can mix the different logging configurations above for different Google modules. For example, you may want use a code-based logging configuration for - one library, but decide you need to also set up environment-based logging configuration for another library. - - #. If you attempt to use both code-based and environment-based configuration for the same module, the environment-based configuration will be ineffectual - if the code -based configuration gets applied first. - -#. The Google-specific logging configurations (default handlers for environment-based configuration; not propagating logging events to the root logger) get - executed the first time *any* client library is instantiated in your application, and only if the affected loggers have not been previously configured. - (This is the reason for 2.i. above.) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css deleted file mode 100644 index b0a295464b23..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_static/custom.css +++ /dev/null @@ -1,20 +0,0 @@ -div#python2-eol { - border-color: red; - border-width: medium; -} - -/* Ensure minimum width for 'Parameters' / 'Returns' column */ -dl.field-list > dt { - min-width: 100px -} - -/* Insert space between methods for readability */ -dl.method { - padding-top: 10px; - padding-bottom: 10px -} - -/* Insert empty space between classes */ -dl.class { - padding-bottom: 50px -} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html deleted file mode 100644 index 95e9c77fcfe1..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/_templates/layout.html +++ /dev/null @@ -1,50 +0,0 @@ - -{% extends "!layout.html" %} -{%- block content %} -{%- if theme_fixed_sidebar|lower == 'true' %} -
- {{ sidebar() }} - {%- block document %} -
- {%- if render_sidebar %} -
- {%- endif %} - - {%- block relbar_top %} - {%- if theme_show_relbar_top|tobool %} - - {%- endif %} - {% endblock %} - -
-
- As of January 1, 2020 this library no longer supports Python 2 on the latest released version. - Library versions released prior to that date will continue to be available. For more information please - visit Python 2 support on Google Cloud. -
- {% block body %} {% endblock %} -
- - {%- block relbar_bottom %} - {%- if theme_show_relbar_bottom|tobool %} - - {%- endif %} - {% endblock %} - - {%- if render_sidebar %} -
- {%- endif %} -
- {%- endblock %} -
-
-{%- else %} -{{ super() }} -{%- endif %} -{%- endblock %} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py deleted file mode 100644 index 302daf996542..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/conf.py +++ /dev/null @@ -1,385 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-shopping-merchant-products documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -# For plugins that can not read conf.py. -# See also: https://github.com/docascode/sphinx-docfx-yaml/issues/85 -sys.path.insert(0, os.path.abspath(".")) - -__version__ = "" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "4.5.0" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.doctest", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", - "recommonmark", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_options = {"members": True} -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# source_suffix = ['.rst', '.md'] -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The root toctree document. -root_doc = "index" - -# General information about the project. -project = u"google-shopping-merchant-products" -copyright = u"2025, Google, LLC" -author = u"Google APIs" - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = [ - "_build", - "**/.nox/**/*", - "samples/AUTHORING_GUIDE.md", - "samples/CONTRIBUTING.md", - "samples/snippets/README.rst", -] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Shopping Client Libraries for google-shopping-merchant-products", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-shopping-merchant-products-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - root_doc, - "google-shopping-merchant-products.tex", - u"google-shopping-merchant-products Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - root_doc, - "google-shopping-merchant-products", - "google-shopping-merchant-products Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - root_doc, - "google-shopping-merchant-products", - "google-shopping-merchant-products Documentation", - author, - "google-shopping-merchant-products", - "google-shopping-merchant-products Library", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("https://python.readthedocs.org/en/latest/", None), - "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ( - "https://googleapis.dev/python/google-api-core/latest/", - None, - ), - "grpc": ("https://grpc.github.io/grpc/python/", None), - "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst deleted file mode 100644 index eee21402d328..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -.. include:: multiprocessing.rst - - -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - merchant_products_v1beta/services_ - merchant_products_v1beta/types_ diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst deleted file mode 100644 index 99e2c59bfb43..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/product_inputs_service.rst +++ /dev/null @@ -1,6 +0,0 @@ -ProductInputsService --------------------------------------- - -.. automodule:: google.shopping.merchant_products_v1beta.services.product_inputs_service - :members: - :inherited-members: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst deleted file mode 100644 index f20ce0b9e362..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/products_service.rst +++ /dev/null @@ -1,10 +0,0 @@ -ProductsService ---------------------------------- - -.. automodule:: google.shopping.merchant_products_v1beta.services.products_service - :members: - :inherited-members: - -.. automodule:: google.shopping.merchant_products_v1beta.services.products_service.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst deleted file mode 100644 index ce641539544e..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/services_.rst +++ /dev/null @@ -1,7 +0,0 @@ -Services for Google Shopping Merchant Products v1beta API -========================================================= -.. toctree:: - :maxdepth: 2 - - product_inputs_service - products_service diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst deleted file mode 100644 index af3a6c59c20f..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/merchant_products_v1beta/types_.rst +++ /dev/null @@ -1,6 +0,0 @@ -Types for Google Shopping Merchant Products v1beta API -====================================================== - -.. automodule:: google.shopping.merchant_products_v1beta.types - :members: - :show-inheritance: diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst deleted file mode 100644 index 536d17b2ea65..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/docs/multiprocessing.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. note:: - - Because this client uses :mod:`grpc` library, it is safe to - share instances across threads. In multiprocessing scenarios, the best - practice is to create client instances *after* the invocation of - :func:`os.fork` by :class:`multiprocessing.pool.Pool` or - :class:`multiprocessing.Process`. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py deleted file mode 100644 index 92054cbf7e04..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/__init__.py +++ /dev/null @@ -1,93 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.shopping.merchant_products import gapic_version as package_version - -__version__ = package_version.__version__ - - -from google.shopping.merchant_products_v1beta.services.product_inputs_service.client import ProductInputsServiceClient -from google.shopping.merchant_products_v1beta.services.product_inputs_service.async_client import ProductInputsServiceAsyncClient -from google.shopping.merchant_products_v1beta.services.products_service.client import ProductsServiceClient -from google.shopping.merchant_products_v1beta.services.products_service.async_client import ProductsServiceAsyncClient - -from google.shopping.merchant_products_v1beta.types.productinputs import DeleteProductInputRequest -from google.shopping.merchant_products_v1beta.types.productinputs import InsertProductInputRequest -from google.shopping.merchant_products_v1beta.types.productinputs import ProductInput -from google.shopping.merchant_products_v1beta.types.productinputs import UpdateProductInputRequest -from google.shopping.merchant_products_v1beta.types.products import GetProductRequest -from google.shopping.merchant_products_v1beta.types.products import ListProductsRequest -from google.shopping.merchant_products_v1beta.types.products import ListProductsResponse -from google.shopping.merchant_products_v1beta.types.products import Product -from google.shopping.merchant_products_v1beta.types.products_common import Attributes -from google.shopping.merchant_products_v1beta.types.products_common import AutomatedDiscounts -from google.shopping.merchant_products_v1beta.types.products_common import Certification -from google.shopping.merchant_products_v1beta.types.products_common import CloudExportAdditionalProperties -from google.shopping.merchant_products_v1beta.types.products_common import FreeShippingThreshold -from google.shopping.merchant_products_v1beta.types.products_common import Installment -from google.shopping.merchant_products_v1beta.types.products_common import LoyaltyPoints -from google.shopping.merchant_products_v1beta.types.products_common import LoyaltyProgram -from google.shopping.merchant_products_v1beta.types.products_common import ProductDetail -from google.shopping.merchant_products_v1beta.types.products_common import ProductDimension -from google.shopping.merchant_products_v1beta.types.products_common import ProductStatus -from google.shopping.merchant_products_v1beta.types.products_common import ProductStructuredDescription -from google.shopping.merchant_products_v1beta.types.products_common import ProductStructuredTitle -from google.shopping.merchant_products_v1beta.types.products_common import ProductSustainabilityIncentive -from google.shopping.merchant_products_v1beta.types.products_common import ProductWeight -from google.shopping.merchant_products_v1beta.types.products_common import Shipping -from google.shopping.merchant_products_v1beta.types.products_common import ShippingDimension -from google.shopping.merchant_products_v1beta.types.products_common import ShippingWeight -from google.shopping.merchant_products_v1beta.types.products_common import SubscriptionCost -from google.shopping.merchant_products_v1beta.types.products_common import Tax -from google.shopping.merchant_products_v1beta.types.products_common import UnitPricingBaseMeasure -from google.shopping.merchant_products_v1beta.types.products_common import UnitPricingMeasure -from google.shopping.merchant_products_v1beta.types.products_common import SubscriptionPeriod - -__all__ = ('ProductInputsServiceClient', - 'ProductInputsServiceAsyncClient', - 'ProductsServiceClient', - 'ProductsServiceAsyncClient', - 'DeleteProductInputRequest', - 'InsertProductInputRequest', - 'ProductInput', - 'UpdateProductInputRequest', - 'GetProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'Product', - 'Attributes', - 'AutomatedDiscounts', - 'Certification', - 'CloudExportAdditionalProperties', - 'FreeShippingThreshold', - 'Installment', - 'LoyaltyPoints', - 'LoyaltyProgram', - 'ProductDetail', - 'ProductDimension', - 'ProductStatus', - 'ProductStructuredDescription', - 'ProductStructuredTitle', - 'ProductSustainabilityIncentive', - 'ProductWeight', - 'Shipping', - 'ShippingDimension', - 'ShippingWeight', - 'SubscriptionCost', - 'Tax', - 'UnitPricingBaseMeasure', - 'UnitPricingMeasure', - 'SubscriptionPeriod', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py deleted file mode 100644 index 20a9cd975b02..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed deleted file mode 100644 index 962817aecdcd..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py deleted file mode 100644 index ab41e40727d8..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/__init__.py +++ /dev/null @@ -1,94 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -__version__ = package_version.__version__ - - -from .services.product_inputs_service import ProductInputsServiceClient -from .services.product_inputs_service import ProductInputsServiceAsyncClient -from .services.products_service import ProductsServiceClient -from .services.products_service import ProductsServiceAsyncClient - -from .types.productinputs import DeleteProductInputRequest -from .types.productinputs import InsertProductInputRequest -from .types.productinputs import ProductInput -from .types.productinputs import UpdateProductInputRequest -from .types.products import GetProductRequest -from .types.products import ListProductsRequest -from .types.products import ListProductsResponse -from .types.products import Product -from .types.products_common import Attributes -from .types.products_common import AutomatedDiscounts -from .types.products_common import Certification -from .types.products_common import CloudExportAdditionalProperties -from .types.products_common import FreeShippingThreshold -from .types.products_common import Installment -from .types.products_common import LoyaltyPoints -from .types.products_common import LoyaltyProgram -from .types.products_common import ProductDetail -from .types.products_common import ProductDimension -from .types.products_common import ProductStatus -from .types.products_common import ProductStructuredDescription -from .types.products_common import ProductStructuredTitle -from .types.products_common import ProductSustainabilityIncentive -from .types.products_common import ProductWeight -from .types.products_common import Shipping -from .types.products_common import ShippingDimension -from .types.products_common import ShippingWeight -from .types.products_common import SubscriptionCost -from .types.products_common import Tax -from .types.products_common import UnitPricingBaseMeasure -from .types.products_common import UnitPricingMeasure -from .types.products_common import SubscriptionPeriod - -__all__ = ( - 'ProductInputsServiceAsyncClient', - 'ProductsServiceAsyncClient', -'Attributes', -'AutomatedDiscounts', -'Certification', -'CloudExportAdditionalProperties', -'DeleteProductInputRequest', -'FreeShippingThreshold', -'GetProductRequest', -'InsertProductInputRequest', -'Installment', -'ListProductsRequest', -'ListProductsResponse', -'LoyaltyPoints', -'LoyaltyProgram', -'Product', -'ProductDetail', -'ProductDimension', -'ProductInput', -'ProductInputsServiceClient', -'ProductStatus', -'ProductStructuredDescription', -'ProductStructuredTitle', -'ProductSustainabilityIncentive', -'ProductWeight', -'ProductsServiceClient', -'Shipping', -'ShippingDimension', -'ShippingWeight', -'SubscriptionCost', -'SubscriptionPeriod', -'Tax', -'UnitPricingBaseMeasure', -'UnitPricingMeasure', -'UpdateProductInputRequest', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json deleted file mode 100644 index bcae8fc1c898..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_metadata.json +++ /dev/null @@ -1,122 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.shopping.merchant_products_v1beta", - "protoPackage": "google.shopping.merchant.products.v1beta", - "schema": "1.0", - "services": { - "ProductInputsService": { - "clients": { - "grpc": { - "libraryClient": "ProductInputsServiceClient", - "rpcs": { - "DeleteProductInput": { - "methods": [ - "delete_product_input" - ] - }, - "InsertProductInput": { - "methods": [ - "insert_product_input" - ] - }, - "UpdateProductInput": { - "methods": [ - "update_product_input" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ProductInputsServiceAsyncClient", - "rpcs": { - "DeleteProductInput": { - "methods": [ - "delete_product_input" - ] - }, - "InsertProductInput": { - "methods": [ - "insert_product_input" - ] - }, - "UpdateProductInput": { - "methods": [ - "update_product_input" - ] - } - } - }, - "rest": { - "libraryClient": "ProductInputsServiceClient", - "rpcs": { - "DeleteProductInput": { - "methods": [ - "delete_product_input" - ] - }, - "InsertProductInput": { - "methods": [ - "insert_product_input" - ] - }, - "UpdateProductInput": { - "methods": [ - "update_product_input" - ] - } - } - } - } - }, - "ProductsService": { - "clients": { - "grpc": { - "libraryClient": "ProductsServiceClient", - "rpcs": { - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - } - } - }, - "grpc-async": { - "libraryClient": "ProductsServiceAsyncClient", - "rpcs": { - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - } - } - }, - "rest": { - "libraryClient": "ProductsServiceClient", - "rpcs": { - "GetProduct": { - "methods": [ - "get_product" - ] - }, - "ListProducts": { - "methods": [ - "list_products" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py deleted file mode 100644 index 20a9cd975b02..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed deleted file mode 100644 index 962817aecdcd..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-shopping-merchant-products package uses inline types. diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py deleted file mode 100644 index 570e3b7a9ffd..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import ProductInputsServiceClient -from .async_client import ProductInputsServiceAsyncClient - -__all__ = ( - 'ProductInputsServiceClient', - 'ProductInputsServiceAsyncClient', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py deleted file mode 100644 index ee37c23d3725..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/async_client.py +++ /dev/null @@ -1,689 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging as std_logging -from collections import OrderedDict -import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union - -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -from google.api_core.client_options import ClientOptions -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - - -try: - OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore - -from google.protobuf import field_mask_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types -from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport -from .client import ProductInputsServiceClient - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - -class ProductInputsServiceAsyncClient: - """Service to use ProductInput resource. - This service works for products with online channel only. - """ - - _client: ProductInputsServiceClient - - # Copy defaults from the synchronous client for use here. - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = ProductInputsServiceClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - _DEFAULT_ENDPOINT_TEMPLATE = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE - _DEFAULT_UNIVERSE = ProductInputsServiceClient._DEFAULT_UNIVERSE - - product_path = staticmethod(ProductInputsServiceClient.product_path) - parse_product_path = staticmethod(ProductInputsServiceClient.parse_product_path) - product_input_path = staticmethod(ProductInputsServiceClient.product_input_path) - parse_product_input_path = staticmethod(ProductInputsServiceClient.parse_product_input_path) - common_billing_account_path = staticmethod(ProductInputsServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductInputsServiceClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ProductInputsServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductInputsServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductInputsServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductInputsServiceClient.parse_common_organization_path) - common_project_path = staticmethod(ProductInputsServiceClient.common_project_path) - parse_common_project_path = staticmethod(ProductInputsServiceClient.parse_common_project_path) - common_location_path = staticmethod(ProductInputsServiceClient.common_location_path) - parse_common_location_path = staticmethod(ProductInputsServiceClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductInputsServiceAsyncClient: The constructed client. - """ - return ProductInputsServiceClient.from_service_account_info.__func__(ProductInputsServiceAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductInputsServiceAsyncClient: The constructed client. - """ - return ProductInputsServiceClient.from_service_account_file.__func__(ProductInputsServiceAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - return ProductInputsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore - - @property - def transport(self) -> ProductInputsServiceTransport: - """Returns the transport used by the client instance. - - Returns: - ProductInputsServiceTransport: The transport used by the client instance. - """ - return self._client.transport - - @property - def api_endpoint(self): - """Return the API endpoint used by the client instance. - - Returns: - str: The API endpoint used by the client instance. - """ - return self._client._api_endpoint - - @property - def universe_domain(self) -> str: - """Return the universe domain used by the client instance. - - Returns: - str: The universe domain used - by the client instance. - """ - return self._client._universe_domain - - get_transport_class = ProductInputsServiceClient.get_transport_class - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product inputs service async client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Optional[Union[str,ProductInputsServiceTransport,Callable[..., ProductInputsServiceTransport]]]): - The transport to use, or a Callable that constructs and returns a new transport to use. - If a Callable is given, it will be called with the same set of initialization - arguments as used in the ProductInputsServiceTransport constructor. - If set to None, a transport is chosen automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): - Custom options for the client. - - 1. The ``api_endpoint`` property can be used to override the - default endpoint provided by the client when ``transport`` is - not explicitly provided. Only if this property is not set and - ``transport`` was not explicitly provided, the endpoint is - determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment - variable, which have one of the following values: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto-switch to the - default mTLS endpoint if client certificate is present; this is - the default value). - - 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide a client certificate for mTLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - 3. The ``universe_domain`` property can be used to override the - default "googleapis.com" universe. Note that ``api_endpoint`` - property still takes precedence; and ``universe_domain`` is - currently not supported for mTLS. - - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = ProductInputsServiceClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER - _LOGGER.debug( - "Created client `google.shopping.merchant.products_v1beta.ProductInputsServiceAsyncClient`.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), - "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._client._transport, "_credentials") else { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "credentialsType": None, - } - ) - - async def insert_product_input(self, - request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: - r"""`Uploads a product input to your Merchant Center - account `__. - You must have a products data source to be able to insert a - product. The unique identifier of the data source is passed as a - query parameter in the request URL. - - If an input with the same contentLanguage, offerId, and - dataSource already exists, this method replaces that entry. - - After inserting, updating, or deleting a product input, it may - take several minutes before the processed product can be - retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - async def sample_insert_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceAsyncClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.InsertProductInputRequest( - parent="parent_value", - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = await client.insert_product_input(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.shopping.merchant_products_v1beta.types.InsertProductInputRequest, dict]]): - The request object. Request message for the - InsertProductInput method. - retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.types.ProductInput: - This resource represents input data you submit for a product, not the - processed product that you see in Merchant Center, in - Shopping ads, or across Google surfaces. Product - inputs, rules and supplemental data source data are - combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. - For more information, see [Manage - products](/merchant/api/guides/products/overview). - - Required product input attributes to pass data - validation checks are primarily defined in the - [Products Data - Specification](\ https://support.google.com/merchants/answer/188494). - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product - input, it may take several minutes before the - processed product can be retrieved. - - All fields in the product input and its sub-messages - match the English name of their corresponding - attribute in the [Products Data - Specification](\ https://support.google.com/merchants/answer/188494) - with [some - exceptions](\ https://support.google.com/merchants/answer/7052112). - The following reference documentation lists the field - names in the **camelCase** casing style while the - Products Data Specification lists the names in the - **snake_case** casing style. - - """ - # Create or coerce a protobuf request object. - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, productinputs.InsertProductInputRequest): - request = productinputs.InsertProductInputRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.insert_product_input] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Validate the universe domain. - self._client._validate_universe_domain() - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def update_product_input(self, - request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, - *, - product_input: Optional[productinputs.ProductInput] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: - r"""Updates the existing product input in your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - async def sample_update_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceAsyncClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.UpdateProductInputRequest( - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = await client.update_product_input(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest, dict]]): - The request object. Request message for the - UpdateProductInput method. The product - (primary input) must exist for the - update to succeed. If the update is for - a primary product input, the existing - primary product input must be from the - same data source. - product_input (:class:`google.shopping.merchant_products_v1beta.types.ProductInput`): - Required. The product input resource - to update. Information you submit will - be applied to the processed product as - well. - - This corresponds to the ``product_input`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Optional. The list of product attributes to be updated. - - If the update mask is omitted, then it is treated as - implied field mask equivalent to all fields that are - populated (have a non-empty value). - - Attributes specified in the update mask without a value - specified in the body will be deleted from the product. - - Update mask can only be specified for top level fields - in attributes and custom attributes. - - To specify the update mask for custom attributes you - need to add the ``custom_attribute.`` prefix. - - Providing special "*" value for full product replacement - is not supported. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.types.ProductInput: - This resource represents input data you submit for a product, not the - processed product that you see in Merchant Center, in - Shopping ads, or across Google surfaces. Product - inputs, rules and supplemental data source data are - combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. - For more information, see [Manage - products](/merchant/api/guides/products/overview). - - Required product input attributes to pass data - validation checks are primarily defined in the - [Products Data - Specification](\ https://support.google.com/merchants/answer/188494). - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product - input, it may take several minutes before the - processed product can be retrieved. - - All fields in the product input and its sub-messages - match the English name of their corresponding - attribute in the [Products Data - Specification](\ https://support.google.com/merchants/answer/188494) - with [some - exceptions](\ https://support.google.com/merchants/answer/7052112). - The following reference documentation lists the field - names in the **camelCase** casing style while the - Products Data Specification lists the names in the - **snake_case** casing style. - - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [product_input, update_mask] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, productinputs.UpdateProductInputRequest): - request = productinputs.UpdateProductInputRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_input is not None: - request.product_input = product_input - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.update_product_input] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_input.name", request.product_input.name), - )), - ) - - # Validate the universe domain. - self._client._validate_universe_domain() - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_product_input(self, - request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> None: - r"""Deletes a product input from your Merchant Center - account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - async def sample_delete_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceAsyncClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.DeleteProductInputRequest( - name="name_value", - data_source="data_source_value", - ) - - # Make the request - await client.delete_product_input(request=request) - - Args: - request (Optional[Union[google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest, dict]]): - The request object. Request message for the - DeleteProductInput method. - name (:class:`str`): - Required. The name of the product input resource to - delete. Format: - ``accounts/{account}/productInputs/{product}`` where the - last section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example - for product name is - ``accounts/123/productInputs/online~en~US~sku123``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, productinputs.DeleteProductInputRequest): - request = productinputs.DeleteProductInputRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.delete_product_input] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Validate the universe domain. - self._client._validate_universe_domain() - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def __aenter__(self) -> "ProductInputsServiceAsyncClient": - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - - -__all__ = ( - "ProductInputsServiceAsyncClient", -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py deleted file mode 100644 index 6b98c8ed0463..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/client.py +++ /dev/null @@ -1,1057 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from http import HTTPStatus -import json -import logging as std_logging -import os -import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast -import warnings - -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -from google.api_core import client_options as client_options_lib -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object, None] # type: ignore - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - -from google.protobuf import field_mask_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types -from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ProductInputsServiceGrpcTransport -from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport -from .transports.rest import ProductInputsServiceRestTransport - - -class ProductInputsServiceClientMeta(type): - """Metaclass for the ProductInputsService client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] - _transport_registry["grpc"] = ProductInputsServiceGrpcTransport - _transport_registry["grpc_asyncio"] = ProductInputsServiceGrpcAsyncIOTransport - _transport_registry["rest"] = ProductInputsServiceRestTransport - - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[ProductInputsServiceTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class ProductInputsServiceClient(metaclass=ProductInputsServiceClientMeta): - """Service to use ProductInput resource. - This service works for products with online channel only. - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "merchantapi.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductInputsServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductInputsServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ProductInputsServiceTransport: - """Returns the transport used by the client instance. - - Returns: - ProductInputsServiceTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(account: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "accounts/{account}/products/{product}".format(account=account, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def product_input_path(account: str,productinput: str,) -> str: - """Returns a fully-qualified product_input string.""" - return "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) - - @staticmethod - def parse_product_input_path(path: str) -> Dict[str,str]: - """Parses a product_input path into its component segments.""" - m = re.match(r"^accounts/(?P.+?)/productInputs/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): - """Deprecated. Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - - warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", - DeprecationWarning) - if client_options is None: - client_options = client_options_lib.ClientOptions() - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - - # Figure out the client cert source to use. - client_cert_source = None - if use_client_cert == "true": - if client_options.client_cert_source: - client_cert_source = client_options.client_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - api_endpoint = cls.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = cls.DEFAULT_ENDPOINT - - return api_endpoint, client_cert_source - - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - return use_client_cert == "true", use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): - """Return the API endpoint used by the client. - - Args: - api_override (str): The API endpoint override. If specified, this is always - the return value of this function and the other arguments are not used. - client_cert_source (bytes): The client certificate source used by the client. - universe_domain (str): The universe domain used by the client. - use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. - Possible values are "always", "auto", or "never". - - Returns: - str: The API endpoint to be used by the client. - """ - if api_override is not None: - api_endpoint = api_override - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - _default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE - if universe_domain != _default_universe: - raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") - api_endpoint = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) - return api_endpoint - - @staticmethod - def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ProductInputsServiceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain - - def _validate_universe_domain(self): - """Validates client's and credentials' universe domains are consistent. - - Returns: - bool: True iff the configured universe domain is valid. - - Raises: - ValueError: If the configured universe domain is not valid. - """ - - # NOTE (b/349488459): universe validation is disabled until further notice. - return True - - def _add_cred_info_for_auth_errors( - self, - error: core_exceptions.GoogleAPICallError - ) -> None: - """Adds credential info string to error details for 401/403/404 errors. - - Args: - error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. - """ - if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: - return - - cred = self._transport._credentials - - # get_cred_info is only available in google-auth>=2.35.0 - if not hasattr(cred, "get_cred_info"): - return - - # ignore the type check since pypy test fails when get_cred_info - # is not available - cred_info = cred.get_cred_info() # type: ignore - if cred_info and hasattr(error._details, "append"): - error._details.append(json.dumps(cred_info)) - - @property - def api_endpoint(self): - """Return the API endpoint used by the client instance. - - Returns: - str: The API endpoint used by the client instance. - """ - return self._api_endpoint - - @property - def universe_domain(self) -> str: - """Return the universe domain used by the client instance. - - Returns: - str: The universe domain used by the client instance. - """ - return self._universe_domain - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the product inputs service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Optional[Union[str,ProductInputsServiceTransport,Callable[..., ProductInputsServiceTransport]]]): - The transport to use, or a Callable that constructs and returns a new transport. - If a Callable is given, it will be called with the same set of initialization - arguments as used in the ProductInputsServiceTransport constructor. - If set to None, a transport is chosen automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): - Custom options for the client. - - 1. The ``api_endpoint`` property can be used to override the - default endpoint provided by the client when ``transport`` is - not explicitly provided. Only if this property is not set and - ``transport`` was not explicitly provided, the endpoint is - determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment - variable, which have one of the following values: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto-switch to the - default mTLS endpoint if client certificate is present; this is - the default value). - - 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide a client certificate for mTLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - 3. The ``universe_domain`` property can be used to override the - default "googleapis.com" universe. Note that the ``api_endpoint`` - property still takes precedence; and ``universe_domain`` is - currently not supported for mTLS. - - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client_options = client_options - if isinstance(self._client_options, dict): - self._client_options = client_options_lib.from_dict(self._client_options) - if self._client_options is None: - self._client_options = client_options_lib.ClientOptions() - self._client_options = cast(client_options_lib.ClientOptions, self._client_options) - - universe_domain_opt = getattr(self._client_options, 'universe_domain', None) - - self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductInputsServiceClient._read_environment_variables() - self._client_cert_source = ProductInputsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) - self._universe_domain = ProductInputsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` - - # Initialize the universe domain validation. - self._is_universe_domain_valid = False - - if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER - # Setup logging. - client_logging.initialize_logging() - - api_key_value = getattr(self._client_options, "api_key", None) - if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - transport_provided = isinstance(transport, ProductInputsServiceTransport) - if transport_provided: - # transport is a ProductInputsServiceTransport instance. - if credentials or self._client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if self._client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = cast(ProductInputsServiceTransport, transport) - self._api_endpoint = self._transport.host - - self._api_endpoint = (self._api_endpoint or - ProductInputsServiceClient._get_api_endpoint( - self._client_options.api_endpoint, - self._client_cert_source, - self._universe_domain, - self._use_mtls_endpoint)) - - if not transport_provided: - import google.auth._default # type: ignore - - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) - - transport_init: Union[Type[ProductInputsServiceTransport], Callable[..., ProductInputsServiceTransport]] = ( - ProductInputsServiceClient.get_transport_class(transport) - if isinstance(transport, str) or transport is None - else cast(Callable[..., ProductInputsServiceTransport], transport) - ) - # initialize with the provided callable or the passed in class - self._transport = transport_init( - credentials=credentials, - credentials_file=self._client_options.credentials_file, - host=self._api_endpoint, - scopes=self._client_options.scopes, - client_cert_source_for_mtls=self._client_cert_source, - quota_project_id=self._client_options.quota_project_id, - client_info=client_info, - always_use_jwt_access=True, - api_audience=self._client_options.api_audience, - ) - - if "async" not in str(self._transport): - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER - _LOGGER.debug( - "Created client `google.shopping.merchant.products_v1beta.ProductInputsServiceClient`.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), - "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._transport, "_credentials") else { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "credentialsType": None, - } - ) - - def insert_product_input(self, - request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: - r"""`Uploads a product input to your Merchant Center - account `__. - You must have a products data source to be able to insert a - product. The unique identifier of the data source is passed as a - query parameter in the request URL. - - If an input with the same contentLanguage, offerId, and - dataSource already exists, this method replaces that entry. - - After inserting, updating, or deleting a product input, it may - take several minutes before the processed product can be - retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - def sample_insert_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.InsertProductInputRequest( - parent="parent_value", - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = client.insert_product_input(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.shopping.merchant_products_v1beta.types.InsertProductInputRequest, dict]): - The request object. Request message for the - InsertProductInput method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.types.ProductInput: - This resource represents input data you submit for a product, not the - processed product that you see in Merchant Center, in - Shopping ads, or across Google surfaces. Product - inputs, rules and supplemental data source data are - combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. - For more information, see [Manage - products](/merchant/api/guides/products/overview). - - Required product input attributes to pass data - validation checks are primarily defined in the - [Products Data - Specification](\ https://support.google.com/merchants/answer/188494). - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product - input, it may take several minutes before the - processed product can be retrieved. - - All fields in the product input and its sub-messages - match the English name of their corresponding - attribute in the [Products Data - Specification](\ https://support.google.com/merchants/answer/188494) - with [some - exceptions](\ https://support.google.com/merchants/answer/7052112). - The following reference documentation lists the field - names in the **camelCase** casing style while the - Products Data Specification lists the names in the - **snake_case** casing style. - - """ - # Create or coerce a protobuf request object. - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, productinputs.InsertProductInputRequest): - request = productinputs.InsertProductInputRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.insert_product_input] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Validate the universe domain. - self._validate_universe_domain() - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def update_product_input(self, - request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, - *, - product_input: Optional[productinputs.ProductInput] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: - r"""Updates the existing product input in your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - def sample_update_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.UpdateProductInputRequest( - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = client.update_product_input(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest, dict]): - The request object. Request message for the - UpdateProductInput method. The product - (primary input) must exist for the - update to succeed. If the update is for - a primary product input, the existing - primary product input must be from the - same data source. - product_input (google.shopping.merchant_products_v1beta.types.ProductInput): - Required. The product input resource - to update. Information you submit will - be applied to the processed product as - well. - - This corresponds to the ``product_input`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Optional. The list of product attributes to be updated. - - If the update mask is omitted, then it is treated as - implied field mask equivalent to all fields that are - populated (have a non-empty value). - - Attributes specified in the update mask without a value - specified in the body will be deleted from the product. - - Update mask can only be specified for top level fields - in attributes and custom attributes. - - To specify the update mask for custom attributes you - need to add the ``custom_attribute.`` prefix. - - Providing special "*" value for full product replacement - is not supported. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.types.ProductInput: - This resource represents input data you submit for a product, not the - processed product that you see in Merchant Center, in - Shopping ads, or across Google surfaces. Product - inputs, rules and supplemental data source data are - combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. - For more information, see [Manage - products](/merchant/api/guides/products/overview). - - Required product input attributes to pass data - validation checks are primarily defined in the - [Products Data - Specification](\ https://support.google.com/merchants/answer/188494). - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product - input, it may take several minutes before the - processed product can be retrieved. - - All fields in the product input and its sub-messages - match the English name of their corresponding - attribute in the [Products Data - Specification](\ https://support.google.com/merchants/answer/188494) - with [some - exceptions](\ https://support.google.com/merchants/answer/7052112). - The following reference documentation lists the field - names in the **camelCase** casing style while the - Products Data Specification lists the names in the - **snake_case** casing style. - - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [product_input, update_mask] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, productinputs.UpdateProductInputRequest): - request = productinputs.UpdateProductInputRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if product_input is not None: - request.product_input = product_input - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_product_input] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_input.name", request.product_input.name), - )), - ) - - # Validate the universe domain. - self._validate_universe_domain() - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_product_input(self, - request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> None: - r"""Deletes a product input from your Merchant Center - account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - def sample_delete_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.DeleteProductInputRequest( - name="name_value", - data_source="data_source_value", - ) - - # Make the request - client.delete_product_input(request=request) - - Args: - request (Union[google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest, dict]): - The request object. Request message for the - DeleteProductInput method. - name (str): - Required. The name of the product input resource to - delete. Format: - ``accounts/{account}/productInputs/{product}`` where the - last section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example - for product name is - ``accounts/123/productInputs/online~en~US~sku123``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, productinputs.DeleteProductInputRequest): - request = productinputs.DeleteProductInputRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_product_input] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Validate the universe domain. - self._validate_universe_domain() - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def __enter__(self) -> "ProductInputsServiceClient": - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - -__all__ = ( - "ProductInputsServiceClient", -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst deleted file mode 100644 index fa031e4be3c9..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/README.rst +++ /dev/null @@ -1,9 +0,0 @@ - -transport inheritance structure -_______________________________ - -`ProductInputsServiceTransport` is the ABC for all transports. -- public child `ProductInputsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProductInputsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProductInputsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProductInputsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py deleted file mode 100644 index e9792827a667..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import ProductInputsServiceTransport -from .grpc import ProductInputsServiceGrpcTransport -from .grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport -from .rest import ProductInputsServiceRestTransport -from .rest import ProductInputsServiceRestInterceptor - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] -_transport_registry['grpc'] = ProductInputsServiceGrpcTransport -_transport_registry['grpc_asyncio'] = ProductInputsServiceGrpcAsyncIOTransport -_transport_registry['rest'] = ProductInputsServiceRestTransport - -__all__ = ( - 'ProductInputsServiceTransport', - 'ProductInputsServiceGrpcTransport', - 'ProductInputsServiceGrpcAsyncIOTransport', - 'ProductInputsServiceRestTransport', - 'ProductInputsServiceRestInterceptor', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py deleted file mode 100644 index 2fbd406ff780..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/base.py +++ /dev/null @@ -1,188 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union - -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -import google.auth # type: ignore -import google.api_core -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - -from google.protobuf import empty_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - - -class ProductInputsServiceTransport(abc.ABC): - """Abstract transport class for ProductInputsService.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/content', - ) - - DEFAULT_HOST: str = 'merchantapi.googleapis.com' - - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - - # Save the scopes. - self._scopes = scopes - if not hasattr(self, "_ignore_credentials"): - self._ignore_credentials: bool = False - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - elif credentials is None and not self._ignore_credentials: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - # Don't apply audience if the credentials file passed from user. - if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) - - # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - @property - def host(self): - return self._host - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.insert_product_input: gapic_v1.method.wrap_method( - self.insert_product_input, - default_timeout=None, - client_info=client_info, - ), - self.update_product_input: gapic_v1.method.wrap_method( - self.update_product_input, - default_timeout=None, - client_info=client_info, - ), - self.delete_product_input: gapic_v1.method.wrap_method( - self.delete_product_input, - default_timeout=None, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - Union[ - productinputs.ProductInput, - Awaitable[productinputs.ProductInput] - ]]: - raise NotImplementedError() - - @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - Union[ - productinputs.ProductInput, - Awaitable[productinputs.ProductInput] - ]]: - raise NotImplementedError() - - @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def kind(self) -> str: - raise NotImplementedError() - - -__all__ = ( - 'ProductInputsServiceTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py deleted file mode 100644 index 79403a317639..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc.py +++ /dev/null @@ -1,419 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json -import logging as std_logging -import pickle -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers -from google.api_core import gapic_v1 -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.protobuf.json_format import MessageToJson -import google.protobuf.message - -import grpc # type: ignore -import proto # type: ignore - -from google.protobuf import empty_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs -from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - - -class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER - def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) - if logging_enabled: # pragma: NO COVER - request_metadata = client_call_details.metadata - if isinstance(request, proto.Message): - request_payload = type(request).to_json(request) - elif isinstance(request, google.protobuf.message.Message): - request_payload = MessageToJson(request) - else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" - - request_metadata = { - key: value.decode("utf-8") if isinstance(value, bytes) else value - for key, value in request_metadata - } - grpc_request = { - "payload": request_payload, - "requestMethod": "grpc", - "metadata": dict(request_metadata), - } - _LOGGER.debug( - f"Sending request for {client_call_details.method}", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": str(client_call_details.method), - "request": grpc_request, - "metadata": grpc_request["metadata"], - }, - ) - response = continuation(client_call_details, request) - if logging_enabled: # pragma: NO COVER - response_metadata = response.trailing_metadata() - # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None - result = response.result() - if isinstance(result, proto.Message): - response_payload = type(result).to_json(result) - elif isinstance(result, google.protobuf.message.Message): - response_payload = MessageToJson(result) - else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" - grpc_response = { - "payload": response_payload, - "metadata": metadata, - "status": "OK", - } - _LOGGER.debug( - f"Received response for {client_call_details.method}.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": client_call_details.method, - "response": grpc_response, - "metadata": grpc_response["metadata"], - }, - ) - return response - - -class ProductInputsServiceGrpcTransport(ProductInputsServiceTransport): - """gRPC backend transport for ProductInputsService. - - Service to use ProductInput resource. - This service works for products with online channel only. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if a ``channel`` instance is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if a ``channel`` instance is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if a ``channel`` instance is provided. - channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): - A ``Channel`` instance through which to make calls, or a Callable - that constructs and returns one. If set to None, ``self.create_channel`` - is used to create the channel. If a Callable is given, it will be called - with the same arguments as used in ``self.create_channel``. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if a ``channel`` instance is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if isinstance(channel, grpc.Channel): - # Ignore credentials if a channel was passed. - credentials = None - self._ignore_credentials = True - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - # initialize with the provided callable or the default channel - channel_init = channel or type(self).create_channel - self._grpc_channel = channel_init( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - self._interceptor = _LoggingClientInterceptor() - self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) - - # Wrap messages. This must be done after self._logged_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - productinputs.ProductInput]: - r"""Return a callable for the insert product input method over gRPC. - - `Uploads a product input to your Merchant Center - account `__. - You must have a products data source to be able to insert a - product. The unique identifier of the data source is passed as a - query parameter in the request URL. - - If an input with the same contentLanguage, offerId, and - dataSource already exists, this method replaces that entry. - - After inserting, updating, or deleting a product input, it may - take several minutes before the processed product can be - retrieved. - - Returns: - Callable[[~.InsertProductInputRequest], - ~.ProductInput]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'insert_product_input' not in self._stubs: - self._stubs['insert_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductInputsService/InsertProductInput', - request_serializer=productinputs.InsertProductInputRequest.serialize, - response_deserializer=productinputs.ProductInput.deserialize, - ) - return self._stubs['insert_product_input'] - - @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - productinputs.ProductInput]: - r"""Return a callable for the update product input method over gRPC. - - Updates the existing product input in your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - Returns: - Callable[[~.UpdateProductInputRequest], - ~.ProductInput]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_product_input' not in self._stubs: - self._stubs['update_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductInputsService/UpdateProductInput', - request_serializer=productinputs.UpdateProductInputRequest.serialize, - response_deserializer=productinputs.ProductInput.deserialize, - ) - return self._stubs['update_product_input'] - - @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete product input method over gRPC. - - Deletes a product input from your Merchant Center - account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - Returns: - Callable[[~.DeleteProductInputRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_product_input' not in self._stubs: - self._stubs['delete_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductInputsService/DeleteProductInput', - request_serializer=productinputs.DeleteProductInputRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_input'] - - def close(self): - self._logged_channel.close() - - @property - def kind(self) -> str: - return "grpc" - - -__all__ = ( - 'ProductInputsServiceGrpcTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py deleted file mode 100644 index a7c5e8de0a0e..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/grpc_asyncio.py +++ /dev/null @@ -1,450 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import inspect -import json -import pickle -import logging as std_logging -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import exceptions as core_exceptions -from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.protobuf.json_format import MessageToJson -import google.protobuf.message - -import grpc # type: ignore -import proto # type: ignore -from grpc.experimental import aio # type: ignore - -from google.protobuf import empty_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs -from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO -from .grpc import ProductInputsServiceGrpcTransport - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - - -class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER - async def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) - if logging_enabled: # pragma: NO COVER - request_metadata = client_call_details.metadata - if isinstance(request, proto.Message): - request_payload = type(request).to_json(request) - elif isinstance(request, google.protobuf.message.Message): - request_payload = MessageToJson(request) - else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" - - request_metadata = { - key: value.decode("utf-8") if isinstance(value, bytes) else value - for key, value in request_metadata - } - grpc_request = { - "payload": request_payload, - "requestMethod": "grpc", - "metadata": dict(request_metadata), - } - _LOGGER.debug( - f"Sending request for {client_call_details.method}", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": str(client_call_details.method), - "request": grpc_request, - "metadata": grpc_request["metadata"], - }, - ) - response = await continuation(client_call_details, request) - if logging_enabled: # pragma: NO COVER - response_metadata = await response.trailing_metadata() - # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None - result = await response - if isinstance(result, proto.Message): - response_payload = type(result).to_json(result) - elif isinstance(result, google.protobuf.message.Message): - response_payload = MessageToJson(result) - else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" - grpc_response = { - "payload": response_payload, - "metadata": metadata, - "status": "OK", - } - _LOGGER.debug( - f"Received response to rpc {client_call_details.method}.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": str(client_call_details.method), - "response": grpc_response, - "metadata": grpc_response["metadata"], - }, - ) - return response - - -class ProductInputsServiceGrpcAsyncIOTransport(ProductInputsServiceTransport): - """gRPC AsyncIO backend transport for ProductInputsService. - - Service to use ProductInput resource. - This service works for products with online channel only. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if a ``channel`` instance is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if a ``channel`` instance is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): - A ``Channel`` instance through which to make calls, or a Callable - that constructs and returns one. If set to None, ``self.create_channel`` - is used to create the channel. If a Callable is given, it will be called - with the same arguments as used in ``self.create_channel``. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if a ``channel`` instance is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if isinstance(channel, aio.Channel): - # Ignore credentials if a channel was passed. - credentials = None - self._ignore_credentials = True - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - # initialize with the provided callable or the default channel - channel_init = channel or type(self).create_channel - self._grpc_channel = channel_init( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - self._interceptor = _LoggingClientAIOInterceptor() - self._grpc_channel._unary_unary_interceptors.append(self._interceptor) - self._logged_channel = self._grpc_channel - self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters - # Wrap messages. This must be done after self._logged_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - Awaitable[productinputs.ProductInput]]: - r"""Return a callable for the insert product input method over gRPC. - - `Uploads a product input to your Merchant Center - account `__. - You must have a products data source to be able to insert a - product. The unique identifier of the data source is passed as a - query parameter in the request URL. - - If an input with the same contentLanguage, offerId, and - dataSource already exists, this method replaces that entry. - - After inserting, updating, or deleting a product input, it may - take several minutes before the processed product can be - retrieved. - - Returns: - Callable[[~.InsertProductInputRequest], - Awaitable[~.ProductInput]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'insert_product_input' not in self._stubs: - self._stubs['insert_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductInputsService/InsertProductInput', - request_serializer=productinputs.InsertProductInputRequest.serialize, - response_deserializer=productinputs.ProductInput.deserialize, - ) - return self._stubs['insert_product_input'] - - @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - Awaitable[productinputs.ProductInput]]: - r"""Return a callable for the update product input method over gRPC. - - Updates the existing product input in your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - Returns: - Callable[[~.UpdateProductInputRequest], - Awaitable[~.ProductInput]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_product_input' not in self._stubs: - self._stubs['update_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductInputsService/UpdateProductInput', - request_serializer=productinputs.UpdateProductInputRequest.serialize, - response_deserializer=productinputs.ProductInput.deserialize, - ) - return self._stubs['update_product_input'] - - @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete product input method over gRPC. - - Deletes a product input from your Merchant Center - account. - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - Returns: - Callable[[~.DeleteProductInputRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_product_input' not in self._stubs: - self._stubs['delete_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductInputsService/DeleteProductInput', - request_serializer=productinputs.DeleteProductInputRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_product_input'] - - def _prep_wrapped_messages(self, client_info): - """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" - self._wrapped_methods = { - self.insert_product_input: self._wrap_method( - self.insert_product_input, - default_timeout=None, - client_info=client_info, - ), - self.update_product_input: self._wrap_method( - self.update_product_input, - default_timeout=None, - client_info=client_info, - ), - self.delete_product_input: self._wrap_method( - self.delete_product_input, - default_timeout=None, - client_info=client_info, - ), - } - - def _wrap_method(self, func, *args, **kwargs): - if self._wrap_with_kind: # pragma: NO COVER - kwargs["kind"] = self.kind - return gapic_v1.method_async.wrap_method(func, *args, **kwargs) - - def close(self): - return self._logged_channel.close() - - @property - def kind(self) -> str: - return "grpc_asyncio" - - -__all__ = ( - 'ProductInputsServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py deleted file mode 100644 index 5284480922da..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest.py +++ /dev/null @@ -1,711 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -import json # type: ignore - -from google.auth.transport.requests import AuthorizedSession # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.api_core import exceptions as core_exceptions -from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import gapic_v1 -import google.protobuf - -from google.protobuf import json_format - -from requests import __version__ as requests_version -import dataclasses -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - - -from google.protobuf import empty_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs - - -from .rest_base import _BaseProductInputsServiceRestTransport -from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object, None] # type: ignore - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = logging.getLogger(__name__) - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, - grpc_version=None, - rest_version=f"requests@{requests_version}", -) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - - -class ProductInputsServiceRestInterceptor: - """Interceptor for ProductInputsService. - - Interceptors are used to manipulate requests, request metadata, and responses - in arbitrary ways. - Example use cases include: - * Logging - * Verifying requests according to service or custom semantics - * Stripping extraneous information from responses - - These use cases and more can be enabled by injecting an - instance of a custom subclass when constructing the ProductInputsServiceRestTransport. - - .. code-block:: python - class MyCustomProductInputsServiceInterceptor(ProductInputsServiceRestInterceptor): - def pre_delete_product_input(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_insert_product_input(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_insert_product_input(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_update_product_input(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_update_product_input(self, response): - logging.log(f"Received response: {response}") - return response - - transport = ProductInputsServiceRestTransport(interceptor=MyCustomProductInputsServiceInterceptor()) - client = ProductInputsServiceClient(transport=transport) - - - """ - def pre_delete_product_input(self, request: productinputs.DeleteProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.DeleteProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: - """Pre-rpc interceptor for delete_product_input - - Override in a subclass to manipulate the request or metadata - before they are sent to the ProductInputsService server. - """ - return request, metadata - - def pre_insert_product_input(self, request: productinputs.InsertProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.InsertProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: - """Pre-rpc interceptor for insert_product_input - - Override in a subclass to manipulate the request or metadata - before they are sent to the ProductInputsService server. - """ - return request, metadata - - def post_insert_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: - """Post-rpc interceptor for insert_product_input - - DEPRECATED. Please use the `post_insert_product_input_with_metadata` - interceptor instead. - - Override in a subclass to read or manipulate the response - after it is returned by the ProductInputsService server but before - it is returned to user code. This `post_insert_product_input` interceptor runs - before the `post_insert_product_input_with_metadata` interceptor. - """ - return response - - def post_insert_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: - """Post-rpc interceptor for insert_product_input - - Override in a subclass to read or manipulate the response or metadata after it - is returned by the ProductInputsService server but before it is returned to user code. - - We recommend only using this `post_insert_product_input_with_metadata` - interceptor in new development instead of the `post_insert_product_input` interceptor. - When both interceptors are used, this `post_insert_product_input_with_metadata` interceptor runs after the - `post_insert_product_input` interceptor. The (possibly modified) response returned by - `post_insert_product_input` will be passed to - `post_insert_product_input_with_metadata`. - """ - return response, metadata - - def pre_update_product_input(self, request: productinputs.UpdateProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.UpdateProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: - """Pre-rpc interceptor for update_product_input - - Override in a subclass to manipulate the request or metadata - before they are sent to the ProductInputsService server. - """ - return request, metadata - - def post_update_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: - """Post-rpc interceptor for update_product_input - - DEPRECATED. Please use the `post_update_product_input_with_metadata` - interceptor instead. - - Override in a subclass to read or manipulate the response - after it is returned by the ProductInputsService server but before - it is returned to user code. This `post_update_product_input` interceptor runs - before the `post_update_product_input_with_metadata` interceptor. - """ - return response - - def post_update_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: - """Post-rpc interceptor for update_product_input - - Override in a subclass to read or manipulate the response or metadata after it - is returned by the ProductInputsService server but before it is returned to user code. - - We recommend only using this `post_update_product_input_with_metadata` - interceptor in new development instead of the `post_update_product_input` interceptor. - When both interceptors are used, this `post_update_product_input_with_metadata` interceptor runs after the - `post_update_product_input` interceptor. The (possibly modified) response returned by - `post_update_product_input` will be passed to - `post_update_product_input_with_metadata`. - """ - return response, metadata - - -@dataclasses.dataclass -class ProductInputsServiceRestStub: - _session: AuthorizedSession - _host: str - _interceptor: ProductInputsServiceRestInterceptor - - -class ProductInputsServiceRestTransport(_BaseProductInputsServiceRestTransport): - """REST backend synchronous transport for ProductInputsService. - - Service to use ProductInput resource. - This service works for products with online channel only. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - """ - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[ProductInputsServiceRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client - certificate to configure mutual TLS HTTP channel. It is ignored - if ``channel`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. - # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the - # credentials object - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - url_scheme=url_scheme, - api_audience=api_audience - ) - self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) - if client_cert_source_for_mtls: - self._session.configure_mtls_channel(client_cert_source_for_mtls) - self._interceptor = interceptor or ProductInputsServiceRestInterceptor() - self._prep_wrapped_messages(client_info) - - class _DeleteProductInput(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput, ProductInputsServiceRestStub): - def __hash__(self): - return hash("ProductInputsServiceRestTransport.DeleteProductInput") - - @staticmethod - def _get_response( - host, - metadata, - query_params, - session, - timeout, - transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(session, method)( - "{host}{uri}".format(host=host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - return response - - def __call__(self, - request: productinputs.DeleteProductInputRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ): - r"""Call the delete product input method over HTTP. - - Args: - request (~.productinputs.DeleteProductInputRequest): - The request object. Request message for the - DeleteProductInput method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - """ - - http_options = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_http_options() - - request, metadata = self._interceptor.pre_delete_product_input(request, metadata) - transcoded_request = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_transcoded_request(http_options, request) - - # Jsonify the query params - query_params = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] - try: - request_payload = json_format.MessageToJson(request) - except: - request_payload = None - http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), - } - _LOGGER.debug( - f"Sending request for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.DeleteProductInput", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": "DeleteProductInput", - "httpRequest": http_request, - "metadata": http_request["headers"], - }, - ) - - # Send the request - response = ProductInputsServiceRestTransport._DeleteProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _InsertProductInput(_BaseProductInputsServiceRestTransport._BaseInsertProductInput, ProductInputsServiceRestStub): - def __hash__(self): - return hash("ProductInputsServiceRestTransport.InsertProductInput") - - @staticmethod - def _get_response( - host, - metadata, - query_params, - session, - timeout, - transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(session, method)( - "{host}{uri}".format(host=host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - return response - - def __call__(self, - request: productinputs.InsertProductInputRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> productinputs.ProductInput: - r"""Call the insert product input method over HTTP. - - Args: - request (~.productinputs.InsertProductInputRequest): - The request object. Request message for the - InsertProductInput method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - ~.productinputs.ProductInput: - This resource represents input data you submit for a - product, not the processed product that you see in - Merchant Center, in Shopping ads, or across Google - surfaces. Product inputs, rules and supplemental data - source data are combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. - For more information, see `Manage - products `__. - - Required product input attributes to pass data - validation checks are primarily defined in the `Products - Data - Specification `__. - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - All fields in the product input and its sub-messages - match the English name of their corresponding attribute - in the `Products Data - Specification `__ - with `some - exceptions `__. - The following reference documentation lists the field - names in the **camelCase** casing style while the - Products Data Specification lists the names in the - **snake_case** casing style. - - """ - - http_options = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_http_options() - - request, metadata = self._interceptor.pre_insert_product_input(request, metadata) - transcoded_request = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_transcoded_request(http_options, request) - - body = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_request_body_json(transcoded_request) - - # Jsonify the query params - query_params = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] - try: - request_payload = type(request).to_json(request) - except: - request_payload = None - http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), - } - _LOGGER.debug( - f"Sending request for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.InsertProductInput", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": "InsertProductInput", - "httpRequest": http_request, - "metadata": http_request["headers"], - }, - ) - - # Send the request - response = ProductInputsServiceRestTransport._InsertProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = productinputs.ProductInput() - pb_resp = productinputs.ProductInput.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - - resp = self._interceptor.post_insert_product_input(resp) - response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_insert_product_input_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - try: - response_payload = productinputs.ProductInput.to_json(response) - except: - response_payload = None - http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, - } - _LOGGER.debug( - "Received response for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.insert_product_input", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": "InsertProductInput", - "metadata": http_response["headers"], - "httpResponse": http_response, - }, - ) - return resp - - class _UpdateProductInput(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput, ProductInputsServiceRestStub): - def __hash__(self): - return hash("ProductInputsServiceRestTransport.UpdateProductInput") - - @staticmethod - def _get_response( - host, - metadata, - query_params, - session, - timeout, - transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(session, method)( - "{host}{uri}".format(host=host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - return response - - def __call__(self, - request: productinputs.UpdateProductInputRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> productinputs.ProductInput: - r"""Call the update product input method over HTTP. - - Args: - request (~.productinputs.UpdateProductInputRequest): - The request object. Request message for the - UpdateProductInput method. The product - (primary input) must exist for the - update to succeed. If the update is for - a primary product input, the existing - primary product input must be from the - same data source. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - ~.productinputs.ProductInput: - This resource represents input data you submit for a - product, not the processed product that you see in - Merchant Center, in Shopping ads, or across Google - surfaces. Product inputs, rules and supplemental data - source data are combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. - For more information, see `Manage - products `__. - - Required product input attributes to pass data - validation checks are primarily defined in the `Products - Data - Specification `__. - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product input, - it may take several minutes before the processed product - can be retrieved. - - All fields in the product input and its sub-messages - match the English name of their corresponding attribute - in the `Products Data - Specification `__ - with `some - exceptions `__. - The following reference documentation lists the field - names in the **camelCase** casing style while the - Products Data Specification lists the names in the - **snake_case** casing style. - - """ - - http_options = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_http_options() - - request, metadata = self._interceptor.pre_update_product_input(request, metadata) - transcoded_request = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_transcoded_request(http_options, request) - - body = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_request_body_json(transcoded_request) - - # Jsonify the query params - query_params = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] - try: - request_payload = type(request).to_json(request) - except: - request_payload = None - http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), - } - _LOGGER.debug( - f"Sending request for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.UpdateProductInput", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": "UpdateProductInput", - "httpRequest": http_request, - "metadata": http_request["headers"], - }, - ) - - # Send the request - response = ProductInputsServiceRestTransport._UpdateProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = productinputs.ProductInput() - pb_resp = productinputs.ProductInput.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - - resp = self._interceptor.post_update_product_input(resp) - response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_update_product_input_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - try: - response_payload = productinputs.ProductInput.to_json(response) - except: - response_payload = None - http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, - } - _LOGGER.debug( - "Received response for google.shopping.merchant.products_v1beta.ProductInputsServiceClient.update_product_input", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "rpcName": "UpdateProductInput", - "metadata": http_response["headers"], - "httpResponse": http_response, - }, - ) - return resp - - @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._DeleteProductInput(self._session, self._host, self._interceptor) # type: ignore - - @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - productinputs.ProductInput]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._InsertProductInput(self._session, self._host, self._interceptor) # type: ignore - - @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - productinputs.ProductInput]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._UpdateProductInput(self._session, self._host, self._interceptor) # type: ignore - - @property - def kind(self) -> str: - return "rest" - - def close(self): - self._session.close() - - -__all__=( - 'ProductInputsServiceRestTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py deleted file mode 100644 index 7518357fe1db..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/product_inputs_service/transports/rest_base.py +++ /dev/null @@ -1,223 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json # type: ignore -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO - -import re -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union - - -from google.protobuf import empty_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import productinputs - - -class _BaseProductInputsServiceRestTransport(ProductInputsServiceTransport): - """Base REST backend transport for ProductInputsService. - - Note: This class is not meant to be used directly. Use its sync and - async sub-classes instead. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - """ - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[Any] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[Any]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) - if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER - - url_match_items = maybe_url_match.groupdict() - - host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host - - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience - ) - - class _BaseDeleteProductInput: - def __hash__(self): # pragma: NO COVER - return NotImplementedError("__hash__ must be implemented.") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "dataSource" : "", } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - @staticmethod - def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/products/v1beta/{name=accounts/*/productInputs/*}', - }, - ] - return http_options - - @staticmethod - def _get_transcoded_request(http_options, request): - pb_request = productinputs.DeleteProductInputRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - return transcoded_request - - @staticmethod - def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - return query_params - - class _BaseInsertProductInput: - def __hash__(self): # pragma: NO COVER - return NotImplementedError("__hash__ must be implemented.") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "dataSource" : "", } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - @staticmethod - def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/products/v1beta/{parent=accounts/*}/productInputs:insert', - 'body': 'product_input', - }, - ] - return http_options - - @staticmethod - def _get_transcoded_request(http_options, request): - pb_request = productinputs.InsertProductInputRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - return transcoded_request - - @staticmethod - def _get_request_body_json(transcoded_request): - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - use_integers_for_enums=True - ) - return body - @staticmethod - def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - return query_params - - class _BaseUpdateProductInput: - def __hash__(self): # pragma: NO COVER - return NotImplementedError("__hash__ must be implemented.") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "dataSource" : "", } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - @staticmethod - def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/products/v1beta/{product_input.name=accounts/*/productInputs/*}', - 'body': 'product_input', - }, - ] - return http_options - - @staticmethod - def _get_transcoded_request(http_options, request): - pb_request = productinputs.UpdateProductInputRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - return transcoded_request - - @staticmethod - def _get_request_body_json(transcoded_request): - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - use_integers_for_enums=True - ) - return body - @staticmethod - def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - return query_params - - -__all__=( - '_BaseProductInputsServiceRestTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py deleted file mode 100644 index f3c4a4aa101a..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/async_client.py +++ /dev/null @@ -1,522 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging as std_logging -from collections import OrderedDict -import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union - -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -from google.api_core.client_options import ClientOptions -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - - -try: - OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore - -from google.shopping.merchant_products_v1beta.services.products_service import pagers -from google.shopping.merchant_products_v1beta.types import products -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types -from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport -from .client import ProductsServiceClient - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - -class ProductsServiceAsyncClient: - """Service to use Product resource.""" - - _client: ProductsServiceClient - - # Copy defaults from the synchronous client for use here. - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = ProductsServiceClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - _DEFAULT_ENDPOINT_TEMPLATE = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE - _DEFAULT_UNIVERSE = ProductsServiceClient._DEFAULT_UNIVERSE - - product_path = staticmethod(ProductsServiceClient.product_path) - parse_product_path = staticmethod(ProductsServiceClient.parse_product_path) - common_billing_account_path = staticmethod(ProductsServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductsServiceClient.parse_common_billing_account_path) - common_folder_path = staticmethod(ProductsServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductsServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductsServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductsServiceClient.parse_common_organization_path) - common_project_path = staticmethod(ProductsServiceClient.common_project_path) - parse_common_project_path = staticmethod(ProductsServiceClient.parse_common_project_path) - common_location_path = staticmethod(ProductsServiceClient.common_location_path) - parse_common_location_path = staticmethod(ProductsServiceClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductsServiceAsyncClient: The constructed client. - """ - return ProductsServiceClient.from_service_account_info.__func__(ProductsServiceAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductsServiceAsyncClient: The constructed client. - """ - return ProductsServiceClient.from_service_account_file.__func__(ProductsServiceAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - return ProductsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore - - @property - def transport(self) -> ProductsServiceTransport: - """Returns the transport used by the client instance. - - Returns: - ProductsServiceTransport: The transport used by the client instance. - """ - return self._client.transport - - @property - def api_endpoint(self): - """Return the API endpoint used by the client instance. - - Returns: - str: The API endpoint used by the client instance. - """ - return self._client._api_endpoint - - @property - def universe_domain(self) -> str: - """Return the universe domain used by the client instance. - - Returns: - str: The universe domain used - by the client instance. - """ - return self._client._universe_domain - - get_transport_class = ProductsServiceClient.get_transport_class - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the products service async client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Optional[Union[str,ProductsServiceTransport,Callable[..., ProductsServiceTransport]]]): - The transport to use, or a Callable that constructs and returns a new transport to use. - If a Callable is given, it will be called with the same set of initialization - arguments as used in the ProductsServiceTransport constructor. - If set to None, a transport is chosen automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): - Custom options for the client. - - 1. The ``api_endpoint`` property can be used to override the - default endpoint provided by the client when ``transport`` is - not explicitly provided. Only if this property is not set and - ``transport`` was not explicitly provided, the endpoint is - determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment - variable, which have one of the following values: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto-switch to the - default mTLS endpoint if client certificate is present; this is - the default value). - - 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide a client certificate for mTLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - 3. The ``universe_domain`` property can be used to override the - default "googleapis.com" universe. Note that ``api_endpoint`` - property still takes precedence; and ``universe_domain`` is - currently not supported for mTLS. - - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = ProductsServiceClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER - _LOGGER.debug( - "Created client `google.shopping.merchant.products_v1beta.ProductsServiceAsyncClient`.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), - "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._client._transport, "_credentials") else { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "credentialsType": None, - } - ) - - async def get_product(self, - request: Optional[Union[products.GetProductRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> products.Product: - r"""Retrieves the processed product from your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the updated final - product can be retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - async def sample_get_product(): - # Create a client - client = merchant_products_v1beta.ProductsServiceAsyncClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.GetProductRequest( - name="name_value", - ) - - # Make the request - response = await client.get_product(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.shopping.merchant_products_v1beta.types.GetProductRequest, dict]]): - The request object. Request message for the GetProduct - method. - name (:class:`str`): - Required. The name of the product to retrieve. Format: - ``accounts/{account}/products/{product}`` where the last - section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example - for product name is - ``accounts/123/products/online~en~US~sku123`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.types.Product: - The processed product, built from multiple [product - inputs][google.shopping.merchant.products.v1main.ProductInput] - after applying rules and supplemental data sources. - This processed product matches what is shown in your - Merchant Center account. Each product is built from - exactly one primary data source product input, and - multiple supplemental data source inputs. After - inserting, updating, or deleting a product input, it - may take several minutes before the updated processed - product can be retrieved. - - All fields in the processed product and its - sub-messages match the name of their corresponding - attribute in the [Product data - specification](\ https://support.google.com/merchants/answer/7052112) - with some exceptions. - - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, products.GetProductRequest): - request = products.GetProductRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.get_product] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Validate the universe domain. - self._client._validate_universe_domain() - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_products(self, - request: Optional[Union[products.ListProductsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> pagers.ListProductsAsyncPager: - r"""Lists the processed products in your Merchant Center account. - The response might contain fewer items than specified by - ``pageSize``. Rely on ``pageToken`` to determine if there are - more items to be requested. - - After inserting, updating, or deleting a product input, it may - take several minutes before the updated processed product can be - retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - async def sample_list_products(): - # Create a client - client = merchant_products_v1beta.ProductsServiceAsyncClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.ListProductsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_products(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.shopping.merchant_products_v1beta.types.ListProductsRequest, dict]]): - The request object. Request message for the ListProducts - method. - parent (:class:`str`): - Required. The account to list processed products for. - Format: ``accounts/{account}`` - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsAsyncPager: - Response message for the ListProducts - method. - Iterating over this object will yield - results and resolve additional pages - automatically. - - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [parent] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, products.ListProductsRequest): - request = products.ListProductsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.list_products] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Validate the universe domain. - self._client._validate_universe_domain() - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListProductsAsyncPager( - method=rpc, - request=request, - response=response, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self) -> "ProductsServiceAsyncClient": - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - - -__all__ = ( - "ProductsServiceAsyncClient", -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py deleted file mode 100644 index cea09df43fbe..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/client.py +++ /dev/null @@ -1,881 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from http import HTTPStatus -import json -import logging as std_logging -import os -import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast -import warnings - -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -from google.api_core import client_options as client_options_lib -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object, None] # type: ignore - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - -from google.shopping.merchant_products_v1beta.services.products_service import pagers -from google.shopping.merchant_products_v1beta.types import products -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types -from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import ProductsServiceGrpcTransport -from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport -from .transports.rest import ProductsServiceRestTransport - - -class ProductsServiceClientMeta(type): - """Metaclass for the ProductsService client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] - _transport_registry["grpc"] = ProductsServiceGrpcTransport - _transport_registry["grpc_asyncio"] = ProductsServiceGrpcAsyncIOTransport - _transport_registry["rest"] = ProductsServiceRestTransport - - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[ProductsServiceTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class ProductsServiceClient(metaclass=ProductsServiceClientMeta): - """Service to use Product resource.""" - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. - DEFAULT_ENDPOINT = "merchantapi.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - _DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.{UNIVERSE_DOMAIN}" - _DEFAULT_UNIVERSE = "googleapis.com" - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductsServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - ProductsServiceClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> ProductsServiceTransport: - """Returns the transport used by the client instance. - - Returns: - ProductsServiceTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def product_path(account: str,product: str,) -> str: - """Returns a fully-qualified product string.""" - return "accounts/{account}/products/{product}".format(account=account, product=product, ) - - @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: - """Parses a product path into its component segments.""" - m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): - """Deprecated. Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - - warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", - DeprecationWarning) - if client_options is None: - client_options = client_options_lib.ClientOptions() - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - - # Figure out the client cert source to use. - client_cert_source = None - if use_client_cert == "true": - if client_options.client_cert_source: - client_cert_source = client_options.client_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - api_endpoint = cls.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = cls.DEFAULT_ENDPOINT - - return api_endpoint, client_cert_source - - @staticmethod - def _read_environment_variables(): - """Returns the environment variables used by the client. - - Returns: - Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, - GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. - - Raises: - ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not - any of ["true", "false"]. - google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT - is not any of ["auto", "never", "always"]. - """ - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() - universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - return use_client_cert == "true", use_mtls_endpoint, universe_domain_env - - @staticmethod - def _get_client_cert_source(provided_cert_source, use_cert_flag): - """Return the client cert source to be used by the client. - - Args: - provided_cert_source (bytes): The client certificate source provided. - use_cert_flag (bool): A flag indicating whether to use the client certificate. - - Returns: - bytes or None: The client cert source to be used by the client. - """ - client_cert_source = None - if use_cert_flag: - if provided_cert_source: - client_cert_source = provided_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - return client_cert_source - - @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): - """Return the API endpoint used by the client. - - Args: - api_override (str): The API endpoint override. If specified, this is always - the return value of this function and the other arguments are not used. - client_cert_source (bytes): The client certificate source used by the client. - universe_domain (str): The universe domain used by the client. - use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. - Possible values are "always", "auto", or "never". - - Returns: - str: The API endpoint to be used by the client. - """ - if api_override is not None: - api_endpoint = api_override - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - _default_universe = ProductsServiceClient._DEFAULT_UNIVERSE - if universe_domain != _default_universe: - raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") - api_endpoint = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) - return api_endpoint - - @staticmethod - def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: - """Return the universe domain used by the client. - - Args: - client_universe_domain (Optional[str]): The universe domain configured via the client options. - universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. - - Returns: - str: The universe domain to be used by the client. - - Raises: - ValueError: If the universe domain is an empty string. - """ - universe_domain = ProductsServiceClient._DEFAULT_UNIVERSE - if client_universe_domain is not None: - universe_domain = client_universe_domain - elif universe_domain_env is not None: - universe_domain = universe_domain_env - if len(universe_domain.strip()) == 0: - raise ValueError("Universe Domain cannot be an empty string.") - return universe_domain - - def _validate_universe_domain(self): - """Validates client's and credentials' universe domains are consistent. - - Returns: - bool: True iff the configured universe domain is valid. - - Raises: - ValueError: If the configured universe domain is not valid. - """ - - # NOTE (b/349488459): universe validation is disabled until further notice. - return True - - def _add_cred_info_for_auth_errors( - self, - error: core_exceptions.GoogleAPICallError - ) -> None: - """Adds credential info string to error details for 401/403/404 errors. - - Args: - error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. - """ - if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: - return - - cred = self._transport._credentials - - # get_cred_info is only available in google-auth>=2.35.0 - if not hasattr(cred, "get_cred_info"): - return - - # ignore the type check since pypy test fails when get_cred_info - # is not available - cred_info = cred.get_cred_info() # type: ignore - if cred_info and hasattr(error._details, "append"): - error._details.append(json.dumps(cred_info)) - - @property - def api_endpoint(self): - """Return the API endpoint used by the client instance. - - Returns: - str: The API endpoint used by the client instance. - """ - return self._api_endpoint - - @property - def universe_domain(self) -> str: - """Return the universe domain used by the client instance. - - Returns: - str: The universe domain used by the client instance. - """ - return self._universe_domain - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the products service client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Optional[Union[str,ProductsServiceTransport,Callable[..., ProductsServiceTransport]]]): - The transport to use, or a Callable that constructs and returns a new transport. - If a Callable is given, it will be called with the same set of initialization - arguments as used in the ProductsServiceTransport constructor. - If set to None, a transport is chosen automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): - Custom options for the client. - - 1. The ``api_endpoint`` property can be used to override the - default endpoint provided by the client when ``transport`` is - not explicitly provided. Only if this property is not set and - ``transport`` was not explicitly provided, the endpoint is - determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment - variable, which have one of the following values: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto-switch to the - default mTLS endpoint if client certificate is present; this is - the default value). - - 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide a client certificate for mTLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - 3. The ``universe_domain`` property can be used to override the - default "googleapis.com" universe. Note that the ``api_endpoint`` - property still takes precedence; and ``universe_domain`` is - currently not supported for mTLS. - - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client_options = client_options - if isinstance(self._client_options, dict): - self._client_options = client_options_lib.from_dict(self._client_options) - if self._client_options is None: - self._client_options = client_options_lib.ClientOptions() - self._client_options = cast(client_options_lib.ClientOptions, self._client_options) - - universe_domain_opt = getattr(self._client_options, 'universe_domain', None) - - self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductsServiceClient._read_environment_variables() - self._client_cert_source = ProductsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) - self._universe_domain = ProductsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` - - # Initialize the universe domain validation. - self._is_universe_domain_valid = False - - if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER - # Setup logging. - client_logging.initialize_logging() - - api_key_value = getattr(self._client_options, "api_key", None) - if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - transport_provided = isinstance(transport, ProductsServiceTransport) - if transport_provided: - # transport is a ProductsServiceTransport instance. - if credentials or self._client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if self._client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = cast(ProductsServiceTransport, transport) - self._api_endpoint = self._transport.host - - self._api_endpoint = (self._api_endpoint or - ProductsServiceClient._get_api_endpoint( - self._client_options.api_endpoint, - self._client_cert_source, - self._universe_domain, - self._use_mtls_endpoint)) - - if not transport_provided: - import google.auth._default # type: ignore - - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) - - transport_init: Union[Type[ProductsServiceTransport], Callable[..., ProductsServiceTransport]] = ( - ProductsServiceClient.get_transport_class(transport) - if isinstance(transport, str) or transport is None - else cast(Callable[..., ProductsServiceTransport], transport) - ) - # initialize with the provided callable or the passed in class - self._transport = transport_init( - credentials=credentials, - credentials_file=self._client_options.credentials_file, - host=self._api_endpoint, - scopes=self._client_options.scopes, - client_cert_source_for_mtls=self._client_cert_source, - quota_project_id=self._client_options.quota_project_id, - client_info=client_info, - always_use_jwt_access=True, - api_audience=self._client_options.api_audience, - ) - - if "async" not in str(self._transport): - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER - _LOGGER.debug( - "Created client `google.shopping.merchant.products_v1beta.ProductsServiceClient`.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), - "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._transport, "_credentials") else { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "credentialsType": None, - } - ) - - def get_product(self, - request: Optional[Union[products.GetProductRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> products.Product: - r"""Retrieves the processed product from your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the updated final - product can be retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - def sample_get_product(): - # Create a client - client = merchant_products_v1beta.ProductsServiceClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.GetProductRequest( - name="name_value", - ) - - # Make the request - response = client.get_product(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.shopping.merchant_products_v1beta.types.GetProductRequest, dict]): - The request object. Request message for the GetProduct - method. - name (str): - Required. The name of the product to retrieve. Format: - ``accounts/{account}/products/{product}`` where the last - section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example - for product name is - ``accounts/123/products/online~en~US~sku123`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.types.Product: - The processed product, built from multiple [product - inputs][google.shopping.merchant.products.v1main.ProductInput] - after applying rules and supplemental data sources. - This processed product matches what is shown in your - Merchant Center account. Each product is built from - exactly one primary data source product input, and - multiple supplemental data source inputs. After - inserting, updating, or deleting a product input, it - may take several minutes before the updated processed - product can be retrieved. - - All fields in the processed product and its - sub-messages match the name of their corresponding - attribute in the [Product data - specification](\ https://support.google.com/merchants/answer/7052112) - with some exceptions. - - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, products.GetProductRequest): - request = products.GetProductRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_product] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Validate the universe domain. - self._validate_universe_domain() - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def list_products(self, - request: Optional[Union[products.ListProductsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> pagers.ListProductsPager: - r"""Lists the processed products in your Merchant Center account. - The response might contain fewer items than specified by - ``pageSize``. Rely on ``pageToken`` to determine if there are - more items to be requested. - - After inserting, updating, or deleting a product input, it may - take several minutes before the updated processed product can be - retrieved. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.shopping import merchant_products_v1beta - - def sample_list_products(): - # Create a client - client = merchant_products_v1beta.ProductsServiceClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.ListProductsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_products(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.shopping.merchant_products_v1beta.types.ListProductsRequest, dict]): - The request object. Request message for the ListProducts - method. - parent (str): - Required. The account to list processed products for. - Format: ``accounts/{account}`` - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsPager: - Response message for the ListProducts - method. - Iterating over this object will yield - results and resolve additional pages - automatically. - - """ - # Create or coerce a protobuf request object. - # - Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - flattened_params = [parent] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # - Use the request object if provided (there's no risk of modifying the input as - # there are no flattened fields), or create one. - if not isinstance(request, products.ListProductsRequest): - request = products.ListProductsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_products] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Validate the universe domain. - self._validate_universe_domain() - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListProductsPager( - method=rpc, - request=request, - response=response, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def __enter__(self) -> "ProductsServiceClient": - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - -__all__ = ( - "ProductsServiceClient", -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py deleted file mode 100644 index f5b22754278b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/pagers.py +++ /dev/null @@ -1,166 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.api_core import retry_async as retries_async -from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator, Union -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] - OptionalAsyncRetry = Union[retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object, None] # type: ignore - OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore - -from google.shopping.merchant_products_v1beta.types import products - - -class ListProductsPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., products.ListProductsResponse], - request: products.ListProductsRequest, - response: products.ListProductsResponse, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.shopping.merchant_products_v1beta.types.ListProductsRequest): - The initial request object. - response (google.shopping.merchant_products_v1beta.types.ListProductsResponse): - The initial response object. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - """ - self._method = method - self._request = products.ListProductsRequest(request) - self._response = response - self._retry = retry - self._timeout = timeout - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[products.ListProductsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[products.Product]: - for page in self.pages: - yield from page.products - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListProductsAsyncPager: - """A pager for iterating through ``list_products`` requests. - - This class thinly wraps an initial - :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``products`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListProducts`` requests and continue to iterate - through the ``products`` field on the - corresponding responses. - - All the usual :class:`google.shopping.merchant_products_v1beta.types.ListProductsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[products.ListProductsResponse]], - request: products.ListProductsRequest, - response: products.ListProductsResponse, - *, - retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.shopping.merchant_products_v1beta.types.ListProductsRequest): - The initial request object. - response (google.shopping.merchant_products_v1beta.types.ListProductsResponse): - The initial response object. - retry (google.api_core.retry.AsyncRetry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - """ - self._method = method - self._request = products.ListProductsRequest(request) - self._response = response - self._retry = retry - self._timeout = timeout - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[products.ListProductsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[products.Product]: - async def async_generator(): - async for page in self.pages: - for response in page.products: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst deleted file mode 100644 index c1cbe3d98697..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/README.rst +++ /dev/null @@ -1,9 +0,0 @@ - -transport inheritance structure -_______________________________ - -`ProductsServiceTransport` is the ABC for all transports. -- public child `ProductsServiceGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `ProductsServiceGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseProductsServiceRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `ProductsServiceRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py deleted file mode 100644 index 29d073519076..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import ProductsServiceTransport -from .grpc import ProductsServiceGrpcTransport -from .grpc_asyncio import ProductsServiceGrpcAsyncIOTransport -from .rest import ProductsServiceRestTransport -from .rest import ProductsServiceRestInterceptor - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] -_transport_registry['grpc'] = ProductsServiceGrpcTransport -_transport_registry['grpc_asyncio'] = ProductsServiceGrpcAsyncIOTransport -_transport_registry['rest'] = ProductsServiceRestTransport - -__all__ = ( - 'ProductsServiceTransport', - 'ProductsServiceGrpcTransport', - 'ProductsServiceGrpcAsyncIOTransport', - 'ProductsServiceRestTransport', - 'ProductsServiceRestInterceptor', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py deleted file mode 100644 index 6fa077ce7155..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/base.py +++ /dev/null @@ -1,173 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union - -from google.shopping.merchant_products_v1beta import gapic_version as package_version - -import google.auth # type: ignore -import google.api_core -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore -import google.protobuf - -from google.shopping.merchant_products_v1beta.types import products - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - - -class ProductsServiceTransport(abc.ABC): - """Abstract transport class for ProductsService.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/content', - ) - - DEFAULT_HOST: str = 'merchantapi.googleapis.com' - - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - - # Save the scopes. - self._scopes = scopes - if not hasattr(self, "_ignore_credentials"): - self._ignore_credentials: bool = False - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - elif credentials is None and not self._ignore_credentials: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - # Don't apply audience if the credentials file passed from user. - if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) - - # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - @property - def host(self): - return self._host - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.get_product: gapic_v1.method.wrap_method( - self.get_product, - default_timeout=None, - client_info=client_info, - ), - self.list_products: gapic_v1.method.wrap_method( - self.list_products, - default_timeout=None, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - Union[ - products.Product, - Awaitable[products.Product] - ]]: - raise NotImplementedError() - - @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - Union[ - products.ListProductsResponse, - Awaitable[products.ListProductsResponse] - ]]: - raise NotImplementedError() - - @property - def kind(self) -> str: - raise NotImplementedError() - - -__all__ = ( - 'ProductsServiceTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py deleted file mode 100644 index 628a7d22acfd..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc.py +++ /dev/null @@ -1,383 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json -import logging as std_logging -import pickle -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers -from google.api_core import gapic_v1 -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.protobuf.json_format import MessageToJson -import google.protobuf.message - -import grpc # type: ignore -import proto # type: ignore - -from google.shopping.merchant_products_v1beta.types import products -from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - - -class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER - def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) - if logging_enabled: # pragma: NO COVER - request_metadata = client_call_details.metadata - if isinstance(request, proto.Message): - request_payload = type(request).to_json(request) - elif isinstance(request, google.protobuf.message.Message): - request_payload = MessageToJson(request) - else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" - - request_metadata = { - key: value.decode("utf-8") if isinstance(value, bytes) else value - for key, value in request_metadata - } - grpc_request = { - "payload": request_payload, - "requestMethod": "grpc", - "metadata": dict(request_metadata), - } - _LOGGER.debug( - f"Sending request for {client_call_details.method}", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": str(client_call_details.method), - "request": grpc_request, - "metadata": grpc_request["metadata"], - }, - ) - response = continuation(client_call_details, request) - if logging_enabled: # pragma: NO COVER - response_metadata = response.trailing_metadata() - # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None - result = response.result() - if isinstance(result, proto.Message): - response_payload = type(result).to_json(result) - elif isinstance(result, google.protobuf.message.Message): - response_payload = MessageToJson(result) - else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" - grpc_response = { - "payload": response_payload, - "metadata": metadata, - "status": "OK", - } - _LOGGER.debug( - f"Received response for {client_call_details.method}.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": client_call_details.method, - "response": grpc_response, - "metadata": grpc_response["metadata"], - }, - ) - return response - - -class ProductsServiceGrpcTransport(ProductsServiceTransport): - """gRPC backend transport for ProductsService. - - Service to use Product resource. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if a ``channel`` instance is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if a ``channel`` instance is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if a ``channel`` instance is provided. - channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): - A ``Channel`` instance through which to make calls, or a Callable - that constructs and returns one. If set to None, ``self.create_channel`` - is used to create the channel. If a Callable is given, it will be called - with the same arguments as used in ``self.create_channel``. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if a ``channel`` instance is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if isinstance(channel, grpc.Channel): - # Ignore credentials if a channel was passed. - credentials = None - self._ignore_credentials = True - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - # initialize with the provided callable or the default channel - channel_init = channel or type(self).create_channel - self._grpc_channel = channel_init( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - self._interceptor = _LoggingClientInterceptor() - self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) - - # Wrap messages. This must be done after self._logged_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - products.Product]: - r"""Return a callable for the get product method over gRPC. - - Retrieves the processed product from your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the updated final - product can be retrieved. - - Returns: - Callable[[~.GetProductRequest], - ~.Product]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_product' not in self._stubs: - self._stubs['get_product'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductsService/GetProduct', - request_serializer=products.GetProductRequest.serialize, - response_deserializer=products.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - products.ListProductsResponse]: - r"""Return a callable for the list products method over gRPC. - - Lists the processed products in your Merchant Center account. - The response might contain fewer items than specified by - ``pageSize``. Rely on ``pageToken`` to determine if there are - more items to be requested. - - After inserting, updating, or deleting a product input, it may - take several minutes before the updated processed product can be - retrieved. - - Returns: - Callable[[~.ListProductsRequest], - ~.ListProductsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_products' not in self._stubs: - self._stubs['list_products'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductsService/ListProducts', - request_serializer=products.ListProductsRequest.serialize, - response_deserializer=products.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - def close(self): - self._logged_channel.close() - - @property - def kind(self) -> str: - return "grpc" - - -__all__ = ( - 'ProductsServiceGrpcTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py deleted file mode 100644 index cff684bcb9f2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/grpc_asyncio.py +++ /dev/null @@ -1,409 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import inspect -import json -import pickle -import logging as std_logging -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import exceptions as core_exceptions -from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.protobuf.json_format import MessageToJson -import google.protobuf.message - -import grpc # type: ignore -import proto # type: ignore -from grpc.experimental import aio # type: ignore - -from google.shopping.merchant_products_v1beta.types import products -from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO -from .grpc import ProductsServiceGrpcTransport - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = std_logging.getLogger(__name__) - - -class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER - async def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) - if logging_enabled: # pragma: NO COVER - request_metadata = client_call_details.metadata - if isinstance(request, proto.Message): - request_payload = type(request).to_json(request) - elif isinstance(request, google.protobuf.message.Message): - request_payload = MessageToJson(request) - else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" - - request_metadata = { - key: value.decode("utf-8") if isinstance(value, bytes) else value - for key, value in request_metadata - } - grpc_request = { - "payload": request_payload, - "requestMethod": "grpc", - "metadata": dict(request_metadata), - } - _LOGGER.debug( - f"Sending request for {client_call_details.method}", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": str(client_call_details.method), - "request": grpc_request, - "metadata": grpc_request["metadata"], - }, - ) - response = await continuation(client_call_details, request) - if logging_enabled: # pragma: NO COVER - response_metadata = await response.trailing_metadata() - # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None - result = await response - if isinstance(result, proto.Message): - response_payload = type(result).to_json(result) - elif isinstance(result, google.protobuf.message.Message): - response_payload = MessageToJson(result) - else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" - grpc_response = { - "payload": response_payload, - "metadata": metadata, - "status": "OK", - } - _LOGGER.debug( - f"Received response to rpc {client_call_details.method}.", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": str(client_call_details.method), - "response": grpc_response, - "metadata": grpc_response["metadata"], - }, - ) - return response - - -class ProductsServiceGrpcAsyncIOTransport(ProductsServiceTransport): - """gRPC AsyncIO backend transport for ProductsService. - - Service to use Product resource. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if a ``channel`` instance is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if a ``channel`` instance is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): - A ``Channel`` instance through which to make calls, or a Callable - that constructs and returns one. If set to None, ``self.create_channel`` - is used to create the channel. If a Callable is given, it will be called - with the same arguments as used in ``self.create_channel``. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if a ``channel`` instance is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if isinstance(channel, aio.Channel): - # Ignore credentials if a channel was passed. - credentials = None - self._ignore_credentials = True - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - # initialize with the provided callable or the default channel - channel_init = channel or type(self).create_channel - self._grpc_channel = channel_init( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - self._interceptor = _LoggingClientAIOInterceptor() - self._grpc_channel._unary_unary_interceptors.append(self._interceptor) - self._logged_channel = self._grpc_channel - self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters - # Wrap messages. This must be done after self._logged_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - Awaitable[products.Product]]: - r"""Return a callable for the get product method over gRPC. - - Retrieves the processed product from your Merchant - Center account. - After inserting, updating, or deleting a product input, - it may take several minutes before the updated final - product can be retrieved. - - Returns: - Callable[[~.GetProductRequest], - Awaitable[~.Product]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_product' not in self._stubs: - self._stubs['get_product'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductsService/GetProduct', - request_serializer=products.GetProductRequest.serialize, - response_deserializer=products.Product.deserialize, - ) - return self._stubs['get_product'] - - @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - Awaitable[products.ListProductsResponse]]: - r"""Return a callable for the list products method over gRPC. - - Lists the processed products in your Merchant Center account. - The response might contain fewer items than specified by - ``pageSize``. Rely on ``pageToken`` to determine if there are - more items to be requested. - - After inserting, updating, or deleting a product input, it may - take several minutes before the updated processed product can be - retrieved. - - Returns: - Callable[[~.ListProductsRequest], - Awaitable[~.ListProductsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_products' not in self._stubs: - self._stubs['list_products'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1beta.ProductsService/ListProducts', - request_serializer=products.ListProductsRequest.serialize, - response_deserializer=products.ListProductsResponse.deserialize, - ) - return self._stubs['list_products'] - - def _prep_wrapped_messages(self, client_info): - """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" - self._wrapped_methods = { - self.get_product: self._wrap_method( - self.get_product, - default_timeout=None, - client_info=client_info, - ), - self.list_products: self._wrap_method( - self.list_products, - default_timeout=None, - client_info=client_info, - ), - } - - def _wrap_method(self, func, *args, **kwargs): - if self._wrap_with_kind: # pragma: NO COVER - kwargs["kind"] = self.kind - return gapic_v1.method_async.wrap_method(func, *args, **kwargs) - - def close(self): - return self._logged_channel.close() - - @property - def kind(self) -> str: - return "grpc_asyncio" - - -__all__ = ( - 'ProductsServiceGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py deleted file mode 100644 index ec18bf51f534..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest.py +++ /dev/null @@ -1,542 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import logging -import json # type: ignore - -from google.auth.transport.requests import AuthorizedSession # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.api_core import exceptions as core_exceptions -from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import gapic_v1 -import google.protobuf - -from google.protobuf import json_format - -from requests import __version__ as requests_version -import dataclasses -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - - -from google.shopping.merchant_products_v1beta.types import products - - -from .rest_base import _BaseProductsServiceRestTransport -from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object, None] # type: ignore - -try: - from google.api_core import client_logging # type: ignore - CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER -except ImportError: # pragma: NO COVER - CLIENT_LOGGING_SUPPORTED = False - -_LOGGER = logging.getLogger(__name__) - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, - grpc_version=None, - rest_version=f"requests@{requests_version}", -) - -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER - DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ - - -class ProductsServiceRestInterceptor: - """Interceptor for ProductsService. - - Interceptors are used to manipulate requests, request metadata, and responses - in arbitrary ways. - Example use cases include: - * Logging - * Verifying requests according to service or custom semantics - * Stripping extraneous information from responses - - These use cases and more can be enabled by injecting an - instance of a custom subclass when constructing the ProductsServiceRestTransport. - - .. code-block:: python - class MyCustomProductsServiceInterceptor(ProductsServiceRestInterceptor): - def pre_get_product(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_product(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_products(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_products(self, response): - logging.log(f"Received response: {response}") - return response - - transport = ProductsServiceRestTransport(interceptor=MyCustomProductsServiceInterceptor()) - client = ProductsServiceClient(transport=transport) - - - """ - def pre_get_product(self, request: products.GetProductRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.GetProductRequest, Sequence[Tuple[str, Union[str, bytes]]]]: - """Pre-rpc interceptor for get_product - - Override in a subclass to manipulate the request or metadata - before they are sent to the ProductsService server. - """ - return request, metadata - - def post_get_product(self, response: products.Product) -> products.Product: - """Post-rpc interceptor for get_product - - DEPRECATED. Please use the `post_get_product_with_metadata` - interceptor instead. - - Override in a subclass to read or manipulate the response - after it is returned by the ProductsService server but before - it is returned to user code. This `post_get_product` interceptor runs - before the `post_get_product_with_metadata` interceptor. - """ - return response - - def post_get_product_with_metadata(self, response: products.Product, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.Product, Sequence[Tuple[str, Union[str, bytes]]]]: - """Post-rpc interceptor for get_product - - Override in a subclass to read or manipulate the response or metadata after it - is returned by the ProductsService server but before it is returned to user code. - - We recommend only using this `post_get_product_with_metadata` - interceptor in new development instead of the `post_get_product` interceptor. - When both interceptors are used, this `post_get_product_with_metadata` interceptor runs after the - `post_get_product` interceptor. The (possibly modified) response returned by - `post_get_product` will be passed to - `post_get_product_with_metadata`. - """ - return response, metadata - - def pre_list_products(self, request: products.ListProductsRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: - """Pre-rpc interceptor for list_products - - Override in a subclass to manipulate the request or metadata - before they are sent to the ProductsService server. - """ - return request, metadata - - def post_list_products(self, response: products.ListProductsResponse) -> products.ListProductsResponse: - """Post-rpc interceptor for list_products - - DEPRECATED. Please use the `post_list_products_with_metadata` - interceptor instead. - - Override in a subclass to read or manipulate the response - after it is returned by the ProductsService server but before - it is returned to user code. This `post_list_products` interceptor runs - before the `post_list_products_with_metadata` interceptor. - """ - return response - - def post_list_products_with_metadata(self, response: products.ListProductsResponse, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsResponse, Sequence[Tuple[str, Union[str, bytes]]]]: - """Post-rpc interceptor for list_products - - Override in a subclass to read or manipulate the response or metadata after it - is returned by the ProductsService server but before it is returned to user code. - - We recommend only using this `post_list_products_with_metadata` - interceptor in new development instead of the `post_list_products` interceptor. - When both interceptors are used, this `post_list_products_with_metadata` interceptor runs after the - `post_list_products` interceptor. The (possibly modified) response returned by - `post_list_products` will be passed to - `post_list_products_with_metadata`. - """ - return response, metadata - - -@dataclasses.dataclass -class ProductsServiceRestStub: - _session: AuthorizedSession - _host: str - _interceptor: ProductsServiceRestInterceptor - - -class ProductsServiceRestTransport(_BaseProductsServiceRestTransport): - """REST backend synchronous transport for ProductsService. - - Service to use Product resource. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - """ - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[ProductsServiceRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client - certificate to configure mutual TLS HTTP channel. It is ignored - if ``channel`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. - # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the - # credentials object - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - url_scheme=url_scheme, - api_audience=api_audience - ) - self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) - if client_cert_source_for_mtls: - self._session.configure_mtls_channel(client_cert_source_for_mtls) - self._interceptor = interceptor or ProductsServiceRestInterceptor() - self._prep_wrapped_messages(client_info) - - class _GetProduct(_BaseProductsServiceRestTransport._BaseGetProduct, ProductsServiceRestStub): - def __hash__(self): - return hash("ProductsServiceRestTransport.GetProduct") - - @staticmethod - def _get_response( - host, - metadata, - query_params, - session, - timeout, - transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(session, method)( - "{host}{uri}".format(host=host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - return response - - def __call__(self, - request: products.GetProductRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> products.Product: - r"""Call the get product method over HTTP. - - Args: - request (~.products.GetProductRequest): - The request object. Request message for the GetProduct - method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - ~.products.Product: - The processed product, built from multiple [product - inputs][google.shopping.merchant.products.v1main.ProductInput] - after applying rules and supplemental data sources. This - processed product matches what is shown in your Merchant - Center account. Each product is built from exactly one - primary data source product input, and multiple - supplemental data source inputs. After inserting, - updating, or deleting a product input, it may take - several minutes before the updated processed product can - be retrieved. - - All fields in the processed product and its sub-messages - match the name of their corresponding attribute in the - `Product data - specification `__ - with some exceptions. - - """ - - http_options = _BaseProductsServiceRestTransport._BaseGetProduct._get_http_options() - - request, metadata = self._interceptor.pre_get_product(request, metadata) - transcoded_request = _BaseProductsServiceRestTransport._BaseGetProduct._get_transcoded_request(http_options, request) - - # Jsonify the query params - query_params = _BaseProductsServiceRestTransport._BaseGetProduct._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] - try: - request_payload = type(request).to_json(request) - except: - request_payload = None - http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), - } - _LOGGER.debug( - f"Sending request for google.shopping.merchant.products_v1beta.ProductsServiceClient.GetProduct", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": "GetProduct", - "httpRequest": http_request, - "metadata": http_request["headers"], - }, - ) - - # Send the request - response = ProductsServiceRestTransport._GetProduct._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = products.Product() - pb_resp = products.Product.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - - resp = self._interceptor.post_get_product(resp) - response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_get_product_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - try: - response_payload = products.Product.to_json(response) - except: - response_payload = None - http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, - } - _LOGGER.debug( - "Received response for google.shopping.merchant.products_v1beta.ProductsServiceClient.get_product", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": "GetProduct", - "metadata": http_response["headers"], - "httpResponse": http_response, - }, - ) - return resp - - class _ListProducts(_BaseProductsServiceRestTransport._BaseListProducts, ProductsServiceRestStub): - def __hash__(self): - return hash("ProductsServiceRestTransport.ListProducts") - - @staticmethod - def _get_response( - host, - metadata, - query_params, - session, - timeout, - transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(session, method)( - "{host}{uri}".format(host=host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - return response - - def __call__(self, - request: products.ListProductsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> products.ListProductsResponse: - r"""Call the list products method over HTTP. - - Args: - request (~.products.ListProductsRequest): - The request object. Request message for the ListProducts - method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be - sent along with the request as metadata. Normally, each value must be of type `str`, - but for metadata keys ending with the suffix `-bin`, the corresponding values must - be of type `bytes`. - - Returns: - ~.products.ListProductsResponse: - Response message for the ListProducts - method. - - """ - - http_options = _BaseProductsServiceRestTransport._BaseListProducts._get_http_options() - - request, metadata = self._interceptor.pre_list_products(request, metadata) - transcoded_request = _BaseProductsServiceRestTransport._BaseListProducts._get_transcoded_request(http_options, request) - - # Jsonify the query params - query_params = _BaseProductsServiceRestTransport._BaseListProducts._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] - try: - request_payload = type(request).to_json(request) - except: - request_payload = None - http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), - } - _LOGGER.debug( - f"Sending request for google.shopping.merchant.products_v1beta.ProductsServiceClient.ListProducts", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": "ListProducts", - "httpRequest": http_request, - "metadata": http_request["headers"], - }, - ) - - # Send the request - response = ProductsServiceRestTransport._ListProducts._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = products.ListProductsResponse() - pb_resp = products.ListProductsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - - resp = self._interceptor.post_list_products(resp) - response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_list_products_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - try: - response_payload = products.ListProductsResponse.to_json(response) - except: - response_payload = None - http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, - } - _LOGGER.debug( - "Received response for google.shopping.merchant.products_v1beta.ProductsServiceClient.list_products", - extra = { - "serviceName": "google.shopping.merchant.products.v1beta.ProductsService", - "rpcName": "ListProducts", - "metadata": http_response["headers"], - "httpResponse": http_response, - }, - ) - return resp - - @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - products.Product]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetProduct(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - products.ListProductsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListProducts(self._session, self._host, self._interceptor) # type: ignore - - @property - def kind(self) -> str: - return "rest" - - def close(self): - self._session.close() - - -__all__=( - 'ProductsServiceRestTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py deleted file mode 100644 index 069cfe69d8b9..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/transports/rest_base.py +++ /dev/null @@ -1,165 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import json # type: ignore -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO - -import re -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union - - -from google.shopping.merchant_products_v1beta.types import products - - -class _BaseProductsServiceRestTransport(ProductsServiceTransport): - """Base REST backend transport for ProductsService. - - Note: This class is not meant to be used directly. Use its sync and - async sub-classes instead. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - """ - - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[Any] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - Args: - host (Optional[str]): - The hostname to connect to (default: 'merchantapi.googleapis.com'). - credentials (Optional[Any]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) - if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER - - url_match_items = maybe_url_match.groupdict() - - host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host - - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience - ) - - class _BaseGetProduct: - def __hash__(self): # pragma: NO COVER - return NotImplementedError("__hash__ must be implemented.") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - @staticmethod - def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/products/v1beta/{name=accounts/*/products/*}', - }, - ] - return http_options - - @staticmethod - def _get_transcoded_request(http_options, request): - pb_request = products.GetProductRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - return transcoded_request - - @staticmethod - def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductsServiceRestTransport._BaseGetProduct._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - return query_params - - class _BaseListProducts: - def __hash__(self): # pragma: NO COVER - return NotImplementedError("__hash__ must be implemented.") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - @staticmethod - def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/products/v1beta/{parent=accounts/*}/products', - }, - ] - return http_options - - @staticmethod - def _get_transcoded_request(http_options, request): - pb_request = products.ListProductsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - return transcoded_request - - @staticmethod - def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductsServiceRestTransport._BaseListProducts._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - return query_params - - -__all__=( - '_BaseProductsServiceRestTransport', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py deleted file mode 100644 index 3d7f862c5cd3..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/__init__.py +++ /dev/null @@ -1,86 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .productinputs import ( - DeleteProductInputRequest, - InsertProductInputRequest, - ProductInput, - UpdateProductInputRequest, -) -from .products import ( - GetProductRequest, - ListProductsRequest, - ListProductsResponse, - Product, -) -from .products_common import ( - Attributes, - AutomatedDiscounts, - Certification, - CloudExportAdditionalProperties, - FreeShippingThreshold, - Installment, - LoyaltyPoints, - LoyaltyProgram, - ProductDetail, - ProductDimension, - ProductStatus, - ProductStructuredDescription, - ProductStructuredTitle, - ProductSustainabilityIncentive, - ProductWeight, - Shipping, - ShippingDimension, - ShippingWeight, - SubscriptionCost, - Tax, - UnitPricingBaseMeasure, - UnitPricingMeasure, - SubscriptionPeriod, -) - -__all__ = ( - 'DeleteProductInputRequest', - 'InsertProductInputRequest', - 'ProductInput', - 'UpdateProductInputRequest', - 'GetProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'Product', - 'Attributes', - 'AutomatedDiscounts', - 'Certification', - 'CloudExportAdditionalProperties', - 'FreeShippingThreshold', - 'Installment', - 'LoyaltyPoints', - 'LoyaltyProgram', - 'ProductDetail', - 'ProductDimension', - 'ProductStatus', - 'ProductStructuredDescription', - 'ProductStructuredTitle', - 'ProductSustainabilityIncentive', - 'ProductWeight', - 'Shipping', - 'ShippingDimension', - 'ShippingWeight', - 'SubscriptionCost', - 'Tax', - 'UnitPricingBaseMeasure', - 'UnitPricingMeasure', - 'SubscriptionPeriod', -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py deleted file mode 100644 index 723010bf9c61..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/productinputs.py +++ /dev/null @@ -1,305 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import field_mask_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types - - -__protobuf__ = proto.module( - package='google.shopping.merchant.products.v1beta', - manifest={ - 'ProductInput', - 'InsertProductInputRequest', - 'UpdateProductInputRequest', - 'DeleteProductInputRequest', - }, -) - - -class ProductInput(proto.Message): - r"""This resource represents input data you submit for a product, not - the processed product that you see in Merchant Center, in Shopping - ads, or across Google surfaces. Product inputs, rules and - supplemental data source data are combined to create the processed - [Product][google.shopping.merchant.products.v1beta.Product]. For - more information, see `Manage - products `__. - - Required product input attributes to pass data validation checks are - primarily defined in the `Products Data - Specification `__. - - The following attributes are required: - [feedLabel][google.shopping.merchant.products.v1beta.Product.feed_label], - [contentLanguage][google.shopping.merchant.products.v1beta.Product.content_language] - and - [offerId][google.shopping.merchant.products.v1beta.Product.offer_id]. - - After inserting, updating, or deleting a product input, it may take - several minutes before the processed product can be retrieved. - - All fields in the product input and its sub-messages match the - English name of their corresponding attribute in the `Products Data - Specification `__ - with `some - exceptions `__. - The following reference documentation lists the field names in the - **camelCase** casing style while the Products Data Specification - lists the names in the **snake_case** casing style. - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - name (str): - Identifier. The name of the product input. Format: - ``accounts/{account}/productInputs/{productinput}`` where - the last section ``productinput`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example for - product input name is - ``accounts/123/productInputs/online~en~US~sku123`` - product (str): - Output only. The name of the processed product. Format: - ``accounts/{account}/products/{product}`` - channel (google.shopping.type.types.Channel.ChannelEnum): - Immutable. The - `channel `__ - of the product. - offer_id (str): - Required. Immutable. Your unique identifier for the product. - This is the same for the product input and processed - product. Leading and trailing whitespaces are stripped and - multiple whitespaces are replaced by a single whitespace - upon submission. See the `products data - specification `__ - for details. - content_language (str): - Required. Immutable. The two-letter `ISO - 639-1 `__ language - code for the product. - feed_label (str): - Required. Immutable. The label that lets you categorize and - identify your products. The maximum allowed characters are - 20, and the supported characters are ``A-Z``, ``0-9``, - hyphen, and underscore. The feed label must not include any - spaces. For more information, see `Using feed - labels `__. - version_number (int): - Optional. Immutable. Represents the existing version - (freshness) of the product, which can be used to preserve - the right order when multiple updates are done at the same - time. - - If set, the insertion is prevented when version number is - lower than the current version number of the existing - product. Re-insertion (for example, product refresh after 30 - days) can be performed with the current ``version_number``. - - Only supported for insertions into primary data sources. Do - not set this field for updates. Do not set this field for - insertions into supplemental data sources. - - If the operation is prevented, the aborted exception will be - thrown. - - This field is a member of `oneof`_ ``_version_number``. - attributes (google.shopping.merchant_products_v1beta.types.Attributes): - Optional. A list of product attributes. - custom_attributes (MutableSequence[google.shopping.type.types.CustomAttribute]): - Optional. A list of custom (merchant-provided) attributes. - It can also be used for submitting any attribute of the data - specification in its generic form (for example, - ``{ "name": "size type", "value": "regular" }``). This is - useful for submitting attributes not explicitly exposed by - the API. Maximum allowed number of characters for each - custom attribute is 10240 (represents sum of characters for - name and value). Maximum 2500 custom attributes can be set - per product, with total size of 102.4kB. Underscores in - custom attribute names are replaced by spaces upon - insertion. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - product: str = proto.Field( - proto.STRING, - number=2, - ) - channel: types.Channel.ChannelEnum = proto.Field( - proto.ENUM, - number=3, - enum=types.Channel.ChannelEnum, - ) - offer_id: str = proto.Field( - proto.STRING, - number=4, - ) - content_language: str = proto.Field( - proto.STRING, - number=5, - ) - feed_label: str = proto.Field( - proto.STRING, - number=6, - ) - version_number: int = proto.Field( - proto.INT64, - number=7, - optional=True, - ) - attributes: products_common.Attributes = proto.Field( - proto.MESSAGE, - number=8, - message=products_common.Attributes, - ) - custom_attributes: MutableSequence[types.CustomAttribute] = proto.RepeatedField( - proto.MESSAGE, - number=9, - message=types.CustomAttribute, - ) - - -class InsertProductInputRequest(proto.Message): - r"""Request message for the InsertProductInput method. - - Attributes: - parent (str): - Required. The account where this product will be inserted. - Format: ``accounts/{account}`` - product_input (google.shopping.merchant_products_v1beta.types.ProductInput): - Required. The product input to insert. - data_source (str): - Required. The primary or supplemental product data source - name. If the product already exists and data source provided - is different, then the product will be moved to a new data - source. For more information, see `Overview of Data sources - sub-API `__. - - Only API data sources are supported. - - Format: ``accounts/{account}/dataSources/{datasource}``. For - example, ``accounts/123456/dataSources/104628``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - product_input: 'ProductInput' = proto.Field( - proto.MESSAGE, - number=2, - message='ProductInput', - ) - data_source: str = proto.Field( - proto.STRING, - number=3, - ) - - -class UpdateProductInputRequest(proto.Message): - r"""Request message for the UpdateProductInput method. - The product (primary input) must exist for the update to - succeed. If the update is for a primary product input, the - existing primary product input must be from the same data - source. - - Attributes: - product_input (google.shopping.merchant_products_v1beta.types.ProductInput): - Required. The product input resource to - update. Information you submit will be applied - to the processed product as well. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Optional. The list of product attributes to be updated. - - If the update mask is omitted, then it is treated as implied - field mask equivalent to all fields that are populated (have - a non-empty value). - - Attributes specified in the update mask without a value - specified in the body will be deleted from the product. - - Update mask can only be specified for top level fields in - attributes and custom attributes. - - To specify the update mask for custom attributes you need to - add the ``custom_attribute.`` prefix. - - Providing special "*" value for full product replacement is - not supported. - data_source (str): - Required. The primary or supplemental product data source - where ``data_source`` name identifies the product input to - be updated. - - Only API data sources are supported. - - Format: ``accounts/{account}/dataSources/{datasource}``. For - example, ``accounts/123456/dataSources/104628``. - """ - - product_input: 'ProductInput' = proto.Field( - proto.MESSAGE, - number=1, - message='ProductInput', - ) - update_mask: field_mask_pb2.FieldMask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - data_source: str = proto.Field( - proto.STRING, - number=3, - ) - - -class DeleteProductInputRequest(proto.Message): - r"""Request message for the DeleteProductInput method. - - Attributes: - name (str): - Required. The name of the product input resource to delete. - Format: ``accounts/{account}/productInputs/{product}`` where - the last section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example for - product name is - ``accounts/123/productInputs/online~en~US~sku123``. - data_source (str): - Required. The primary or supplemental data source from which - the product input should be deleted. Format: - ``accounts/{account}/dataSources/{datasource}``. For - example, ``accounts/123456/dataSources/104628``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - data_source: str = proto.Field( - proto.STRING, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py deleted file mode 100644 index 6f066fa568f9..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products.py +++ /dev/null @@ -1,260 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types - - -__protobuf__ = proto.module( - package='google.shopping.merchant.products.v1beta', - manifest={ - 'Product', - 'GetProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - }, -) - - -class Product(proto.Message): - r"""The processed product, built from multiple [product - inputs][google.shopping.merchant.products.v1main.ProductInput] after - applying rules and supplemental data sources. This processed product - matches what is shown in your Merchant Center account. Each product - is built from exactly one primary data source product input, and - multiple supplemental data source inputs. After inserting, updating, - or deleting a product input, it may take several minutes before the - updated processed product can be retrieved. - - All fields in the processed product and its sub-messages match the - name of their corresponding attribute in the `Product data - specification `__ - with some exceptions. - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - name (str): - The name of the product. Format: - ``accounts/{account}/products/{product}`` where the last - section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example for - product name is - ``accounts/123/products/online~en~US~sku123`` - channel (google.shopping.type.types.Channel.ChannelEnum): - Output only. The - `channel `__ - of the product. - offer_id (str): - Output only. Your unique identifier for the product. This is - the same for the product input and processed product. - Leading and trailing whitespaces are stripped and multiple - whitespaces are replaced by a single whitespace upon - submission. See the `product data - specification `__ - for details. - content_language (str): - Output only. The two-letter `ISO - 639-1 `__ language - code for the product. - feed_label (str): - Output only. The feed label lets you categorize and identify - your products. The maximum allowed characters is 20 and the - supported characters are\ ``A-Z``, ``0-9``, hyphen and - underscore. The feed label must not include any spaces. For - more information, see `Using feed - labels `__ - data_source (str): - Output only. The primary data source of the - product. - version_number (int): - Output only. Represents the existing version (freshness) of - the product, which can be used to preserve the right order - when multiple updates are done at the same time. - - If set, the insertion is prevented when version number is - lower than the current version number of the existing - product. Re-insertion (for example, product refresh after 30 - days) can be performed with the current ``version_number``. - - Only supported for insertions into primary data sources. - - If the operation is prevented, the aborted exception will be - thrown. - - This field is a member of `oneof`_ ``_version_number``. - attributes (google.shopping.merchant_products_v1beta.types.Attributes): - Output only. A list of product attributes. - custom_attributes (MutableSequence[google.shopping.type.types.CustomAttribute]): - Output only. A list of custom (merchant-provided) - attributes. It can also be used to submit any attribute of - the data specification in its generic form (for example, - ``{ "name": "size type", "value": "regular" }``). This is - useful for submitting attributes not explicitly exposed by - the API, such as additional attributes used for Buy on - Google. - product_status (google.shopping.merchant_products_v1beta.types.ProductStatus): - Output only. The status of a product, data - validation issues, that is, information about a - product computed asynchronously. - automated_discounts (google.shopping.merchant_products_v1beta.types.AutomatedDiscounts): - Output only. The automated discounts - information for the product. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - channel: types.Channel.ChannelEnum = proto.Field( - proto.ENUM, - number=2, - enum=types.Channel.ChannelEnum, - ) - offer_id: str = proto.Field( - proto.STRING, - number=3, - ) - content_language: str = proto.Field( - proto.STRING, - number=4, - ) - feed_label: str = proto.Field( - proto.STRING, - number=5, - ) - data_source: str = proto.Field( - proto.STRING, - number=6, - ) - version_number: int = proto.Field( - proto.INT64, - number=7, - optional=True, - ) - attributes: products_common.Attributes = proto.Field( - proto.MESSAGE, - number=8, - message=products_common.Attributes, - ) - custom_attributes: MutableSequence[types.CustomAttribute] = proto.RepeatedField( - proto.MESSAGE, - number=9, - message=types.CustomAttribute, - ) - product_status: products_common.ProductStatus = proto.Field( - proto.MESSAGE, - number=10, - message=products_common.ProductStatus, - ) - automated_discounts: products_common.AutomatedDiscounts = proto.Field( - proto.MESSAGE, - number=12, - message=products_common.AutomatedDiscounts, - ) - - -class GetProductRequest(proto.Message): - r"""Request message for the GetProduct method. - - Attributes: - name (str): - Required. The name of the product to retrieve. Format: - ``accounts/{account}/products/{product}`` where the last - section ``product`` consists of 4 parts: - ``channel~content_language~feed_label~offer_id`` example for - product name is - ``accounts/123/products/online~en~US~sku123`` - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class ListProductsRequest(proto.Message): - r"""Request message for the ListProducts method. - - Attributes: - parent (str): - Required. The account to list processed products for. - Format: ``accounts/{account}`` - page_size (int): - The maximum number of products to return. The - service may return fewer than this value. - The maximum value is 1000; values above 1000 - will be coerced to 1000. If unspecified, the - maximum number of products will be returned. - page_token (str): - A page token, received from a previous ``ListProducts`` - call. Provide this to retrieve the subsequent page. - - When paginating, all other parameters provided to - ``ListProducts`` must match the call that provided the page - token. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - page_size: int = proto.Field( - proto.INT32, - number=2, - ) - page_token: str = proto.Field( - proto.STRING, - number=3, - ) - - -class ListProductsResponse(proto.Message): - r"""Response message for the ListProducts method. - - Attributes: - products (MutableSequence[google.shopping.merchant_products_v1beta.types.Product]): - The processed products from the specified - account. These are your processed products after - applying rules and supplemental data sources. - next_page_token (str): - A token, which can be sent as ``page_token`` to retrieve the - next page. If this field is omitted, there are no subsequent - pages. - """ - - @property - def raw_page(self): - return self - - products: MutableSequence['Product'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Product', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py deleted file mode 100644 index ceb744ff33fa..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/types/products_common.py +++ /dev/null @@ -1,2109 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore -from google.shopping.type.types import types -from google.type import interval_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.shopping.merchant.products.v1beta', - manifest={ - 'SubscriptionPeriod', - 'Attributes', - 'Tax', - 'ShippingWeight', - 'ShippingDimension', - 'UnitPricingBaseMeasure', - 'UnitPricingMeasure', - 'SubscriptionCost', - 'Installment', - 'LoyaltyPoints', - 'LoyaltyProgram', - 'Shipping', - 'FreeShippingThreshold', - 'ProductDetail', - 'Certification', - 'ProductStructuredTitle', - 'ProductStructuredDescription', - 'ProductDimension', - 'ProductWeight', - 'ProductStatus', - 'CloudExportAdditionalProperties', - 'ProductSustainabilityIncentive', - 'AutomatedDiscounts', - }, -) - - -class SubscriptionPeriod(proto.Enum): - r"""The subscription period of the product. - - Values: - SUBSCRIPTION_PERIOD_UNSPECIFIED (0): - Indicates that the subscription period is - unspecified. - MONTH (1): - Indicates that the subscription period is - month. - YEAR (2): - Indicates that the subscription period is - year. - """ - SUBSCRIPTION_PERIOD_UNSPECIFIED = 0 - MONTH = 1 - YEAR = 2 - - -class Attributes(proto.Message): - r"""Attributes. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - identifier_exists (bool): - Set this value to false when the item does - not have unique product identifiers appropriate - to its category, such as GTIN, MPN, and brand. - Defaults to true, if not provided. - - This field is a member of `oneof`_ ``_identifier_exists``. - is_bundle (bool): - Whether the item is a business-defined sub-API. A [sub-API] - (https://support.google.com/merchants/answer/6324449) is a - custom grouping of different products sold by a business for - a single price. - - This field is a member of `oneof`_ ``_is_bundle``. - title (str): - Title of the item. - - This field is a member of `oneof`_ ``_title``. - description (str): - Description of the item. - - This field is a member of `oneof`_ ``_description``. - link (str): - URL directly linking to your item's page on - your online store. - - This field is a member of `oneof`_ ``_link``. - mobile_link (str): - URL for the mobile-optimized version of your - item's landing page. - - This field is a member of `oneof`_ ``_mobile_link``. - canonical_link (str): - URL for the canonical version of your item's - landing page. - - This field is a member of `oneof`_ ``_canonical_link``. - image_link (str): - URL of an image of the item. - - This field is a member of `oneof`_ ``_image_link``. - additional_image_links (MutableSequence[str]): - Additional URLs of images of the item. - expiration_date (google.protobuf.timestamp_pb2.Timestamp): - Date on which the item should expire, as specified upon - insertion, in `ISO - 8601 `__ format. The - actual expiration date is exposed in ``productstatuses`` as - `googleExpirationDate `__ - and might be earlier if ``expirationDate`` is too far in the - future. - disclosure_date (google.protobuf.timestamp_pb2.Timestamp): - The date time when an offer becomes visible in search - results across Google’s YouTube surfaces, in `ISO - 8601 `__ format. See - `Disclosure - date `__ - for more information. - adult (bool): - Set to true if the item is targeted towards - adults. - - This field is a member of `oneof`_ ``_adult``. - age_group (str): - Target `age - group `__ - of the item. - - This field is a member of `oneof`_ ``_age_group``. - availability (str): - `Availability `__ - status of the item. For example, "in_stock" or - "out_of_stock". - - This field is a member of `oneof`_ ``_availability``. - availability_date (google.protobuf.timestamp_pb2.Timestamp): - The day a pre-ordered product becomes available for - delivery, in `ISO - 8601 `__ format. - brand (str): - `Brand `__ - of the item. For example, "Google". - - This field is a member of `oneof`_ ``_brand``. - color (str): - `Color `__ - of the item. For example, "red". - - This field is a member of `oneof`_ ``_color``. - condition (str): - `Condition `__ - or state of the item. For example, "new" or "used". - - This field is a member of `oneof`_ ``_condition``. - gender (str): - Target - `gender `__ - of the item. For example, "male" or "female". - - This field is a member of `oneof`_ ``_gender``. - google_product_category (str): - Google's category of the item (see `Google product - taxonomy `__). - When querying products, this field will contain the user - provided value. There is currently no way to get back the - auto assigned google product categories through the API. - - This field is a member of `oneof`_ ``_google_product_category``. - gtin (MutableSequence[str]): - Global Trade Item Numbers - (`GTIN `__) - of the item. You can provide up to 10 GTINs. - - Deprecated: Use ``gtins`` instead. - gtins (MutableSequence[str]): - Global Trade Item Numbers - (`GTIN `__) - of the item. You can provide up to 10 GTINs. - item_group_id (str): - Shared identifier for all variants of the - same product. - - This field is a member of `oneof`_ ``_item_group_id``. - material (str): - The - `material `__ - of which the item is made. For example, "Leather" or - "Cotton". - - This field is a member of `oneof`_ ``_material``. - mpn (str): - Manufacturer Part Number - (`MPN `__) - of the item. - - This field is a member of `oneof`_ ``_mpn``. - pattern (str): - The item's - `pattern `__. - For example, polka dots. - - This field is a member of `oneof`_ ``_pattern``. - price (google.shopping.type.types.Price): - Price of the item. - maximum_retail_price (google.shopping.type.types.Price): - Maximum retail price (MRP) of the item. - Applicable to India only. - installment (google.shopping.merchant_products_v1beta.types.Installment): - Number and amount of installments to pay for - an item. - subscription_cost (google.shopping.merchant_products_v1beta.types.SubscriptionCost): - Number of periods (months or years) and - amount of payment per period for an item with an - associated subscription contract. - loyalty_points (google.shopping.merchant_products_v1beta.types.LoyaltyPoints): - Loyalty points that users receive after - purchasing the item. Japan only. - loyalty_programs (MutableSequence[google.shopping.merchant_products_v1beta.types.LoyaltyProgram]): - A list of loyalty program information that is - used to surface loyalty benefits (for example, - better pricing, points, etc) to the user of this - item. - product_types (MutableSequence[str]): - Categories of the item (formatted as in `product data - specification `__). - sale_price (google.shopping.type.types.Price): - Advertised sale price of the item. - sale_price_effective_date (google.type.interval_pb2.Interval): - Date range during which the item is on sale, see `product - data - specification `__. - sell_on_google_quantity (int): - The quantity of the product that is available - for selling on Google. Supported only for online - products. - - This field is a member of `oneof`_ ``_sell_on_google_quantity``. - product_height (google.shopping.merchant_products_v1beta.types.ProductDimension): - The height of the product in the units - provided. The value must be between - 0 (exclusive) and 3000 (inclusive). - product_length (google.shopping.merchant_products_v1beta.types.ProductDimension): - The length of the product in the units - provided. The value must be between 0 - (exclusive) and 3000 (inclusive). - product_width (google.shopping.merchant_products_v1beta.types.ProductDimension): - The width of the product in the units - provided. The value must be between 0 - (exclusive) and 3000 (inclusive). - product_weight (google.shopping.merchant_products_v1beta.types.ProductWeight): - The weight of the product in the units - provided. The value must be between 0 - (exclusive) and 2000 (inclusive). - shipping (MutableSequence[google.shopping.merchant_products_v1beta.types.Shipping]): - Shipping rules. - free_shipping_threshold (MutableSequence[google.shopping.merchant_products_v1beta.types.FreeShippingThreshold]): - Conditions to be met for a product to have - free shipping. - shipping_weight (google.shopping.merchant_products_v1beta.types.ShippingWeight): - Weight of the item for shipping. - shipping_length (google.shopping.merchant_products_v1beta.types.ShippingDimension): - Length of the item for shipping. - shipping_width (google.shopping.merchant_products_v1beta.types.ShippingDimension): - Width of the item for shipping. - shipping_height (google.shopping.merchant_products_v1beta.types.ShippingDimension): - Height of the item for shipping. - max_handling_time (int): - Maximal product handling time (in business - days). - - This field is a member of `oneof`_ ``_max_handling_time``. - min_handling_time (int): - Minimal product handling time (in business - days). - - This field is a member of `oneof`_ ``_min_handling_time``. - shipping_label (str): - The shipping label of the product, used to - group product in account-level shipping rules. - - This field is a member of `oneof`_ ``_shipping_label``. - transit_time_label (str): - The transit time label of the product, used - to group product in account-level transit time - tables. - - This field is a member of `oneof`_ ``_transit_time_label``. - size (str): - Size of the item. Only one value is allowed. For variants - with different sizes, insert a separate product for each - size with the same ``itemGroupId`` value, see - `Size `__. - - This field is a member of `oneof`_ ``_size``. - size_system (str): - System in which the size is specified. Recommended for - apparel items. For example, "US", "UK", "DE". For more - information, see `Size - system `__. - - This field is a member of `oneof`_ ``_size_system``. - size_types (MutableSequence[str]): - The cut of the item. It can be used to represent combined - size types for apparel items. Maximum two of size types can - be provided, see `Size - type `__. - For example, "petite", "plus size". - taxes (MutableSequence[google.shopping.merchant_products_v1beta.types.Tax]): - Tax information. - tax_category (str): - The `tax - category `__ - of the product. - - This field is a member of `oneof`_ ``_tax_category``. - energy_efficiency_class (str): - The energy efficiency class as defined in EU - directive 2010/30/EU. - - This field is a member of `oneof`_ ``_energy_efficiency_class``. - min_energy_efficiency_class (str): - The energy efficiency class as defined in EU - directive 2010/30/EU. - - This field is a member of `oneof`_ ``_min_energy_efficiency_class``. - max_energy_efficiency_class (str): - The energy efficiency class as defined in EU - directive 2010/30/EU. - - This field is a member of `oneof`_ ``_max_energy_efficiency_class``. - unit_pricing_measure (google.shopping.merchant_products_v1beta.types.UnitPricingMeasure): - The measure and dimension of an item. - unit_pricing_base_measure (google.shopping.merchant_products_v1beta.types.UnitPricingBaseMeasure): - The preference of the denominator of the unit - price. - multipack (int): - The number of identical products in a - business-defined multipack. - - This field is a member of `oneof`_ ``_multipack``. - ads_grouping (str): - Used to group items in an arbitrary way. Only for CPA%, - discouraged otherwise. For more information, see `Display - ads - attribute `__. - - This field is a member of `oneof`_ ``_ads_grouping``. - ads_labels (MutableSequence[str]): - Similar to ads_grouping, but only works on CPC. - ads_redirect (str): - Allows advertisers to override the item URL - when the product is shown within the context of - Product ads. - - This field is a member of `oneof`_ ``_ads_redirect``. - cost_of_goods_sold (google.shopping.type.types.Price): - Cost of goods sold. Used for gross profit - reporting. - product_details (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductDetail]): - Technical specification or additional product - details. - product_highlights (MutableSequence[str]): - Bullet points describing the most relevant `product - highlights `__. - display_ads_id (str): - An identifier for an item for dynamic - remarketing campaigns. - - This field is a member of `oneof`_ ``_display_ads_id``. - display_ads_similar_ids (MutableSequence[str]): - Advertiser-specified recommendations. For more information, - see `Display ads attribute - specification `__. - display_ads_title (str): - Title of an item for dynamic remarketing - campaigns. - - This field is a member of `oneof`_ ``_display_ads_title``. - display_ads_link (str): - URL directly to your item's landing page for - dynamic remarketing campaigns. - - This field is a member of `oneof`_ ``_display_ads_link``. - display_ads_value (float): - Offer margin for dynamic remarketing campaigns. For more - information, see `Display ads - attribute `__. - - This field is a member of `oneof`_ ``_display_ads_value``. - promotion_ids (MutableSequence[str]): - The unique ID of a promotion. - pickup_method (str): - The - `pickup `__ - option for the item. - - This field is a member of `oneof`_ ``_pickup_method``. - pickup_sla (str): - Item store pickup timeline. For more information, see - `Pickup - SLA `__. - - This field is a member of `oneof`_ ``_pickup_sla``. - link_template (str): - `Link - template `__ - for business hosted local storefront. - - This field is a member of `oneof`_ ``_link_template``. - mobile_link_template (str): - `Link - template `__ - for business hosted local storefront optimized for mobile - devices. - - This field is a member of `oneof`_ ``_mobile_link_template``. - custom_label_0 (str): - `Custom label - 0 `__ - for custom grouping of items in a Shopping campaign. - - This field is a member of `oneof`_ ``_custom_label_0``. - custom_label_1 (str): - `Custom label - 1 `__ - for custom grouping of items in a Shopping campaign. - - This field is a member of `oneof`_ ``_custom_label_1``. - custom_label_2 (str): - `Custom label - 2 `__ - for custom grouping of items in a Shopping campaign. - - This field is a member of `oneof`_ ``_custom_label_2``. - custom_label_3 (str): - `Custom label - 3 `__ - for custom grouping of items in a Shopping campaign. - - This field is a member of `oneof`_ ``_custom_label_3``. - custom_label_4 (str): - `Custom label - 4 `__ - for custom grouping of items in a Shopping campaign. - - This field is a member of `oneof`_ ``_custom_label_4``. - included_destinations (MutableSequence[str]): - The list of destinations to include for this target - (corresponds to checked check boxes in Merchant Center). - Default destinations are always included unless provided in - ``excludedDestinations``. - - For more information, see `Included - destination `__. - - Note: We recommend setting destinations on datasources level - for most use cases. Use this field within products to only - setup exceptions. - excluded_destinations (MutableSequence[str]): - The list of destinations to exclude for this target - (corresponds to unchecked check boxes in Merchant Center). - - For more information, see `Excluded - destination `__. - - Note: We recommend setting destinations on datasources level - for most use cases. Use this field within products to only - setup exceptions. - shopping_ads_excluded_countries (MutableSequence[str]): - List of country codes `(ISO 3166-1 - alpha-2) `__ - to exclude the offer from Shopping Ads destination. - Countries from this list are removed from countries - configured in data source settings. - external_seller_id (str): - Required for multi-seller accounts. Use this - attribute if you're a marketplace uploading - products for various sellers to your - multi-seller account. - - This field is a member of `oneof`_ ``_external_seller_id``. - pause (str): - Publication of this item will be temporarily - `paused `__. - - This field is a member of `oneof`_ ``_pause``. - lifestyle_image_links (MutableSequence[str]): - Additional URLs of lifestyle images of the item, used to - explicitly identify images that showcase your item in a - real-world context. See the `Help Center - article `__ - for more information. - cloud_export_additional_properties (MutableSequence[google.shopping.merchant_products_v1beta.types.CloudExportAdditionalProperties]): - Extra fields to export to the Cloud Retail - program. - virtual_model_link (str): - URL of the 3D image of the item. See the `Help Center - article `__ - for more information. - - This field is a member of `oneof`_ ``_virtual_model_link``. - certifications (MutableSequence[google.shopping.merchant_products_v1beta.types.Certification]): - Product Certifications, for example for energy efficiency - labeling of products recorded in the `EU - EPREL `__ database. - See the `Help - Center `__ - article for more information. - structured_title (google.shopping.merchant_products_v1beta.types.ProductStructuredTitle): - Structured title, for algorithmically - (AI)-generated titles. - - This field is a member of `oneof`_ ``_structured_title``. - structured_description (google.shopping.merchant_products_v1beta.types.ProductStructuredDescription): - Structured description, for algorithmically - (AI)-generated descriptions. - - This field is a member of `oneof`_ ``_structured_description``. - auto_pricing_min_price (google.shopping.type.types.Price): - A safeguard in the [automated discounts] - (https://support.google.com/merchants/answer/10295759) and - "Dynamic Promotions" - (https://support.google.com/merchants/answer/13949249) - projects, ensuring that discounts on business offers do not - fall below this value, thereby preserving the offer's value - and profitability. - sustainability_incentives (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductSustainabilityIncentive]): - The list of sustainability incentive - programs. - """ - - identifier_exists: bool = proto.Field( - proto.BOOL, - number=4, - optional=True, - ) - is_bundle: bool = proto.Field( - proto.BOOL, - number=5, - optional=True, - ) - title: str = proto.Field( - proto.STRING, - number=6, - optional=True, - ) - description: str = proto.Field( - proto.STRING, - number=7, - optional=True, - ) - link: str = proto.Field( - proto.STRING, - number=8, - optional=True, - ) - mobile_link: str = proto.Field( - proto.STRING, - number=9, - optional=True, - ) - canonical_link: str = proto.Field( - proto.STRING, - number=10, - optional=True, - ) - image_link: str = proto.Field( - proto.STRING, - number=11, - optional=True, - ) - additional_image_links: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=12, - ) - expiration_date: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=16, - message=timestamp_pb2.Timestamp, - ) - disclosure_date: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=79, - message=timestamp_pb2.Timestamp, - ) - adult: bool = proto.Field( - proto.BOOL, - number=17, - optional=True, - ) - age_group: str = proto.Field( - proto.STRING, - number=18, - optional=True, - ) - availability: str = proto.Field( - proto.STRING, - number=19, - optional=True, - ) - availability_date: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=20, - message=timestamp_pb2.Timestamp, - ) - brand: str = proto.Field( - proto.STRING, - number=21, - optional=True, - ) - color: str = proto.Field( - proto.STRING, - number=22, - optional=True, - ) - condition: str = proto.Field( - proto.STRING, - number=23, - optional=True, - ) - gender: str = proto.Field( - proto.STRING, - number=24, - optional=True, - ) - google_product_category: str = proto.Field( - proto.STRING, - number=25, - optional=True, - ) - gtin: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=26, - ) - gtins: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=140, - ) - item_group_id: str = proto.Field( - proto.STRING, - number=27, - optional=True, - ) - material: str = proto.Field( - proto.STRING, - number=28, - optional=True, - ) - mpn: str = proto.Field( - proto.STRING, - number=29, - optional=True, - ) - pattern: str = proto.Field( - proto.STRING, - number=30, - optional=True, - ) - price: types.Price = proto.Field( - proto.MESSAGE, - number=31, - message=types.Price, - ) - maximum_retail_price: types.Price = proto.Field( - proto.MESSAGE, - number=139, - message=types.Price, - ) - installment: 'Installment' = proto.Field( - proto.MESSAGE, - number=32, - message='Installment', - ) - subscription_cost: 'SubscriptionCost' = proto.Field( - proto.MESSAGE, - number=33, - message='SubscriptionCost', - ) - loyalty_points: 'LoyaltyPoints' = proto.Field( - proto.MESSAGE, - number=34, - message='LoyaltyPoints', - ) - loyalty_programs: MutableSequence['LoyaltyProgram'] = proto.RepeatedField( - proto.MESSAGE, - number=136, - message='LoyaltyProgram', - ) - product_types: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=35, - ) - sale_price: types.Price = proto.Field( - proto.MESSAGE, - number=36, - message=types.Price, - ) - sale_price_effective_date: interval_pb2.Interval = proto.Field( - proto.MESSAGE, - number=37, - message=interval_pb2.Interval, - ) - sell_on_google_quantity: int = proto.Field( - proto.INT64, - number=38, - optional=True, - ) - product_height: 'ProductDimension' = proto.Field( - proto.MESSAGE, - number=119, - message='ProductDimension', - ) - product_length: 'ProductDimension' = proto.Field( - proto.MESSAGE, - number=120, - message='ProductDimension', - ) - product_width: 'ProductDimension' = proto.Field( - proto.MESSAGE, - number=121, - message='ProductDimension', - ) - product_weight: 'ProductWeight' = proto.Field( - proto.MESSAGE, - number=122, - message='ProductWeight', - ) - shipping: MutableSequence['Shipping'] = proto.RepeatedField( - proto.MESSAGE, - number=39, - message='Shipping', - ) - free_shipping_threshold: MutableSequence['FreeShippingThreshold'] = proto.RepeatedField( - proto.MESSAGE, - number=135, - message='FreeShippingThreshold', - ) - shipping_weight: 'ShippingWeight' = proto.Field( - proto.MESSAGE, - number=40, - message='ShippingWeight', - ) - shipping_length: 'ShippingDimension' = proto.Field( - proto.MESSAGE, - number=41, - message='ShippingDimension', - ) - shipping_width: 'ShippingDimension' = proto.Field( - proto.MESSAGE, - number=42, - message='ShippingDimension', - ) - shipping_height: 'ShippingDimension' = proto.Field( - proto.MESSAGE, - number=43, - message='ShippingDimension', - ) - max_handling_time: int = proto.Field( - proto.INT64, - number=44, - optional=True, - ) - min_handling_time: int = proto.Field( - proto.INT64, - number=45, - optional=True, - ) - shipping_label: str = proto.Field( - proto.STRING, - number=46, - optional=True, - ) - transit_time_label: str = proto.Field( - proto.STRING, - number=47, - optional=True, - ) - size: str = proto.Field( - proto.STRING, - number=48, - optional=True, - ) - size_system: str = proto.Field( - proto.STRING, - number=49, - optional=True, - ) - size_types: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=50, - ) - taxes: MutableSequence['Tax'] = proto.RepeatedField( - proto.MESSAGE, - number=51, - message='Tax', - ) - tax_category: str = proto.Field( - proto.STRING, - number=52, - optional=True, - ) - energy_efficiency_class: str = proto.Field( - proto.STRING, - number=53, - optional=True, - ) - min_energy_efficiency_class: str = proto.Field( - proto.STRING, - number=54, - optional=True, - ) - max_energy_efficiency_class: str = proto.Field( - proto.STRING, - number=55, - optional=True, - ) - unit_pricing_measure: 'UnitPricingMeasure' = proto.Field( - proto.MESSAGE, - number=56, - message='UnitPricingMeasure', - ) - unit_pricing_base_measure: 'UnitPricingBaseMeasure' = proto.Field( - proto.MESSAGE, - number=57, - message='UnitPricingBaseMeasure', - ) - multipack: int = proto.Field( - proto.INT64, - number=58, - optional=True, - ) - ads_grouping: str = proto.Field( - proto.STRING, - number=59, - optional=True, - ) - ads_labels: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=60, - ) - ads_redirect: str = proto.Field( - proto.STRING, - number=61, - optional=True, - ) - cost_of_goods_sold: types.Price = proto.Field( - proto.MESSAGE, - number=62, - message=types.Price, - ) - product_details: MutableSequence['ProductDetail'] = proto.RepeatedField( - proto.MESSAGE, - number=63, - message='ProductDetail', - ) - product_highlights: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=64, - ) - display_ads_id: str = proto.Field( - proto.STRING, - number=65, - optional=True, - ) - display_ads_similar_ids: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=66, - ) - display_ads_title: str = proto.Field( - proto.STRING, - number=67, - optional=True, - ) - display_ads_link: str = proto.Field( - proto.STRING, - number=68, - optional=True, - ) - display_ads_value: float = proto.Field( - proto.DOUBLE, - number=69, - optional=True, - ) - promotion_ids: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=70, - ) - pickup_method: str = proto.Field( - proto.STRING, - number=80, - optional=True, - ) - pickup_sla: str = proto.Field( - proto.STRING, - number=81, - optional=True, - ) - link_template: str = proto.Field( - proto.STRING, - number=82, - optional=True, - ) - mobile_link_template: str = proto.Field( - proto.STRING, - number=83, - optional=True, - ) - custom_label_0: str = proto.Field( - proto.STRING, - number=71, - optional=True, - ) - custom_label_1: str = proto.Field( - proto.STRING, - number=72, - optional=True, - ) - custom_label_2: str = proto.Field( - proto.STRING, - number=73, - optional=True, - ) - custom_label_3: str = proto.Field( - proto.STRING, - number=74, - optional=True, - ) - custom_label_4: str = proto.Field( - proto.STRING, - number=75, - optional=True, - ) - included_destinations: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=76, - ) - excluded_destinations: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=77, - ) - shopping_ads_excluded_countries: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=78, - ) - external_seller_id: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - pause: str = proto.Field( - proto.STRING, - number=13, - optional=True, - ) - lifestyle_image_links: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=14, - ) - cloud_export_additional_properties: MutableSequence['CloudExportAdditionalProperties'] = proto.RepeatedField( - proto.MESSAGE, - number=84, - message='CloudExportAdditionalProperties', - ) - virtual_model_link: str = proto.Field( - proto.STRING, - number=130, - optional=True, - ) - certifications: MutableSequence['Certification'] = proto.RepeatedField( - proto.MESSAGE, - number=123, - message='Certification', - ) - structured_title: 'ProductStructuredTitle' = proto.Field( - proto.MESSAGE, - number=132, - optional=True, - message='ProductStructuredTitle', - ) - structured_description: 'ProductStructuredDescription' = proto.Field( - proto.MESSAGE, - number=133, - optional=True, - message='ProductStructuredDescription', - ) - auto_pricing_min_price: types.Price = proto.Field( - proto.MESSAGE, - number=124, - message=types.Price, - ) - sustainability_incentives: MutableSequence['ProductSustainabilityIncentive'] = proto.RepeatedField( - proto.MESSAGE, - number=138, - message='ProductSustainabilityIncentive', - ) - - -class Tax(proto.Message): - r"""The Tax of the product. - - Attributes: - rate (float): - The percentage of tax rate that applies to - the item price. - country (str): - The country within which the item is taxed, specified as a - `CLDR territory - code `__. - region (str): - The geographic region to which the tax rate - applies. - tax_ship (bool): - Set to true if tax is charged on shipping. - location_id (int): - The numeric ID of a location that the tax rate applies to as - defined in the `AdWords - API `__. - postal_code (str): - The postal code range that the tax rate applies to, - represented by a ZIP code, a ZIP code prefix using \* - wildcard, a range between two ZIP codes or two ZIP code - prefixes of equal length. Examples: 94114, 94*, 94002-95460, - 94*-95*. - """ - - rate: float = proto.Field( - proto.DOUBLE, - number=1, - ) - country: str = proto.Field( - proto.STRING, - number=2, - ) - region: str = proto.Field( - proto.STRING, - number=3, - ) - tax_ship: bool = proto.Field( - proto.BOOL, - number=4, - ) - location_id: int = proto.Field( - proto.INT64, - number=5, - ) - postal_code: str = proto.Field( - proto.STRING, - number=6, - ) - - -class ShippingWeight(proto.Message): - r"""The ShippingWeight of the product. - - Attributes: - value (float): - The weight of the product used to calculate - the shipping cost of the item. - unit (str): - The unit of value. - """ - - value: float = proto.Field( - proto.DOUBLE, - number=1, - ) - unit: str = proto.Field( - proto.STRING, - number=2, - ) - - -class ShippingDimension(proto.Message): - r"""The ShippingDimension of the product. - - Attributes: - value (float): - The dimension of the product used to - calculate the shipping cost of the item. - unit (str): - The unit of value. - """ - - value: float = proto.Field( - proto.DOUBLE, - number=1, - ) - unit: str = proto.Field( - proto.STRING, - number=2, - ) - - -class UnitPricingBaseMeasure(proto.Message): - r"""The UnitPricingBaseMeasure of the product. - - Attributes: - value (int): - The denominator of the unit price. - unit (str): - The unit of the denominator. - """ - - value: int = proto.Field( - proto.INT64, - number=1, - ) - unit: str = proto.Field( - proto.STRING, - number=2, - ) - - -class UnitPricingMeasure(proto.Message): - r"""The UnitPricingMeasure of the product. - - Attributes: - value (float): - The measure of an item. - unit (str): - The unit of the measure. - """ - - value: float = proto.Field( - proto.DOUBLE, - number=1, - ) - unit: str = proto.Field( - proto.STRING, - number=2, - ) - - -class SubscriptionCost(proto.Message): - r"""The SubscriptionCost of the product. - - Attributes: - period (google.shopping.merchant_products_v1beta.types.SubscriptionPeriod): - The type of subscription period. Supported values are: - - - "``month``" - - "``year``". - period_length (int): - The number of subscription periods the buyer - has to pay. - amount (google.shopping.type.types.Price): - The amount the buyer has to pay per - subscription period. - """ - - period: 'SubscriptionPeriod' = proto.Field( - proto.ENUM, - number=1, - enum='SubscriptionPeriod', - ) - period_length: int = proto.Field( - proto.INT64, - number=2, - ) - amount: types.Price = proto.Field( - proto.MESSAGE, - number=3, - message=types.Price, - ) - - -class Installment(proto.Message): - r"""A message that represents installment. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - months (int): - The number of installments the buyer has to - pay. - amount (google.shopping.type.types.Price): - The amount the buyer has to pay per month. - downpayment (google.shopping.type.types.Price): - The up-front down payment amount the buyer - has to pay. - - This field is a member of `oneof`_ ``_downpayment``. - credit_type (str): - Type of installment payments. Supported values are: - - - "``finance``" - - "``lease``". - - This field is a member of `oneof`_ ``_credit_type``. - """ - - months: int = proto.Field( - proto.INT64, - number=1, - ) - amount: types.Price = proto.Field( - proto.MESSAGE, - number=2, - message=types.Price, - ) - downpayment: types.Price = proto.Field( - proto.MESSAGE, - number=3, - optional=True, - message=types.Price, - ) - credit_type: str = proto.Field( - proto.STRING, - number=4, - optional=True, - ) - - -class LoyaltyPoints(proto.Message): - r"""A message that represents loyalty points. - - Attributes: - name (str): - Name of loyalty points program. It is - recommended to limit the name to 12 full-width - characters or 24 Roman characters. - points_value (int): - The retailer's loyalty points in absolute - value. - ratio (float): - The ratio of a point when converted to - currency. Google assumes currency based on - Merchant Center settings. If ratio is left out, - it defaults to 1.0. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - points_value: int = proto.Field( - proto.INT64, - number=2, - ) - ratio: float = proto.Field( - proto.DOUBLE, - number=3, - ) - - -class LoyaltyProgram(proto.Message): - r"""A message that represents loyalty program. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - program_label (str): - The label of the loyalty program. This is an - internal label that uniquely identifies the - relationship between a business entity and a - loyalty program entity. The label must be - provided so that the system can associate the - assets below (for example, price and points) - with a business. The corresponding program must - be linked to the Merchant Center account. - - This field is a member of `oneof`_ ``_program_label``. - tier_label (str): - The label of the tier within the loyalty - program. Must match one of the labels within the - program. - - This field is a member of `oneof`_ ``_tier_label``. - price (google.shopping.type.types.Price): - The price for members of the given tier, that - is, the instant discount price. Must be smaller - or equal to the regular price. - - This field is a member of `oneof`_ ``_price``. - cashback_for_future_use (google.shopping.type.types.Price): - The cashback that can be used for future - purchases. - - This field is a member of `oneof`_ ``_cashback_for_future_use``. - loyalty_points (int): - The amount of loyalty points earned on a - purchase. - - This field is a member of `oneof`_ ``_loyalty_points``. - member_price_effective_date (google.type.interval_pb2.Interval): - A date range during which the item is - eligible for member price. If not specified, the - member price is always applicable. The date - range is represented by a pair of ISO 8601 dates - separated by a space, comma, or slash. - - This field is a member of `oneof`_ ``_member_price_effective_date``. - shipping_label (str): - The label of the shipping benefit. If the - field has value, this offer has loyalty shipping - benefit. If the field value isn't provided, the - item is not eligible for loyalty shipping for - the given loyalty tier. - - This field is a member of `oneof`_ ``_shipping_label``. - """ - - program_label: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - tier_label: str = proto.Field( - proto.STRING, - number=2, - optional=True, - ) - price: types.Price = proto.Field( - proto.MESSAGE, - number=3, - optional=True, - message=types.Price, - ) - cashback_for_future_use: types.Price = proto.Field( - proto.MESSAGE, - number=4, - optional=True, - message=types.Price, - ) - loyalty_points: int = proto.Field( - proto.INT64, - number=5, - optional=True, - ) - member_price_effective_date: interval_pb2.Interval = proto.Field( - proto.MESSAGE, - number=6, - optional=True, - message=interval_pb2.Interval, - ) - shipping_label: str = proto.Field( - proto.STRING, - number=7, - optional=True, - ) - - -class Shipping(proto.Message): - r"""The Shipping of the product. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - price (google.shopping.type.types.Price): - Fixed shipping price, represented as a - number. - country (str): - The `CLDR territory - code `__ - of the country to which an item will ship. - region (str): - The geographic region to which a shipping rate applies. See - `region `__ - for more information. - service (str): - A free-form description of the service class - or delivery speed. - location_id (int): - The numeric ID of a location that the shipping rate applies - to as defined in the `AdWords - API `__. - location_group_name (str): - The location where the shipping is - applicable, represented by a location group - name. - postal_code (str): - The postal code range that the shipping rate applies to, - represented by a postal code, a postal code prefix followed - by a \* wildcard, a range between two postal codes or two - postal code prefixes of equal length. - min_handling_time (int): - Minimum handling time (inclusive) between when the order is - received and shipped in business days. 0 means that the - order is shipped on the same day as it is received if it - happens before the cut-off time. - [minHandlingTime][google.shopping.merchant.products.v1beta.Shipping.min_handling_time] - can only be present together with - [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time]; - but it is not required if - [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] - is present. - - This field is a member of `oneof`_ ``_min_handling_time``. - max_handling_time (int): - Maximum handling time (inclusive) between when the order is - received and shipped in business days. 0 means that the - order is shipped on the same day as it is received if it - happens before the cut-off time. Both - [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] - and - [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] - are required if providing shipping speeds. - [minHandlingTime][google.shopping.merchant.products.v1beta.Shipping.min_handling_time] - is optional if - [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] - is present. - - This field is a member of `oneof`_ ``_max_handling_time``. - min_transit_time (int): - Minimum transit time (inclusive) between when the order has - shipped and when it is delivered in business days. 0 means - that the order is delivered on the same day as it ships. - [minTransitTime][google.shopping.merchant.products.v1beta.Shipping.min_transit_time] - can only be present together with - [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time]; - but it is not required if - [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] - is present. - - This field is a member of `oneof`_ ``_min_transit_time``. - max_transit_time (int): - Maximum transit time (inclusive) between when the order has - shipped and when it is delivered in business days. 0 means - that the order is delivered on the same day as it ships. - Both - [maxHandlingTime][google.shopping.merchant.products.v1beta.Shipping.max_handling_time] - and - [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] - are required if providing shipping speeds. - [minTransitTime][google.shopping.merchant.products.v1beta.Shipping.min_transit_time] - is optional if - [maxTransitTime][google.shopping.merchant.products.v1beta.Shipping.max_transit_time] - is present. - - This field is a member of `oneof`_ ``_max_transit_time``. - """ - - price: types.Price = proto.Field( - proto.MESSAGE, - number=1, - message=types.Price, - ) - country: str = proto.Field( - proto.STRING, - number=2, - ) - region: str = proto.Field( - proto.STRING, - number=3, - ) - service: str = proto.Field( - proto.STRING, - number=4, - ) - location_id: int = proto.Field( - proto.INT64, - number=5, - ) - location_group_name: str = proto.Field( - proto.STRING, - number=6, - ) - postal_code: str = proto.Field( - proto.STRING, - number=7, - ) - min_handling_time: int = proto.Field( - proto.INT64, - number=8, - optional=True, - ) - max_handling_time: int = proto.Field( - proto.INT64, - number=9, - optional=True, - ) - min_transit_time: int = proto.Field( - proto.INT64, - number=10, - optional=True, - ) - max_transit_time: int = proto.Field( - proto.INT64, - number=11, - optional=True, - ) - - -class FreeShippingThreshold(proto.Message): - r"""Conditions to be met for a product to have free shipping. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - country (str): - The `CLDR territory - code `__ - of the country to which an item will ship. - - This field is a member of `oneof`_ ``_country``. - price_threshold (google.shopping.type.types.Price): - The minimum product price for the shipping - cost to become free. Represented as a number. - - This field is a member of `oneof`_ ``_price_threshold``. - """ - - country: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - price_threshold: types.Price = proto.Field( - proto.MESSAGE, - number=2, - optional=True, - message=types.Price, - ) - - -class ProductDetail(proto.Message): - r"""The product details. - - Attributes: - section_name (str): - The section header used to group a set of - product details. - attribute_name (str): - The name of the product detail. - attribute_value (str): - The value of the product detail. - """ - - section_name: str = proto.Field( - proto.STRING, - number=1, - ) - attribute_name: str = proto.Field( - proto.STRING, - number=2, - ) - attribute_value: str = proto.Field( - proto.STRING, - number=3, - ) - - -class Certification(proto.Message): - r"""Product - `certification `__, - initially introduced for EU energy efficiency labeling compliance - using the EU EPREL database. - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - certification_authority (str): - The certification authority, for example - "European_Commission". Maximum length is 2000 characters. - - This field is a member of `oneof`_ ``_certification_authority``. - certification_name (str): - The name of the certification, for example - "EPREL". Maximum length is 2000 characters. - - This field is a member of `oneof`_ ``_certification_name``. - certification_code (str): - The certification code. - Maximum length is 2000 characters. - - This field is a member of `oneof`_ ``_certification_code``. - certification_value (str): - The certification value (also known as class, - level or grade), for example "A+", "C", "gold". - Maximum length is 2000 characters. - - This field is a member of `oneof`_ ``_certification_value``. - """ - - certification_authority: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - certification_name: str = proto.Field( - proto.STRING, - number=2, - optional=True, - ) - certification_code: str = proto.Field( - proto.STRING, - number=3, - optional=True, - ) - certification_value: str = proto.Field( - proto.STRING, - number=4, - optional=True, - ) - - -class ProductStructuredTitle(proto.Message): - r"""Structured title, for algorithmically (AI)-generated titles. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - digital_source_type (str): - The digital source type, for example - "trained_algorithmic_media". Following - `IPTC `__. - Maximum length is 40 characters. - - This field is a member of `oneof`_ ``_digital_source_type``. - content (str): - The title text - Maximum length is 150 characters - - This field is a member of `oneof`_ ``_content``. - """ - - digital_source_type: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - content: str = proto.Field( - proto.STRING, - number=2, - optional=True, - ) - - -class ProductStructuredDescription(proto.Message): - r"""Structured description, for algorithmically (AI)-generated - descriptions. - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - digital_source_type (str): - The digital source type, for example - "trained_algorithmic_media". Following - `IPTC `__. - Maximum length is 40 characters. - - This field is a member of `oneof`_ ``_digital_source_type``. - content (str): - The description text - Maximum length is 5000 characters - - This field is a member of `oneof`_ ``_content``. - """ - - digital_source_type: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - content: str = proto.Field( - proto.STRING, - number=2, - optional=True, - ) - - -class ProductDimension(proto.Message): - r"""The dimension of the product. - - Attributes: - value (float): - Required. The dimension value represented as - a number. The value can have a maximum precision - of four decimal places. - unit (str): - Required. The dimension units. Acceptable values are: - - - "``in``" - - "``cm``". - """ - - value: float = proto.Field( - proto.DOUBLE, - number=1, - ) - unit: str = proto.Field( - proto.STRING, - number=2, - ) - - -class ProductWeight(proto.Message): - r"""The weight of the product. - - Attributes: - value (float): - Required. The weight represented as a number. - The weight can have a maximum precision of four - decimal places. - unit (str): - Required. The weight unit. Acceptable values are: - - - "``g``" - - "``kg``" - - "``oz``" - - "``lb``". - """ - - value: float = proto.Field( - proto.DOUBLE, - number=1, - ) - unit: str = proto.Field( - proto.STRING, - number=2, - ) - - -class ProductStatus(proto.Message): - r"""The status of a product, data validation issues, that is, - information about a product computed asynchronously. - - Attributes: - destination_statuses (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductStatus.DestinationStatus]): - The intended destinations for the product. - item_level_issues (MutableSequence[google.shopping.merchant_products_v1beta.types.ProductStatus.ItemLevelIssue]): - A list of all issues associated with the - product. - creation_date (google.protobuf.timestamp_pb2.Timestamp): - Date on which the item has been created, in `ISO - 8601 `__ format. - last_update_date (google.protobuf.timestamp_pb2.Timestamp): - Date on which the item has been last updated, in `ISO - 8601 `__ format. - google_expiration_date (google.protobuf.timestamp_pb2.Timestamp): - Date on which the item expires, in `ISO - 8601 `__ format. - """ - - class DestinationStatus(proto.Message): - r"""The destination status of the product status. - - Attributes: - reporting_context (google.shopping.type.types.ReportingContext.ReportingContextEnum): - The name of the reporting context. - approved_countries (MutableSequence[str]): - List of country codes (ISO 3166-1 alpha-2) - where the offer is approved. - pending_countries (MutableSequence[str]): - List of country codes (ISO 3166-1 alpha-2) - where the offer is pending approval. - disapproved_countries (MutableSequence[str]): - List of country codes (ISO 3166-1 alpha-2) - where the offer is disapproved. - """ - - reporting_context: types.ReportingContext.ReportingContextEnum = proto.Field( - proto.ENUM, - number=1, - enum=types.ReportingContext.ReportingContextEnum, - ) - approved_countries: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=2, - ) - pending_countries: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=3, - ) - disapproved_countries: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=4, - ) - - class ItemLevelIssue(proto.Message): - r"""The ItemLevelIssue of the product status. - - Attributes: - code (str): - The error code of the issue. - severity (google.shopping.merchant_products_v1beta.types.ProductStatus.ItemLevelIssue.Severity): - How this issue affects serving of the offer. - resolution (str): - Whether the issue can be resolved by the - business. - attribute (str): - The attribute's name, if the issue is caused - by a single attribute. - reporting_context (google.shopping.type.types.ReportingContext.ReportingContextEnum): - The reporting context the issue applies to. - description (str): - A short issue description in English. - detail (str): - A detailed issue description in English. - documentation (str): - The URL of a web page to help with resolving - this issue. - applicable_countries (MutableSequence[str]): - List of country codes (ISO 3166-1 alpha-2) - where issue applies to the offer. - """ - class Severity(proto.Enum): - r"""How the issue affects the serving of the product. - - Values: - SEVERITY_UNSPECIFIED (0): - Not specified. - NOT_IMPACTED (1): - This issue represents a warning and does not - have a direct affect on the product. - DEMOTED (2): - The product is demoted and most likely have - limited performance in search results - DISAPPROVED (3): - Issue disapproves the product. - """ - SEVERITY_UNSPECIFIED = 0 - NOT_IMPACTED = 1 - DEMOTED = 2 - DISAPPROVED = 3 - - code: str = proto.Field( - proto.STRING, - number=1, - ) - severity: 'ProductStatus.ItemLevelIssue.Severity' = proto.Field( - proto.ENUM, - number=2, - enum='ProductStatus.ItemLevelIssue.Severity', - ) - resolution: str = proto.Field( - proto.STRING, - number=3, - ) - attribute: str = proto.Field( - proto.STRING, - number=4, - ) - reporting_context: types.ReportingContext.ReportingContextEnum = proto.Field( - proto.ENUM, - number=5, - enum=types.ReportingContext.ReportingContextEnum, - ) - description: str = proto.Field( - proto.STRING, - number=6, - ) - detail: str = proto.Field( - proto.STRING, - number=7, - ) - documentation: str = proto.Field( - proto.STRING, - number=8, - ) - applicable_countries: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=9, - ) - - destination_statuses: MutableSequence[DestinationStatus] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=DestinationStatus, - ) - item_level_issues: MutableSequence[ItemLevelIssue] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=ItemLevelIssue, - ) - creation_date: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp_pb2.Timestamp, - ) - last_update_date: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=6, - message=timestamp_pb2.Timestamp, - ) - google_expiration_date: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=7, - message=timestamp_pb2.Timestamp, - ) - - -class CloudExportAdditionalProperties(proto.Message): - r"""Product property for the Cloud Retail API. - For example, properties for a TV product could be - "Screen-Resolution" or "Screen-Size". - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - property_name (str): - Name of the given property. For example, - "Screen-Resolution" for a TV product. Maximum - string size is 256 characters. - - This field is a member of `oneof`_ ``_property_name``. - text_value (MutableSequence[str]): - Text value of the given property. For - example, "8K(UHD)" could be a text value for a - TV product. Maximum repeatedness of this value - is 400. Values are stored in an arbitrary but - consistent order. Maximum string size is 256 - characters. - bool_value (bool): - Boolean value of the given property. For - example for a TV product, "True" or "False" if - the screen is UHD. - - This field is a member of `oneof`_ ``_bool_value``. - int_value (MutableSequence[int]): - Integer values of the given property. For - example, 1080 for a TV product's Screen - Resolution. Maximum repeatedness of this value - is 400. Values are stored in an arbitrary but - consistent order. - float_value (MutableSequence[float]): - Float values of the given property. For - example for a TV product 1.2345. Maximum - repeatedness of this value is 400. Values are - stored in an arbitrary but consistent order. - min_value (float): - Minimum float value of the given property. - For example for a TV product 1.00. - - This field is a member of `oneof`_ ``_min_value``. - max_value (float): - Maximum float value of the given property. - For example for a TV product 100.00. - - This field is a member of `oneof`_ ``_max_value``. - unit_code (str): - Unit of the given property. For example, - "Pixels" for a TV product. Maximum string size - is 256B. - - This field is a member of `oneof`_ ``_unit_code``. - """ - - property_name: str = proto.Field( - proto.STRING, - number=1, - optional=True, - ) - text_value: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=2, - ) - bool_value: bool = proto.Field( - proto.BOOL, - number=3, - optional=True, - ) - int_value: MutableSequence[int] = proto.RepeatedField( - proto.INT64, - number=4, - ) - float_value: MutableSequence[float] = proto.RepeatedField( - proto.FLOAT, - number=5, - ) - min_value: float = proto.Field( - proto.FLOAT, - number=6, - optional=True, - ) - max_value: float = proto.Field( - proto.FLOAT, - number=7, - optional=True, - ) - unit_code: str = proto.Field( - proto.STRING, - number=8, - optional=True, - ) - - -class ProductSustainabilityIncentive(proto.Message): - r"""Information regarding sustainability-related incentive - programs such as rebates or tax relief. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - amount (google.shopping.type.types.Price): - The fixed amount of the incentive. - - This field is a member of `oneof`_ ``value``. - percentage (float): - The percentage of the sale price that the - incentive is applied to. - - This field is a member of `oneof`_ ``value``. - type_ (google.shopping.merchant_products_v1beta.types.ProductSustainabilityIncentive.Type): - Sustainability incentive program. - - This field is a member of `oneof`_ ``_type``. - """ - class Type(proto.Enum): - r"""Types of supported sustainability incentive programs. - - Values: - TYPE_UNSPECIFIED (0): - Unspecified or unknown sustainability - incentive type. - EV_TAX_CREDIT (1): - Program offering tax liability reductions for - electric vehicles and, in some countries, - plug-in hybrids. These reductions can be based - on a specific amount or a percentage of the sale - price. - EV_PRICE_DISCOUNT (2): - A subsidy program, often called an - environmental bonus, provides a purchase grant - for electric vehicles and, in some countries, - plug-in hybrids. The grant amount may be a fixed - sum or a percentage of the sale price. - """ - TYPE_UNSPECIFIED = 0 - EV_TAX_CREDIT = 1 - EV_PRICE_DISCOUNT = 2 - - amount: types.Price = proto.Field( - proto.MESSAGE, - number=2, - oneof='value', - message=types.Price, - ) - percentage: float = proto.Field( - proto.DOUBLE, - number=3, - oneof='value', - ) - type_: Type = proto.Field( - proto.ENUM, - number=1, - optional=True, - enum=Type, - ) - - -class AutomatedDiscounts(proto.Message): - r"""Information regarding Automated Discounts. - - Attributes: - prior_price (google.shopping.type.types.Price): - The price prior to the application of the - first price reduction. Absent if the information - about the prior price of the product is not - available. - prior_price_progressive (google.shopping.type.types.Price): - The price prior to the application of - consecutive price reductions. Absent if the - information about the prior price of the product - is not available. - gad_price (google.shopping.type.types.Price): - The current sale price for products with a price optimized - using Google Automated Discounts (GAD). Absent if the - information about the GAD_price of the product is not - available. - """ - - prior_price: types.Price = proto.Field( - proto.MESSAGE, - number=1, - message=types.Price, - ) - prior_price_progressive: types.Price = proto.Field( - proto.MESSAGE, - number=2, - message=types.Price, - ) - gad_price: types.Price = proto.Field( - proto.MESSAGE, - number=3, - message=types.Price, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini b/owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini deleted file mode 100644 index 574c5aed394b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.7 -namespace_packages = True diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py deleted file mode 100644 index 317670e1652b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/noxfile.py +++ /dev/null @@ -1,591 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import re -import shutil - -from typing import Dict, List -import warnings - -import nox - -BLACK_VERSION = "black[jupyter]==23.7.0" -ISORT_VERSION = "isort==5.11.0" - -LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] - -ALL_PYTHON = [ - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", - "3.12", - "3.13", -] - -DEFAULT_PYTHON_VERSION = ALL_PYTHON[-1] - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = "google-shopping-merchant-products" - -UNIT_TEST_STANDARD_DEPENDENCIES = [ - "mock", - "asyncmock", - "pytest", - "pytest-cov", - "pytest-asyncio", -] -UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] -UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] -UNIT_TEST_DEPENDENCIES: List[str] = [] -UNIT_TEST_EXTRAS: List[str] = [] -UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} - -SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] -SYSTEM_TEST_STANDARD_DEPENDENCIES = [ - "mock", - "pytest", - "google-cloud-testutils", -] -SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] -SYSTEM_TEST_LOCAL_DEPENDENCIES: List[str] = [] -SYSTEM_TEST_DEPENDENCIES: List[str] = [] -SYSTEM_TEST_EXTRAS: List[str] = [] -SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {} - -nox.options.sessions = [ - "unit", - "system", - "cover", - "lint", - "lint_setup_py", - "blacken", - "docs", -] - -# Error if a python version is missing -nox.options.error_on_missing_interpreters = True - - -@nox.session(python=ALL_PYTHON) -def mypy(session): - """Run the type checker.""" - session.install( - "mypy", - "types-requests", - "types-protobuf", - ) - session.install(".") - session.run( - "mypy", - "-p", - "google", - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install("google-cloud-testutils") - session.install(".") - - session.run( - "lower-bound-checker", - "update", - "--package-name", - PACKAGE_NAME, - "--constraints-file", - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install("google-cloud-testutils") - session.install(".") - - session.run( - "lower-bound-checker", - "check", - "--package-name", - PACKAGE_NAME, - "--constraints-file", - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *LINT_PATHS, - ) - - session.run("flake8", "google", "tests") - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *LINT_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def format(session): - """ - Run isort to sort imports. Then run black - to format code to uniform standard. - """ - session.install(BLACK_VERSION, ISORT_VERSION) - # Use the --fss option to sort imports using strict alphabetical order. - # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections - session.run( - "isort", - "--fss", - *LINT_PATHS, - ) - session.run( - "black", - *LINT_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install("setuptools", "docutils", "pygments") - session.run("python", "setup.py", "check", "--restructuredtext", "--strict") - - -def install_unittest_dependencies(session, *constraints): - standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES - session.install(*standard_deps, *constraints) - - if UNIT_TEST_EXTERNAL_DEPENDENCIES: - warnings.warn( - "'unit_test_external_dependencies' is deprecated. Instead, please " - "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", - DeprecationWarning, - ) - session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) - - if UNIT_TEST_LOCAL_DEPENDENCIES: - session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) - - if UNIT_TEST_EXTRAS_BY_PYTHON: - extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) - elif UNIT_TEST_EXTRAS: - extras = UNIT_TEST_EXTRAS - else: - extras = [] - - if extras: - session.install("-e", f".[{','.join(extras)}]", *constraints) - else: - session.install("-e", ".", *constraints) - - -@nox.session(python=ALL_PYTHON) -@nox.parametrize( - "protobuf_implementation", - ["python", "upb", "cpp"], -) -def unit(session, protobuf_implementation): - # Install all test dependencies, then install this package in-place. - - if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): - session.skip("cpp implementation is not supported in python 3.11+") - - constraints_path = str( - CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" - ) - install_unittest_dependencies(session, "-c", constraints_path) - - # TODO(https://github.com/googleapis/synthtool/issues/1976): - # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. - # The 'cpp' implementation requires Protobuf<4. - if protobuf_implementation == "cpp": - session.install("protobuf<4") - - # Run py.test against the unit tests. - session.run( - "py.test", - "--quiet", - f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google", - "--cov=tests/unit", - "--cov-append", - "--cov-config=.coveragerc", - "--cov-report=", - "--cov-fail-under=0", - os.path.join("tests", "unit"), - *session.posargs, - env={ - "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, - }, - ) - - -def install_systemtest_dependencies(session, *constraints): - session.install("--pre", "grpcio") - - session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: - session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_LOCAL_DEPENDENCIES: - session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_DEPENDENCIES: - session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) - - if SYSTEM_TEST_EXTRAS_BY_PYTHON: - extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) - elif SYSTEM_TEST_EXTRAS: - extras = SYSTEM_TEST_EXTRAS - else: - extras = [] - - if extras: - session.install("-e", f".[{','.join(extras)}]", *constraints) - else: - session.install("-e", ".", *constraints) - - -@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) -def system(session): - """Run the system test suite.""" - constraints_path = str( - CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" - ) - system_test_path = os.path.join("tests", "system.py") - system_test_folder_path = os.path.join("tests", "system") - - # Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true. - if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false": - session.skip("RUN_SYSTEM_TESTS is set to false, skipping") - # Install pyopenssl for mTLS testing. - if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": - session.install("pyopenssl") - - system_test_exists = os.path.exists(system_test_path) - system_test_folder_exists = os.path.exists(system_test_folder_path) - # Sanity check: only run tests if found. - if not system_test_exists and not system_test_folder_exists: - session.skip("System tests were not found") - - install_systemtest_dependencies(session, "-c", constraints_path) - - # Run py.test against the system tests. - if system_test_exists: - session.run( - "py.test", - "--quiet", - f"--junitxml=system_{session.python}_sponge_log.xml", - system_test_path, - *session.posargs, - ) - if system_test_folder_exists: - session.run( - "py.test", - "--quiet", - f"--junitxml=system_{session.python}_sponge_log.xml", - system_test_folder_path, - *session.posargs, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def cover(session): - """Run the final coverage report. - - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python="3.10") -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install( - # We need to pin to specific versions of the `sphinxcontrib-*` packages - # which still support sphinx 4.x. - # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 - # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. - "sphinxcontrib-applehelp==1.0.4", - "sphinxcontrib-devhelp==1.0.2", - "sphinxcontrib-htmlhelp==2.0.1", - "sphinxcontrib-qthelp==1.0.3", - "sphinxcontrib-serializinghtml==1.1.5", - "sphinx==4.5.0", - "alabaster", - "recommonmark", - ) - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python="3.10") -def docfx(session): - """Build the docfx yaml files for this library.""" - - session.install("-e", ".") - session.install( - # We need to pin to specific versions of the `sphinxcontrib-*` packages - # which still support sphinx 4.x. - # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 - # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. - "sphinxcontrib-applehelp==1.0.4", - "sphinxcontrib-devhelp==1.0.2", - "sphinxcontrib-htmlhelp==2.0.1", - "sphinxcontrib-qthelp==1.0.3", - "sphinxcontrib-serializinghtml==1.1.5", - "gcp-sphinx-docfx-yaml", - "alabaster", - "recommonmark", - ) - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-T", # show full traceback on exception - "-N", # no colors - "-D", - ( - "extensions=sphinx.ext.autodoc," - "sphinx.ext.autosummary," - "docfx_yaml.extension," - "sphinx.ext.intersphinx," - "sphinx.ext.coverage," - "sphinx.ext.napoleon," - "sphinx.ext.todo," - "sphinx.ext.viewcode," - "recommonmark" - ), - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -@nox.parametrize( - "protobuf_implementation", - ["python", "upb", "cpp"], -) -def prerelease_deps(session, protobuf_implementation): - """ - Run all tests with pre-release versions of dependencies installed - rather than the standard non pre-release versions. - Pre-release versions can be installed using - `pip install --pre `. - """ - - if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"): - session.skip("cpp implementation is not supported in python 3.11+") - - # Install all dependencies - session.install("-e", ".") - - # Install dependencies for the unit test environment - unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES - session.install(*unit_deps_all) - - # Install dependencies for the system test environment - system_deps_all = ( - SYSTEM_TEST_STANDARD_DEPENDENCIES - + SYSTEM_TEST_EXTERNAL_DEPENDENCIES - + SYSTEM_TEST_EXTRAS - ) - session.install(*system_deps_all) - - # Because we test minimum dependency versions on the minimum Python - # version, the first version we test with in the unit tests sessions has a - # constraints file containing all dependencies and extras. - with open( - CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", - encoding="utf-8", - ) as constraints_file: - constraints_text = constraints_file.read() - - # Ignore leading whitespace and comment lines. - constraints_deps = [ - match.group(1) - for match in re.finditer( - r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE - ) - ] - - # Install dependencies specified in `testing/constraints-X.txt`. - session.install(*constraints_deps) - - # Note: If a dependency is added to the `prerel_deps` list, - # the `core_dependencies_from_source` list in the `core_deps_from_source` - # nox session should also be updated. - prerel_deps = [ - "googleapis-common-protos", - "google-api-core", - "google-auth", - "grpc-google-iam-v1", - "grpcio", - "grpcio-status", - "protobuf", - "proto-plus", - ] - - for dep in prerel_deps: - session.install("--pre", "--no-deps", "--ignore-installed", dep) - # TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status`` - # to the dictionary below once this bug is fixed. - # TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add - # `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below - # once this bug is fixed. - package_namespaces = { - "google-api-core": "google.api_core", - "google-auth": "google.auth", - "grpcio": "grpc", - "protobuf": "google.protobuf", - "proto-plus": "proto", - } - - version_namespace = package_namespaces.get(dep) - - print(f"Installed {dep}") - if version_namespace: - session.run( - "python", - "-c", - f"import {version_namespace}; print({version_namespace}.__version__)", - ) - - session.run( - "py.test", - "tests/unit", - env={ - "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, - }, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -@nox.parametrize( - "protobuf_implementation", - ["python", "upb"], -) -def core_deps_from_source(session, protobuf_implementation): - """Run all tests with core dependencies installed from source - rather than pulling the dependencies from PyPI. - """ - - # Install all dependencies - session.install("-e", ".") - - # Install dependencies for the unit test environment - unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES - session.install(*unit_deps_all) - - # Install dependencies for the system test environment - system_deps_all = ( - SYSTEM_TEST_STANDARD_DEPENDENCIES - + SYSTEM_TEST_EXTERNAL_DEPENDENCIES - + SYSTEM_TEST_EXTRAS - ) - session.install(*system_deps_all) - - # Because we test minimum dependency versions on the minimum Python - # version, the first version we test with in the unit tests sessions has a - # constraints file containing all dependencies and extras. - with open( - CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", - encoding="utf-8", - ) as constraints_file: - constraints_text = constraints_file.read() - - # Ignore leading whitespace and comment lines. - constraints_deps = [ - match.group(1) - for match in re.finditer( - r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE - ) - ] - - # Install dependencies specified in `testing/constraints-X.txt`. - session.install(*constraints_deps) - - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and - # `grpcio-status` should be added to the list below so that they are installed from source, - # rather than PyPI. - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be - # added to the list below so that it is installed from source, rather than PyPI - # Note: If a dependency is added to the `core_dependencies_from_source` list, - # the `prerel_deps` list in the `prerelease_deps` nox session should also be updated. - core_dependencies_from_source = [ - "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos", - "google-api-core @ git+https://github.com/googleapis/python-api-core.git", - "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git", - "grpc-google-iam-v1 @ git+https://github.com/googleapis/google-cloud-python#egg=grpc-google-iam-v1&subdirectory=packages/grpc-google-iam-v1", - "proto-plus @ git+https://github.com/googleapis/proto-plus-python.git", - ] - - for dep in core_dependencies_from_source: - session.install(dep, "--no-deps", "--ignore-installed") - print(f"Installed {dep}") - - session.run( - "py.test", - "tests/unit", - env={ - "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, - }, - ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py deleted file mode 100644 index c15d4c99af6a..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteProductInput -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -async def sample_delete_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceAsyncClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.DeleteProductInputRequest( - name="name_value", - data_source="data_source_value", - ) - - # Make the request - await client.delete_product_input(request=request) - - -# [END merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py deleted file mode 100644 index f2b45d69798d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteProductInput -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -def sample_delete_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.DeleteProductInputRequest( - name="name_value", - data_source="data_source_value", - ) - - # Make the request - client.delete_product_input(request=request) - - -# [END merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py deleted file mode 100644 index 2e9351bac625..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for InsertProductInput -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -async def sample_insert_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceAsyncClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.InsertProductInputRequest( - parent="parent_value", - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = await client.insert_product_input(request=request) - - # Handle the response - print(response) - -# [END merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py deleted file mode 100644 index df9c682279da..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for InsertProductInput -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -def sample_insert_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.InsertProductInputRequest( - parent="parent_value", - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = client.insert_product_input(request=request) - - # Handle the response - print(response) - -# [END merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py deleted file mode 100644 index f7b557927349..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateProductInput -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -async def sample_update_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceAsyncClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.UpdateProductInputRequest( - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = await client.update_product_input(request=request) - - # Handle the response - print(response) - -# [END merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py deleted file mode 100644 index 74f753bd83a7..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateProductInput -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -def sample_update_product_input(): - # Create a client - client = merchant_products_v1beta.ProductInputsServiceClient() - - # Initialize request argument(s) - product_input = merchant_products_v1beta.ProductInput() - product_input.offer_id = "offer_id_value" - product_input.content_language = "content_language_value" - product_input.feed_label = "feed_label_value" - - request = merchant_products_v1beta.UpdateProductInputRequest( - product_input=product_input, - data_source="data_source_value", - ) - - # Make the request - response = client.update_product_input(request=request) - - # Handle the response - print(response) - -# [END merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py deleted file mode 100644 index 8d9ac7b3e0d9..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetProduct -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductsService_GetProduct_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -async def sample_get_product(): - # Create a client - client = merchant_products_v1beta.ProductsServiceAsyncClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.GetProductRequest( - name="name_value", - ) - - # Make the request - response = await client.get_product(request=request) - - # Handle the response - print(response) - -# [END merchantapi_v1beta_generated_ProductsService_GetProduct_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py deleted file mode 100644 index d0d027b7dfb5..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_get_product_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetProduct -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductsService_GetProduct_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -def sample_get_product(): - # Create a client - client = merchant_products_v1beta.ProductsServiceClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.GetProductRequest( - name="name_value", - ) - - # Make the request - response = client.get_product(request=request) - - # Handle the response - print(response) - -# [END merchantapi_v1beta_generated_ProductsService_GetProduct_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py deleted file mode 100644 index eb1af0879bf7..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListProducts -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductsService_ListProducts_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -async def sample_list_products(): - # Create a client - client = merchant_products_v1beta.ProductsServiceAsyncClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.ListProductsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_products(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END merchantapi_v1beta_generated_ProductsService_ListProducts_async] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py deleted file mode 100644 index d1b651ca0555..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/merchantapi_v1beta_generated_products_service_list_products_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListProducts -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-shopping-merchant-products - - -# [START merchantapi_v1beta_generated_ProductsService_ListProducts_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.shopping import merchant_products_v1beta - - -def sample_list_products(): - # Create a client - client = merchant_products_v1beta.ProductsServiceClient() - - # Initialize request argument(s) - request = merchant_products_v1beta.ListProductsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_products(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END merchantapi_v1beta_generated_ProductsService_ListProducts_sync] diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json b/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json deleted file mode 100644 index efc245a8341b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json +++ /dev/null @@ -1,814 +0,0 @@ -{ - "clientLibrary": { - "apis": [ - { - "id": "google.shopping.merchant.products.v1beta", - "version": "v1beta" - } - ], - "language": "PYTHON", - "name": "google-shopping-merchant-products", - "version": "0.1.0" - }, - "snippets": [ - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient", - "shortName": "ProductInputsServiceAsyncClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient.delete_product_input", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.DeleteProductInput", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "shortName": "ProductInputsService" - }, - "shortName": "DeleteProductInput" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "shortName": "delete_product_input" - }, - "description": "Sample for DeleteProductInput", - "file": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_async", - "segments": [ - { - "end": 50, - "start": 27, - "type": "FULL" - }, - { - "end": 50, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient", - "shortName": "ProductInputsServiceClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient.delete_product_input", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.DeleteProductInput", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "shortName": "ProductInputsService" - }, - "shortName": "DeleteProductInput" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.DeleteProductInputRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "shortName": "delete_product_input" - }, - "description": "Sample for DeleteProductInput", - "file": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductInputsService_DeleteProductInput_sync", - "segments": [ - { - "end": 50, - "start": 27, - "type": "FULL" - }, - { - "end": 50, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_product_inputs_service_delete_product_input_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient", - "shortName": "ProductInputsServiceAsyncClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient.insert_product_input", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.InsertProductInput", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "shortName": "ProductInputsService" - }, - "shortName": "InsertProductInput" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.InsertProductInputRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", - "shortName": "insert_product_input" - }, - "description": "Sample for InsertProductInput", - "file": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_async", - "segments": [ - { - "end": 58, - "start": 27, - "type": "FULL" - }, - { - "end": 58, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 52, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 55, - "start": 53, - "type": "REQUEST_EXECUTION" - }, - { - "end": 59, - "start": 56, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient", - "shortName": "ProductInputsServiceClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient.insert_product_input", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.InsertProductInput", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "shortName": "ProductInputsService" - }, - "shortName": "InsertProductInput" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.InsertProductInputRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", - "shortName": "insert_product_input" - }, - "description": "Sample for InsertProductInput", - "file": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductInputsService_InsertProductInput_sync", - "segments": [ - { - "end": 58, - "start": 27, - "type": "FULL" - }, - { - "end": 58, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 52, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 55, - "start": 53, - "type": "REQUEST_EXECUTION" - }, - { - "end": 59, - "start": 56, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_product_inputs_service_insert_product_input_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient", - "shortName": "ProductInputsServiceAsyncClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceAsyncClient.update_product_input", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.UpdateProductInput", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "shortName": "ProductInputsService" - }, - "shortName": "UpdateProductInput" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest" - }, - { - "name": "product_input", - "type": "google.shopping.merchant_products_v1beta.types.ProductInput" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", - "shortName": "update_product_input" - }, - "description": "Sample for UpdateProductInput", - "file": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_async", - "segments": [ - { - "end": 57, - "start": 27, - "type": "FULL" - }, - { - "end": 57, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 51, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 54, - "start": 52, - "type": "REQUEST_EXECUTION" - }, - { - "end": 58, - "start": 55, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient", - "shortName": "ProductInputsServiceClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductInputsServiceClient.update_product_input", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService.UpdateProductInput", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductInputsService", - "shortName": "ProductInputsService" - }, - "shortName": "UpdateProductInput" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.UpdateProductInputRequest" - }, - { - "name": "product_input", - "type": "google.shopping.merchant_products_v1beta.types.ProductInput" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.types.ProductInput", - "shortName": "update_product_input" - }, - "description": "Sample for UpdateProductInput", - "file": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductInputsService_UpdateProductInput_sync", - "segments": [ - { - "end": 57, - "start": 27, - "type": "FULL" - }, - { - "end": 57, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 51, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 54, - "start": 52, - "type": "REQUEST_EXECUTION" - }, - { - "end": 58, - "start": 55, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_product_inputs_service_update_product_input_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient", - "shortName": "ProductsServiceAsyncClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient.get_product", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService.GetProduct", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService", - "shortName": "ProductsService" - }, - "shortName": "GetProduct" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.GetProductRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.types.Product", - "shortName": "get_product" - }, - "description": "Sample for GetProduct", - "file": "merchantapi_v1beta_generated_products_service_get_product_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductsService_GetProduct_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_products_service_get_product_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient", - "shortName": "ProductsServiceClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient.get_product", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService.GetProduct", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService", - "shortName": "ProductsService" - }, - "shortName": "GetProduct" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.GetProductRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.types.Product", - "shortName": "get_product" - }, - "description": "Sample for GetProduct", - "file": "merchantapi_v1beta_generated_products_service_get_product_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductsService_GetProduct_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_products_service_get_product_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient", - "shortName": "ProductsServiceAsyncClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceAsyncClient.list_products", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService.ListProducts", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService", - "shortName": "ProductsService" - }, - "shortName": "ListProducts" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.ListProductsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsAsyncPager", - "shortName": "list_products" - }, - "description": "Sample for ListProducts", - "file": "merchantapi_v1beta_generated_products_service_list_products_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductsService_ListProducts_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_products_service_list_products_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient", - "shortName": "ProductsServiceClient" - }, - "fullName": "google.shopping.merchant_products_v1beta.ProductsServiceClient.list_products", - "method": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService.ListProducts", - "service": { - "fullName": "google.shopping.merchant.products.v1beta.ProductsService", - "shortName": "ProductsService" - }, - "shortName": "ListProducts" - }, - "parameters": [ - { - "name": "request", - "type": "google.shopping.merchant_products_v1beta.types.ListProductsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, Union[str, bytes]]]" - } - ], - "resultType": "google.shopping.merchant_products_v1beta.services.products_service.pagers.ListProductsPager", - "shortName": "list_products" - }, - "description": "Sample for ListProducts", - "file": "merchantapi_v1beta_generated_products_service_list_products_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "merchantapi_v1beta_generated_ProductsService_ListProducts_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "merchantapi_v1beta_generated_products_service_list_products_sync.py" - } - ] -} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py deleted file mode 100644 index da63187314ee..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/scripts/fixup_merchant_products_v1beta_keywords.py +++ /dev/null @@ -1,180 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class merchant_productsCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'delete_product_input': ('name', 'data_source', ), - 'get_product': ('name', ), - 'insert_product_input': ('parent', 'product_input', 'data_source', ), - 'list_products': ('parent', 'page_size', 'page_token', ), - 'update_product_input': ('product_input', 'data_source', 'update_mask', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: a.keyword.value not in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=merchant_productsCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the merchant_products client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py deleted file mode 100644 index d1544a0a16b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/setup.py +++ /dev/null @@ -1,99 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os -import re - -import setuptools # type: ignore - -package_root = os.path.abspath(os.path.dirname(__file__)) - -name = 'google-shopping-merchant-products' - - -description = "Google Shopping Merchant Products API client library" - -version = None - -with open(os.path.join(package_root, 'google/shopping/merchant_products/gapic_version.py')) as fp: - version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read()) - assert (len(version_candidates) == 1) - version = version_candidates[0] - -if version[0] == "0": - release_status = "Development Status :: 4 - Beta" -else: - release_status = "Development Status :: 5 - Production/Stable" - -dependencies = [ - "google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", - # Exclude incompatible versions of `google-auth` - # See https://github.com/googleapis/google-cloud-python/issues/12364 - "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", - "proto-plus >= 1.22.3, <2.0.0", - "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", - "google-shopping-type >= 0.1.6, <1.0.0", -] -extras = { -} -url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-shopping-merchant-products" - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, "README.rst") -with io.open(readme_filename, encoding="utf-8") as readme_file: - readme = readme_file.read() - -packages = [ - package - for package in setuptools.find_namespace_packages() - if package.startswith("google") -] - -setuptools.setup( - name=name, - version=version, - description=description, - long_description=readme, - author="Google LLC", - author_email="googleapis-packages@google.com", - license="Apache 2.0", - url=url, - classifiers=[ - release_status, - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "Operating System :: OS Independent", - "Topic :: Internet", - ], - platforms="Posix; MacOS X; Windows", - packages=packages, - python_requires=">=3.7", - install_requires=dependencies, - extras_require=extras, - include_package_data=True, - zip_safe=False, -) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.10.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.11.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.12.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt deleted file mode 100644 index 0112695e5bbb..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.13.txt +++ /dev/null @@ -1,12 +0,0 @@ -# We use the constraints file for the latest Python version -# (currently this file) to check that the latest -# major versions of dependencies are supported in setup.py. -# List all library dependencies and extras in this file. -# Require the latest major version be installed for each dependency. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo>=1 -google-api-core>=2 -google-auth>=2 -proto-plus>=1 -protobuf>=6 -google-shopping-type>=0 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt deleted file mode 100644 index 2af887ec8ba0..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.7.txt +++ /dev/null @@ -1,11 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.1 -google-auth==2.14.1 -proto-plus==1.22.3 -protobuf==3.20.2 -google-shopping-type==0.1.6 diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.8.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt b/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt deleted file mode 100644 index 4cae520d02b2..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/testing/constraints-3.9.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -google-shopping-type diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py deleted file mode 100644 index 191773d5572d..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py deleted file mode 100644 index 58270681dd0b..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_product_inputs_service.py +++ /dev/null @@ -1,3573 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -# try/except added for compatibility with python < 3.8 -try: - from unittest import mock - from unittest.mock import AsyncMock # pragma: NO COVER -except ImportError: # pragma: NO COVER - import mock - -import grpc -from grpc.experimental import aio -from collections.abc import Iterable, AsyncIterable -from google.protobuf import json_format -import json -import math -import pytest -from google.api_core import api_core_version -from proto.marshal.rules.dates import DurationRule, TimestampRule -from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest -from requests.sessions import Session -from google.protobuf import json_format - -try: - from google.auth.aio import credentials as ga_credentials_async - HAS_GOOGLE_AUTH_AIO = True -except ImportError: # pragma: NO COVER - HAS_GOOGLE_AUTH_AIO = False - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import path_template -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.shopping.merchant_products_v1beta.services.product_inputs_service import ProductInputsServiceAsyncClient -from google.shopping.merchant_products_v1beta.services.product_inputs_service import ProductInputsServiceClient -from google.shopping.merchant_products_v1beta.services.product_inputs_service import transports -from google.shopping.merchant_products_v1beta.types import productinputs -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types -from google.type import interval_pb2 # type: ignore -import google.auth - - - -CRED_INFO_JSON = { - "credential_source": "/path/to/file", - "credential_type": "service account credentials", - "principal": "service-account@example.com", -} -CRED_INFO_STRING = json.dumps(CRED_INFO_JSON) - - -async def mock_async_gen(data, chunk_size=1): - for i in range(0, len(data)): # pragma: NO COVER - chunk = data[i : i + chunk_size] - yield chunk.encode("utf-8") - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - -# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. -# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. -def async_anonymous_credentials(): - if HAS_GOOGLE_AUTH_AIO: - return ga_credentials_async.AnonymousCredentials() - return ga_credentials.AnonymousCredentials() - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - -# If default endpoint template is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint template so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint_template(client): - return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert ProductInputsServiceClient._get_default_mtls_endpoint(None) is None - assert ProductInputsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - -def test__read_environment_variables(): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - assert ProductInputsServiceClient._read_environment_variables() == (True, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError) as excinfo: - ProductInputsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "never", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "always", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError) as excinfo: - ProductInputsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - - with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", "foo.com") - -def test__get_client_cert_source(): - mock_provided_cert_source = mock.Mock() - mock_default_cert_source = mock.Mock() - - assert ProductInputsServiceClient._get_client_cert_source(None, False) is None - assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None - assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source - - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): - assert ProductInputsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source - assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source - -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) -def test__get_api_endpoint(): - api_override = "foo.com" - mock_client_cert_source = mock.Mock() - default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) - mock_universe = "bar.com" - mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) - - assert ProductInputsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override - assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint - assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductInputsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint - assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint - - with pytest.raises(MutualTLSChannelError) as excinfo: - ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") - assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." - - -def test__get_universe_domain(): - client_universe_domain = "foo.com" - universe_domain_env = "bar.com" - - assert ProductInputsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain - assert ProductInputsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env - assert ProductInputsServiceClient._get_universe_domain(None, None) == ProductInputsServiceClient._DEFAULT_UNIVERSE - - with pytest.raises(ValueError) as excinfo: - ProductInputsServiceClient._get_universe_domain("", None) - assert str(excinfo.value) == "Universe Domain cannot be an empty string." - -@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ - (401, CRED_INFO_JSON, True), - (403, CRED_INFO_JSON, True), - (404, CRED_INFO_JSON, True), - (500, CRED_INFO_JSON, False), - (401, None, False), - (403, None, False), - (404, None, False), - (500, None, False) -]) -def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): - cred = mock.Mock(["get_cred_info"]) - cred.get_cred_info = mock.Mock(return_value=cred_info_json) - client = ProductInputsServiceClient(credentials=cred) - client._transport._credentials = cred - - error = core_exceptions.GoogleAPICallError("message", details=["foo"]) - error.code = error_code - - client._add_cred_info_for_auth_errors(error) - if show_cred_info: - assert error.details == ["foo", CRED_INFO_STRING] - else: - assert error.details == ["foo"] - -@pytest.mark.parametrize("error_code", [401,403,404,500]) -def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): - cred = mock.Mock([]) - assert not hasattr(cred, "get_cred_info") - client = ProductInputsServiceClient(credentials=cred) - client._transport._credentials = cred - - error = core_exceptions.GoogleAPICallError("message", details=[]) - error.code = error_code - - client._add_cred_info_for_auth_errors(error) - assert error.details == [] - -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductInputsServiceClient, "grpc"), - (ProductInputsServiceAsyncClient, "grpc_asyncio"), - (ProductInputsServiceClient, "rest"), -]) -def test_product_inputs_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info, transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' - ) - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductInputsServiceGrpcTransport, "grpc"), - (transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.ProductInputsServiceRestTransport, "rest"), -]) -def test_product_inputs_service_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductInputsServiceClient, "grpc"), - (ProductInputsServiceAsyncClient, "grpc_asyncio"), - (ProductInputsServiceClient, "rest"), -]) -def test_product_inputs_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' - ) - - -def test_product_inputs_service_client_get_transport_class(): - transport = ProductInputsServiceClient.get_transport_class() - available_transports = [ - transports.ProductInputsServiceGrpcTransport, - transports.ProductInputsServiceRestTransport, - ] - assert transport in available_transports - - transport = ProductInputsServiceClient.get_transport_class("grpc") - assert transport == transports.ProductInputsServiceGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), -]) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) -def test_product_inputs_service_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name, client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError) as excinfo: - client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError) as excinfo: - client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "true"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "false"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "true"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "false"), -]) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_product_inputs_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class", [ - ProductInputsServiceClient, ProductInputsServiceAsyncClient -]) -@mock.patch.object(ProductInputsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceAsyncClient)) -def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_class): - mock_client_cert_source = mock.Mock() - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source == mock_client_cert_source - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - mock_client_cert_source = mock.Mock() - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source == mock_client_cert_source - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError) as excinfo: - client_class.get_mtls_endpoint_and_cert_source() - - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError) as excinfo: - client_class.get_mtls_endpoint_and_cert_source() - - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - -@pytest.mark.parametrize("client_class", [ - ProductInputsServiceClient, ProductInputsServiceAsyncClient -]) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) -def test_product_inputs_service_client_client_api_endpoint(client_class): - mock_client_cert_source = client_cert_source_callback - api_override = "foo.com" - default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) - mock_universe = "bar.com" - mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) - - # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", - # use ClientOptions.api_endpoint as the api endpoint regardless. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == api_override - - # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", - # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == default_endpoint - - # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", - # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - client = client_class(credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - - # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), - # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, - # and ClientOptions.universe_domain="bar.com", - # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. - options = client_options.ClientOptions() - universe_exists = hasattr(options, "universe_domain") - if universe_exists: - options = client_options.ClientOptions(universe_domain=mock_universe) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - else: - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) - assert client.universe_domain == (mock_universe if universe_exists else default_universe) - - # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", - # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. - options = client_options.ClientOptions() - if hasattr(options, "universe_domain"): - delattr(options, "universe_domain") - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == default_endpoint - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), -]) -def test_product_inputs_service_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", None), -]) -def test_product_inputs_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -def test_product_inputs_service_client_client_options_from_dict(): - with mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ProductInputsServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_product_inputs_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() - load_creds.return_value = (file_creds, None) - adc.return_value = (creds, None) - client = client_class(client_options=options, transport=transport_name) - create_channel.assert_called_with( - "merchantapi.googleapis.com:443", - credentials=file_creds, - credentials_file=None, - quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - scopes=None, - default_host="merchantapi.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("request_type", [ - productinputs.InsertProductInputRequest, - dict, -]) -def test_insert_product_input(request_type, transport: str = 'grpc'): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - ) - response = client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = productinputs.InsertProductInputRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.version_number == 1518 - - -def test_insert_product_input_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = productinputs.InsertProductInputRequest( - parent='parent_value', - data_source='data_source_value', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client.insert_product_input(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == productinputs.InsertProductInputRequest( - parent='parent_value', - data_source='data_source_value', - ) - -def test_insert_product_input_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.insert_product_input in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc - request = {} - client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.insert_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_insert_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._client._transport.insert_product_input in client._client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.AsyncMock() - mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.insert_product_input] = mock_rpc - - request = {} - await client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - await client.insert_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_insert_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.InsertProductInputRequest): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) - response = await client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - request = productinputs.InsertProductInputRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.version_number == 1518 - - -@pytest.mark.asyncio -async def test_insert_product_input_async_from_dict(): - await test_insert_product_input_async(request_type=dict) - -def test_insert_product_input_field_headers(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = productinputs.InsertProductInputRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - call.return_value = productinputs.ProductInput() - client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_insert_product_input_field_headers_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = productinputs.InsertProductInputRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) - await client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - productinputs.UpdateProductInputRequest, - dict, -]) -def test_update_product_input(request_type, transport: str = 'grpc'): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - ) - response = client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = productinputs.UpdateProductInputRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.version_number == 1518 - - -def test_update_product_input_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = productinputs.UpdateProductInputRequest( - data_source='data_source_value', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client.update_product_input(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == productinputs.UpdateProductInputRequest( - data_source='data_source_value', - ) - -def test_update_product_input_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.update_product_input in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc - request = {} - client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.update_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_update_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._client._transport.update_product_input in client._client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.AsyncMock() - mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.update_product_input] = mock_rpc - - request = {} - await client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - await client.update_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_update_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.UpdateProductInputRequest): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) - response = await client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - request = productinputs.UpdateProductInputRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.version_number == 1518 - - -@pytest.mark.asyncio -async def test_update_product_input_async_from_dict(): - await test_update_product_input_async(request_type=dict) - -def test_update_product_input_field_headers(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = productinputs.UpdateProductInputRequest() - - request.product_input.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - call.return_value = productinputs.ProductInput() - client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'product_input.name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_product_input_field_headers_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = productinputs.UpdateProductInputRequest() - - request.product_input.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) - await client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'product_input.name=name_value', - ) in kw['metadata'] - - -def test_update_product_input_flattened(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = productinputs.ProductInput() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_product_input( - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].product_input - mock_val = productinputs.ProductInput(name='name_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - - -def test_update_product_input_flattened_error(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_product_input( - productinputs.UpdateProductInputRequest(), - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - -@pytest.mark.asyncio -async def test_update_product_input_flattened_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = productinputs.ProductInput() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_product_input( - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].product_input - mock_val = productinputs.ProductInput(name='name_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - -@pytest.mark.asyncio -async def test_update_product_input_flattened_error_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_product_input( - productinputs.UpdateProductInputRequest(), - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.parametrize("request_type", [ - productinputs.DeleteProductInputRequest, - dict, -]) -def test_delete_product_input(request_type, transport: str = 'grpc'): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = productinputs.DeleteProductInputRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_product_input_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = productinputs.DeleteProductInputRequest( - name='name_value', - data_source='data_source_value', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client.delete_product_input(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == productinputs.DeleteProductInputRequest( - name='name_value', - data_source='data_source_value', - ) - -def test_delete_product_input_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.delete_product_input in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc - request = {} - client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.delete_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_delete_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._client._transport.delete_product_input in client._client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.AsyncMock() - mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.delete_product_input] = mock_rpc - - request = {} - await client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - await client.delete_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_delete_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.DeleteProductInputRequest): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - request = productinputs.DeleteProductInputRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_product_input_async_from_dict(): - await test_delete_product_input_async(request_type=dict) - -def test_delete_product_input_field_headers(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = productinputs.DeleteProductInputRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - call.return_value = None - client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_delete_product_input_field_headers_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = productinputs.DeleteProductInputRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_delete_product_input_flattened(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_product_input( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_delete_product_input_flattened_error(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_product_input( - productinputs.DeleteProductInputRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_delete_product_input_flattened_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_product_input( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_delete_product_input_flattened_error_async(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_product_input( - productinputs.DeleteProductInputRequest(), - name='name_value', - ) - - -def test_insert_product_input_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.insert_product_input in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc - - request = {} - client.insert_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.insert_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - - -def test_insert_product_input_rest_required_fields(request_type=productinputs.InsertProductInputRequest): - transport_class = transports.ProductInputsServiceRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["data_source"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - assert "dataSource" not in jsonified_request - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == request_init["data_source"] - - jsonified_request["parent"] = 'parent_value' - jsonified_request["dataSource"] = 'data_source_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("data_source", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == 'data_source_value' - - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = productinputs.ProductInput() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = productinputs.ProductInput.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - response = client.insert_product_input(request) - - expected_params = [ - ( - "dataSource", - "", - ), - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_insert_product_input_rest_unset_required_fields(): - transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.insert_product_input._get_unset_required_fields({}) - assert set(unset_fields) == (set(("dataSource", )) & set(("parent", "productInput", "dataSource", ))) - - -def test_update_product_input_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.update_product_input in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc - - request = {} - client.update_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.update_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - - -def test_update_product_input_rest_required_fields(request_type=productinputs.UpdateProductInputRequest): - transport_class = transports.ProductInputsServiceRestTransport - - request_init = {} - request_init["data_source"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - assert "dataSource" not in jsonified_request - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == request_init["data_source"] - - jsonified_request["dataSource"] = 'data_source_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("data_source", "update_mask", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == 'data_source_value' - - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = productinputs.ProductInput() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = productinputs.ProductInput.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - response = client.update_product_input(request) - - expected_params = [ - ( - "dataSource", - "", - ), - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_update_product_input_rest_unset_required_fields(): - transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.update_product_input._get_unset_required_fields({}) - assert set(unset_fields) == (set(("dataSource", "updateMask", )) & set(("productInput", "dataSource", ))) - - -def test_update_product_input_rest_flattened(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = productinputs.ProductInput() - - # get arguments that satisfy an http rule for this method - sample_request = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} - - # get truthy value for each flattened field - mock_args = dict( - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = productinputs.ProductInput.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.update_product_input(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1beta/{product_input.name=accounts/*/productInputs/*}" % client.transport._host, args[1]) - - -def test_update_product_input_rest_flattened_error(transport: str = 'rest'): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_product_input( - productinputs.UpdateProductInputRequest(), - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_delete_product_input_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.delete_product_input in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc - - request = {} - client.delete_product_input(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.delete_product_input(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - - -def test_delete_product_input_rest_required_fields(request_type=productinputs.DeleteProductInputRequest): - transport_class = transports.ProductInputsServiceRestTransport - - request_init = {} - request_init["name"] = "" - request_init["data_source"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - assert "dataSource" not in jsonified_request - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == request_init["data_source"] - - jsonified_request["name"] = 'name_value' - jsonified_request["dataSource"] = 'data_source_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("data_source", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == 'data_source_value' - - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - response = client.delete_product_input(request) - - expected_params = [ - ( - "dataSource", - "", - ), - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_delete_product_input_rest_unset_required_fields(): - transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.delete_product_input._get_unset_required_fields({}) - assert set(unset_fields) == (set(("dataSource", )) & set(("name", "dataSource", ))) - - -def test_delete_product_input_rest_flattened(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'accounts/sample1/productInputs/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.delete_product_input(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1beta/{name=accounts/*/productInputs/*}" % client.transport._host, args[1]) - - -def test_delete_product_input_rest_flattened_error(transport: str = 'rest'): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_product_input( - productinputs.DeleteProductInputRequest(), - name='name_value', - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ProductInputsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ProductInputsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductInputsServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide an api_key and a transport instance. - transport = transports.ProductInputsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = ProductInputsServiceClient( - client_options=options, - transport=transport, - ) - - # It is an error to provide an api_key and a credential. - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = ProductInputsServiceClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ProductInputsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductInputsServiceClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductInputsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ProductInputsServiceClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductInputsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ProductInputsServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ProductInputsServiceGrpcTransport, - transports.ProductInputsServiceGrpcAsyncIOTransport, - transports.ProductInputsServiceRestTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -def test_transport_kind_grpc(): - transport = ProductInputsServiceClient.get_transport_class("grpc")( - credentials=ga_credentials.AnonymousCredentials() - ) - assert transport.kind == "grpc" - - -def test_initialize_client_w_grpc(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" - ) - assert client is not None - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_insert_product_input_empty_call_grpc(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - call.return_value = productinputs.ProductInput() - client.insert_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.InsertProductInputRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_product_input_empty_call_grpc(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - call.return_value = productinputs.ProductInput() - client.update_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.UpdateProductInputRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_product_input_empty_call_grpc(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - call.return_value = None - client.delete_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.DeleteProductInputRequest() - - assert args[0] == request_msg - - -def test_transport_kind_grpc_asyncio(): - transport = ProductInputsServiceAsyncClient.get_transport_class("grpc_asyncio")( - credentials=async_anonymous_credentials() - ) - assert transport.kind == "grpc_asyncio" - - -def test_initialize_client_w_grpc_asyncio(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" - ) - assert client is not None - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_insert_product_input_empty_call_grpc_asyncio(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) - await client.insert_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.InsertProductInputRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_product_input_empty_call_grpc_asyncio(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) - await client.update_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.UpdateProductInputRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_product_input_empty_call_grpc_asyncio(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.DeleteProductInputRequest() - - assert args[0] == request_msg - - -def test_transport_kind_rest(): - transport = ProductInputsServiceClient.get_transport_class("rest")( - credentials=ga_credentials.AnonymousCredentials() - ) - assert transport.kind == "rest" - - -def test_insert_product_input_rest_bad_request(request_type=productinputs.InsertProductInputRequest): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = mock.Mock() - json_return_value = '' - response_value.json = mock.Mock(return_value={}) - response_value.status_code = 400 - response_value.request = mock.Mock() - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.insert_product_input(request) - - -@pytest.mark.parametrize("request_type", [ - productinputs.InsertProductInputRequest, - dict, -]) -def test_insert_product_input_rest_call_success(request_type): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} - request_init["product_input"] = {'name': 'name_value', 'product': 'product_value', 'channel': 1, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 'age_group_value', 'availability': 'availability_value', 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 'condition_value', 'gender': 'gender_value', 'google_product_category': 'google_product_category_value', 'gtin': ['gtin_value1', 'gtin_value2'], 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 'credit_type_value'}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 'size_system_value', 'size_types': ['size_types_value1', 'size_types_value2'], 'taxes': [{'rate': 0.428, 'country': 'country_value', 'region': 'region_value', 'tax_ship': True, 'location_id': 1157, 'postal_code': 'postal_code_value'}], 'tax_category': 'tax_category_value', 'energy_efficiency_class': 'energy_efficiency_class_value', 'min_energy_efficiency_class': 'min_energy_efficiency_class_value', 'max_energy_efficiency_class': 'max_energy_efficiency_class_value', 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 'pickup_method_value', 'pickup_sla': 'pickup_sla_value', 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': ['included_destinations_value1', 'included_destinations_value2'], 'excluded_destinations': ['excluded_destinations_value1', 'excluded_destinations_value2'], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 'pause_value', 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 'certification_authority_value', 'certification_name': 'certification_name_value', 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'structured_description': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = productinputs.InsertProductInputRequest.meta.fields["product_input"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["product_input"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - {"field": field, "subfield": subfield, "is_repeated": is_repeated} - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["product_input"][field])): - del request_init["product_input"][field][i][subfield] - else: - del request_init["product_input"][field][subfield] - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - ) - - # Wrap the value into a proper Response obj - response_value = mock.Mock() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = productinputs.ProductInput.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.insert_product_input(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.version_number == 1518 - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_insert_product_input_rest_interceptors(null_interceptor): - transport = transports.ProductInputsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), - ) - client = ProductInputsServiceClient(transport=transport) - - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input") as post, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_insert_product_input") as pre: - pre.assert_not_called() - post.assert_not_called() - post_with_metadata.assert_not_called() - pb_message = productinputs.InsertProductInputRequest.pb(productinputs.InsertProductInputRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = mock.Mock() - req.return_value.status_code = 200 - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = productinputs.ProductInput.to_json(productinputs.ProductInput()) - req.return_value.content = return_value - - request = productinputs.InsertProductInputRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = productinputs.ProductInput() - post_with_metadata.return_value = productinputs.ProductInput(), metadata - - client.insert_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - post_with_metadata.assert_called_once() - - -def test_update_product_input_rest_bad_request(request_type=productinputs.UpdateProductInputRequest): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - # send a request that will satisfy transcoding - request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = mock.Mock() - json_return_value = '' - response_value.json = mock.Mock(return_value={}) - response_value.status_code = 400 - response_value.request = mock.Mock() - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.update_product_input(request) - - -@pytest.mark.parametrize("request_type", [ - productinputs.UpdateProductInputRequest, - dict, -]) -def test_update_product_input_rest_call_success(request_type): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - - # send a request that will satisfy transcoding - request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} - request_init["product_input"] = {'name': 'accounts/sample1/productInputs/sample2', 'product': 'product_value', 'channel': 1, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 'age_group_value', 'availability': 'availability_value', 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 'condition_value', 'gender': 'gender_value', 'google_product_category': 'google_product_category_value', 'gtin': ['gtin_value1', 'gtin_value2'], 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 'credit_type_value'}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 'size_system_value', 'size_types': ['size_types_value1', 'size_types_value2'], 'taxes': [{'rate': 0.428, 'country': 'country_value', 'region': 'region_value', 'tax_ship': True, 'location_id': 1157, 'postal_code': 'postal_code_value'}], 'tax_category': 'tax_category_value', 'energy_efficiency_class': 'energy_efficiency_class_value', 'min_energy_efficiency_class': 'min_energy_efficiency_class_value', 'max_energy_efficiency_class': 'max_energy_efficiency_class_value', 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 'pickup_method_value', 'pickup_sla': 'pickup_sla_value', 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': ['included_destinations_value1', 'included_destinations_value2'], 'excluded_destinations': ['excluded_destinations_value1', 'excluded_destinations_value2'], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 'pause_value', 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 'certification_authority_value', 'certification_name': 'certification_name_value', 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'structured_description': {'digital_source_type': 'digital_source_type_value', 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} - # The version of a generated dependency at test runtime may differ from the version used during generation. - # Delete any fields which are not present in the current runtime dependency - # See https://github.com/googleapis/gapic-generator-python/issues/1748 - - # Determine if the message type is proto-plus or protobuf - test_field = productinputs.UpdateProductInputRequest.meta.fields["product_input"] - - def get_message_fields(field): - # Given a field which is a message (composite type), return a list with - # all the fields of the message. - # If the field is not a composite type, return an empty list. - message_fields = [] - - if hasattr(field, "message") and field.message: - is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") - - if is_field_type_proto_plus_type: - message_fields = field.message.meta.fields.values() - # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER - message_fields = field.message.DESCRIPTOR.fields - return message_fields - - runtime_nested_fields = [ - (field.name, nested_field.name) - for field in get_message_fields(test_field) - for nested_field in get_message_fields(field) - ] - - subfields_not_in_runtime = [] - - # For each item in the sample request, create a list of sub fields which are not present at runtime - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["product_input"].items(): # pragma: NO COVER - result = None - is_repeated = False - # For repeated fields - if isinstance(value, list) and len(value): - is_repeated = True - result = value[0] - # For fields where the type is another message - if isinstance(value, dict): - result = value - - if result and hasattr(result, "keys"): - for subfield in result.keys(): - if (field, subfield) not in runtime_nested_fields: - subfields_not_in_runtime.append( - {"field": field, "subfield": subfield, "is_repeated": is_repeated} - ) - - # Remove fields from the sample request which are not present in the runtime version of the dependency - # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER - field = subfield_to_delete.get("field") - field_repeated = subfield_to_delete.get("is_repeated") - subfield = subfield_to_delete.get("subfield") - if subfield: - if field_repeated: - for i in range(0, len(request_init["product_input"][field])): - del request_init["product_input"][field][i][subfield] - else: - del request_init["product_input"][field][subfield] - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = productinputs.ProductInput( - name='name_value', - product='product_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - ) - - # Wrap the value into a proper Response obj - response_value = mock.Mock() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = productinputs.ProductInput.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.update_product_input(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.version_number == 1518 - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_product_input_rest_interceptors(null_interceptor): - transport = transports.ProductInputsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), - ) - client = ProductInputsServiceClient(transport=transport) - - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input") as post, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_update_product_input") as pre: - pre.assert_not_called() - post.assert_not_called() - post_with_metadata.assert_not_called() - pb_message = productinputs.UpdateProductInputRequest.pb(productinputs.UpdateProductInputRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = mock.Mock() - req.return_value.status_code = 200 - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = productinputs.ProductInput.to_json(productinputs.ProductInput()) - req.return_value.content = return_value - - request = productinputs.UpdateProductInputRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = productinputs.ProductInput() - post_with_metadata.return_value = productinputs.ProductInput(), metadata - - client.update_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - post_with_metadata.assert_called_once() - - -def test_delete_product_input_rest_bad_request(request_type=productinputs.DeleteProductInputRequest): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/productInputs/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = mock.Mock() - json_return_value = '' - response_value.json = mock.Mock(return_value={}) - response_value.status_code = 400 - response_value.request = mock.Mock() - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.delete_product_input(request) - - -@pytest.mark.parametrize("request_type", [ - productinputs.DeleteProductInputRequest, - dict, -]) -def test_delete_product_input_rest_call_success(request_type): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/productInputs/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = mock.Mock() - response_value.status_code = 200 - json_return_value = '' - response_value.content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.delete_product_input(request) - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_product_input_rest_interceptors(null_interceptor): - transport = transports.ProductInputsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), - ) - client = ProductInputsServiceClient(transport=transport) - - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_delete_product_input") as pre: - pre.assert_not_called() - pb_message = productinputs.DeleteProductInputRequest.pb(productinputs.DeleteProductInputRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = mock.Mock() - req.return_value.status_code = 200 - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - request = productinputs.DeleteProductInputRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.delete_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - -def test_initialize_client_w_rest(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - assert client is not None - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_insert_product_input_empty_call_rest(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - client.insert_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.InsertProductInputRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_product_input_empty_call_rest(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - client.update_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.UpdateProductInputRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_product_input_empty_call_rest(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - client.delete_product_input(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = productinputs.DeleteProductInputRequest() - - assert args[0] == request_msg - - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ProductInputsServiceGrpcTransport, - ) - -def test_product_inputs_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ProductInputsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_product_inputs_service_base_transport(): - # Instantiate the base transport. - with mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ProductInputsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'insert_product_input', - 'update_product_input', - 'delete_product_input', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # Catch all for all remaining methods and properties - remainder = [ - 'kind', - ] - for r in remainder: - with pytest.raises(NotImplementedError): - getattr(transport, r)() - - -def test_product_inputs_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductInputsServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - quota_project_id="octopus", - ) - - -def test_product_inputs_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1beta.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductInputsServiceTransport() - adc.assert_called_once() - - -def test_product_inputs_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ProductInputsServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductInputsServiceGrpcTransport, - transports.ProductInputsServiceGrpcAsyncIOTransport, - ], -) -def test_product_inputs_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/content',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductInputsServiceGrpcTransport, - transports.ProductInputsServiceGrpcAsyncIOTransport, - transports.ProductInputsServiceRestTransport, - ], -) -def test_product_inputs_service_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] - for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) - adc.return_value = (gdch_mock, None) - transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ProductInputsServiceGrpcTransport, grpc_helpers), - (transports.ProductInputsServiceGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_product_inputs_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "merchantapi.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - scopes=["1", "2"], - default_host="merchantapi.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) -def test_product_inputs_service_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - -def test_product_inputs_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.ProductInputsServiceRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) - - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_product_inputs_service_host_no_port(transport_name): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), - transport=transport_name, - ) - assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com' - ) - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_product_inputs_service_host_with_port(transport_name): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), - transport=transport_name, - ) - assert client.transport._host == ( - 'merchantapi.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com:8000' - ) - -@pytest.mark.parametrize("transport_name", [ - "rest", -]) -def test_product_inputs_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() - client1 = ProductInputsServiceClient( - credentials=creds1, - transport=transport_name, - ) - client2 = ProductInputsServiceClient( - credentials=creds2, - transport=transport_name, - ) - session1 = client1.transport.insert_product_input._session - session2 = client2.transport.insert_product_input._session - assert session1 != session2 - session1 = client1.transport.update_product_input._session - session2 = client2.transport.update_product_input._session - assert session1 != session2 - session1 = client1.transport.delete_product_input._session - session2 = client2.transport.delete_product_input._session - assert session1 != session2 -def test_product_inputs_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductInputsServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_product_inputs_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductInputsServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) -def test_product_inputs_service_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) -def test_product_inputs_service_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_product_path(): - account = "squid" - product = "clam" - expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) - actual = ProductInputsServiceClient.product_path(account, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "account": "whelk", - "product": "octopus", - } - path = ProductInputsServiceClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_product_path(path) - assert expected == actual - -def test_product_input_path(): - account = "oyster" - productinput = "nudibranch" - expected = "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) - actual = ProductInputsServiceClient.product_input_path(account, productinput) - assert expected == actual - - -def test_parse_product_input_path(): - expected = { - "account": "cuttlefish", - "productinput": "mussel", - } - path = ProductInputsServiceClient.product_input_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_product_input_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ProductInputsServiceClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nautilus", - } - path = ProductInputsServiceClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "scallop" - expected = "folders/{folder}".format(folder=folder, ) - actual = ProductInputsServiceClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "abalone", - } - path = ProductInputsServiceClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "squid" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ProductInputsServiceClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "clam", - } - path = ProductInputsServiceClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "whelk" - expected = "projects/{project}".format(project=project, ) - actual = ProductInputsServiceClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "octopus", - } - path = ProductInputsServiceClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "oyster" - location = "nudibranch" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = ProductInputsServiceClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - } - path = ProductInputsServiceClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ProductInputsServiceClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_with_default_client_info(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: - transport_class = ProductInputsServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -def test_transport_close_grpc(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" - ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - - -@pytest.mark.asyncio -async def test_transport_close_grpc_asyncio(): - client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" - ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - - -def test_transport_close_rest(): - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - - -def test_client_ctx(): - transports = [ - 'rest', - 'grpc', - ] - for transport in transports: - client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() - -@pytest.mark.parametrize("client_class,transport_class", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport), -]) -def test_api_key_credentials(client_class, transport_class): - with mock.patch.object( - google.auth._default, "get_api_key_credentials", create=True - ) as get_api_key_credentials: - mock_cred = mock.Mock() - get_api_key_credentials.return_value = mock_cred - options = client_options.ClientOptions() - options.api_key = "api_key" - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=mock_cred, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py b/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py deleted file mode 100644 index 767ed2b7bcca..000000000000 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/tests/unit/gapic/merchant_products_v1beta/test_products_service.py +++ /dev/null @@ -1,3099 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -# try/except added for compatibility with python < 3.8 -try: - from unittest import mock - from unittest.mock import AsyncMock # pragma: NO COVER -except ImportError: # pragma: NO COVER - import mock - -import grpc -from grpc.experimental import aio -from collections.abc import Iterable, AsyncIterable -from google.protobuf import json_format -import json -import math -import pytest -from google.api_core import api_core_version -from proto.marshal.rules.dates import DurationRule, TimestampRule -from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest -from requests.sessions import Session -from google.protobuf import json_format - -try: - from google.auth.aio import credentials as ga_credentials_async - HAS_GOOGLE_AUTH_AIO = True -except ImportError: # pragma: NO COVER - HAS_GOOGLE_AUTH_AIO = False - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import path_template -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.oauth2 import service_account -from google.shopping.merchant_products_v1beta.services.products_service import ProductsServiceAsyncClient -from google.shopping.merchant_products_v1beta.services.products_service import ProductsServiceClient -from google.shopping.merchant_products_v1beta.services.products_service import pagers -from google.shopping.merchant_products_v1beta.services.products_service import transports -from google.shopping.merchant_products_v1beta.types import products -from google.shopping.merchant_products_v1beta.types import products_common -from google.shopping.type.types import types -import google.auth - - - -CRED_INFO_JSON = { - "credential_source": "/path/to/file", - "credential_type": "service account credentials", - "principal": "service-account@example.com", -} -CRED_INFO_STRING = json.dumps(CRED_INFO_JSON) - - -async def mock_async_gen(data, chunk_size=1): - for i in range(0, len(data)): # pragma: NO COVER - chunk = data[i : i + chunk_size] - yield chunk.encode("utf-8") - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - -# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. -# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. -def async_anonymous_credentials(): - if HAS_GOOGLE_AUTH_AIO: - return ga_credentials_async.AnonymousCredentials() - return ga_credentials.AnonymousCredentials() - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - -# If default endpoint template is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint template so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint_template(client): - return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert ProductsServiceClient._get_default_mtls_endpoint(None) is None - assert ProductsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - -def test__read_environment_variables(): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - assert ProductsServiceClient._read_environment_variables() == (True, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError) as excinfo: - ProductsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - assert ProductsServiceClient._read_environment_variables() == (False, "never", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - assert ProductsServiceClient._read_environment_variables() == (False, "always", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) - - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError) as excinfo: - ProductsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - - with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", "foo.com") - -def test__get_client_cert_source(): - mock_provided_cert_source = mock.Mock() - mock_default_cert_source = mock.Mock() - - assert ProductsServiceClient._get_client_cert_source(None, False) is None - assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None - assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source - - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): - assert ProductsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source - assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source - -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) -def test__get_api_endpoint(): - api_override = "foo.com" - mock_client_cert_source = mock.Mock() - default_universe = ProductsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) - mock_universe = "bar.com" - mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) - - assert ProductsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override - assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint - assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint - assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint - - with pytest.raises(MutualTLSChannelError) as excinfo: - ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") - assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." - - -def test__get_universe_domain(): - client_universe_domain = "foo.com" - universe_domain_env = "bar.com" - - assert ProductsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain - assert ProductsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env - assert ProductsServiceClient._get_universe_domain(None, None) == ProductsServiceClient._DEFAULT_UNIVERSE - - with pytest.raises(ValueError) as excinfo: - ProductsServiceClient._get_universe_domain("", None) - assert str(excinfo.value) == "Universe Domain cannot be an empty string." - -@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ - (401, CRED_INFO_JSON, True), - (403, CRED_INFO_JSON, True), - (404, CRED_INFO_JSON, True), - (500, CRED_INFO_JSON, False), - (401, None, False), - (403, None, False), - (404, None, False), - (500, None, False) -]) -def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): - cred = mock.Mock(["get_cred_info"]) - cred.get_cred_info = mock.Mock(return_value=cred_info_json) - client = ProductsServiceClient(credentials=cred) - client._transport._credentials = cred - - error = core_exceptions.GoogleAPICallError("message", details=["foo"]) - error.code = error_code - - client._add_cred_info_for_auth_errors(error) - if show_cred_info: - assert error.details == ["foo", CRED_INFO_STRING] - else: - assert error.details == ["foo"] - -@pytest.mark.parametrize("error_code", [401,403,404,500]) -def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): - cred = mock.Mock([]) - assert not hasattr(cred, "get_cred_info") - client = ProductsServiceClient(credentials=cred) - client._transport._credentials = cred - - error = core_exceptions.GoogleAPICallError("message", details=[]) - error.code = error_code - - client._add_cred_info_for_auth_errors(error) - assert error.details == [] - -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductsServiceClient, "grpc"), - (ProductsServiceAsyncClient, "grpc_asyncio"), - (ProductsServiceClient, "rest"), -]) -def test_products_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info, transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' - ) - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductsServiceGrpcTransport, "grpc"), - (transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.ProductsServiceRestTransport, "rest"), -]) -def test_products_service_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductsServiceClient, "grpc"), - (ProductsServiceAsyncClient, "grpc_asyncio"), - (ProductsServiceClient, "rest"), -]) -def test_products_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' - ) - - -def test_products_service_client_get_transport_class(): - transport = ProductsServiceClient.get_transport_class() - available_transports = [ - transports.ProductsServiceGrpcTransport, - transports.ProductsServiceRestTransport, - ] - assert transport in available_transports - - transport = ProductsServiceClient.get_transport_class("grpc") - assert transport == transports.ProductsServiceGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), -]) -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) -def test_products_service_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name, client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError) as excinfo: - client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError) as excinfo: - client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "true"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "false"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "true"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "false"), -]) -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_products_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class", [ - ProductsServiceClient, ProductsServiceAsyncClient -]) -@mock.patch.object(ProductsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceAsyncClient)) -def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class): - mock_client_cert_source = mock.Mock() - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source == mock_client_cert_source - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - mock_client_cert_source = mock.Mock() - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source == mock_client_cert_source - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError) as excinfo: - client_class.get_mtls_endpoint_and_cert_source() - - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError) as excinfo: - client_class.get_mtls_endpoint_and_cert_source() - - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - -@pytest.mark.parametrize("client_class", [ - ProductsServiceClient, ProductsServiceAsyncClient -]) -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) -def test_products_service_client_client_api_endpoint(client_class): - mock_client_cert_source = client_cert_source_callback - api_override = "foo.com" - default_universe = ProductsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) - mock_universe = "bar.com" - mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) - - # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", - # use ClientOptions.api_endpoint as the api endpoint regardless. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == api_override - - # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", - # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == default_endpoint - - # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", - # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - client = client_class(credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - - # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), - # GOOGLE_API_USE_CLIENT_CERTIFICATE="false" (default), default cert source doesn't exist, - # and ClientOptions.universe_domain="bar.com", - # use the _DEFAULT_ENDPOINT_TEMPLATE populated with universe domain as the api endpoint. - options = client_options.ClientOptions() - universe_exists = hasattr(options, "universe_domain") - if universe_exists: - options = client_options.ClientOptions(universe_domain=mock_universe) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - else: - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) - assert client.universe_domain == (mock_universe if universe_exists else default_universe) - - # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", - # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. - options = client_options.ClientOptions() - if hasattr(options, "universe_domain"): - delattr(options, "universe_domain") - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == default_endpoint - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), -]) -def test_products_service_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", None), -]) -def test_products_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -def test_products_service_client_client_options_from_dict(): - with mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = ProductsServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_products_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() - load_creds.return_value = (file_creds, None) - adc.return_value = (creds, None) - client = client_class(client_options=options, transport=transport_name) - create_channel.assert_called_with( - "merchantapi.googleapis.com:443", - credentials=file_creds, - credentials_file=None, - quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - scopes=None, - default_host="merchantapi.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("request_type", [ - products.GetProductRequest, - dict, -]) -def test_get_product(request_type, transport: str = 'grpc'): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = products.Product( - name='name_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, - ) - response = client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = products.GetProductRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, products.Product) - assert response.name == 'name_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.data_source == 'data_source_value' - assert response.version_number == 1518 - - -def test_get_product_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = products.GetProductRequest( - name='name_value', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client.get_product(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == products.GetProductRequest( - name='name_value', - ) - -def test_get_product_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.get_product in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.get_product] = mock_rpc - request = {} - client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.get_product(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_get_product_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._client._transport.get_product in client._client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.AsyncMock() - mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.get_product] = mock_rpc - - request = {} - await client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - await client.get_product(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=products.GetProductRequest): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.Product( - name='name_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, - )) - response = await client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - request = products.GetProductRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, products.Product) - assert response.name == 'name_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.data_source == 'data_source_value' - assert response.version_number == 1518 - - -@pytest.mark.asyncio -async def test_get_product_async_from_dict(): - await test_get_product_async(request_type=dict) - -def test_get_product_field_headers(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = products.GetProductRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = products.Product() - client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_product_field_headers_async(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = products.GetProductRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) - await client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_get_product_flattened(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = products.Product() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_product( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_get_product_flattened_error(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_product( - products.GetProductRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_get_product_flattened_async(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = products.Product() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_product( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_product_flattened_error_async(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_product( - products.GetProductRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - products.ListProductsRequest, - dict, -]) -def test_list_products(request_type, transport: str = 'grpc'): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = products.ListProductsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - request = products.ListProductsRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_products_non_empty_request_with_auto_populated_field(): - # This test is a coverage failsafe to make sure that UUID4 fields are - # automatically populated, according to AIP-4235, with non-empty requests. - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Populate all string fields in the request which are not UUID4 - # since we want to check that UUID4 are populated automatically - # if they meet the requirements of AIP 4235. - request = products.ListProductsRequest( - parent='parent_value', - page_token='page_token_value', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client.list_products(request=request) - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == products.ListProductsRequest( - parent='parent_value', - page_token='page_token_value', - ) - -def test_list_products_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.list_products in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.list_products] = mock_rpc - request = {} - client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.list_products(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_list_products_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._client._transport.list_products in client._client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.AsyncMock() - mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.list_products] = mock_rpc - - request = {} - await client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - await client.list_products(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - -@pytest.mark.asyncio -async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=products.ListProductsRequest): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - request = products.ListProductsRequest() - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_products_async_from_dict(): - await test_list_products_async(request_type=dict) - -def test_list_products_field_headers(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = products.ListProductsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = products.ListProductsResponse() - client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_products_field_headers_async(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = products.ListProductsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) - await client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_products_flattened(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = products.ListProductsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_products( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_products_flattened_error(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_products( - products.ListProductsRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_products_flattened_async(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = products.ListProductsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_products( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_products_flattened_error_async(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_products( - products.ListProductsRequest(), - parent='parent_value', - ) - - -def test_list_products_pager(transport_name: str = "grpc"): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - products.Product(), - ], - next_page_token='abc', - ), - products.ListProductsResponse( - products=[], - next_page_token='def', - ), - products.ListProductsResponse( - products=[ - products.Product(), - ], - next_page_token='ghi', - ), - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - ], - ), - RuntimeError, - ) - - expected_metadata = () - retry = retries.Retry() - timeout = 5 - expected_metadata = tuple(expected_metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_products(request={}, retry=retry, timeout=timeout) - - assert pager._metadata == expected_metadata - assert pager._retry == retry - assert pager._timeout == timeout - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, products.Product) - for i in results) -def test_list_products_pages(transport_name: str = "grpc"): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - products.Product(), - ], - next_page_token='abc', - ), - products.ListProductsResponse( - products=[], - next_page_token='def', - ), - products.ListProductsResponse( - products=[ - products.Product(), - ], - next_page_token='ghi', - ), - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - ], - ), - RuntimeError, - ) - pages = list(client.list_products(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_products_async_pager(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - products.Product(), - ], - next_page_token='abc', - ), - products.ListProductsResponse( - products=[], - next_page_token='def', - ), - products.ListProductsResponse( - products=[ - products.Product(), - ], - next_page_token='ghi', - ), - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_products(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, products.Product) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_products_async_pages(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - products.Product(), - ], - next_page_token='abc', - ), - products.ListProductsResponse( - products=[], - next_page_token='def', - ), - products.ListProductsResponse( - products=[ - products.Product(), - ], - next_page_token='ghi', - ), - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - ], - ), - RuntimeError, - ) - pages = [] - # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` - # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 - async for page_ in ( # pragma: no branch - await client.list_products(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -def test_get_product_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.get_product in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.get_product] = mock_rpc - - request = {} - client.get_product(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.get_product(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - - -def test_get_product_rest_required_fields(request_type=products.GetProductRequest): - transport_class = transports.ProductsServiceRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = products.Product() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = products.Product.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - response = client.get_product(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_product_rest_unset_required_fields(): - transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_product._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -def test_get_product_rest_flattened(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = products.Product() - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'accounts/sample1/products/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = products.Product.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.get_product(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1beta/{name=accounts/*/products/*}" % client.transport._host, args[1]) - - -def test_get_product_rest_flattened_error(transport: str = 'rest'): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_product( - products.GetProductRequest(), - name='name_value', - ) - - -def test_list_products_rest_use_cached_wrapped_rpc(): - # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, - # instead of constructing them on each call - with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Should wrap all calls on client creation - assert wrapper_fn.call_count > 0 - wrapper_fn.reset_mock() - - # Ensure method has been cached - assert client._transport.list_products in client._transport._wrapped_methods - - # Replace cached wrapped function with mock - mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.list_products] = mock_rpc - - request = {} - client.list_products(request) - - # Establish that the underlying gRPC stub method was called. - assert mock_rpc.call_count == 1 - - client.list_products(request) - - # Establish that a new wrapper was not created for this call - assert wrapper_fn.call_count == 0 - assert mock_rpc.call_count == 2 - - -def test_list_products_rest_required_fields(request_type=products.ListProductsRequest): - transport_class = transports.ProductsServiceRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = products.ListProductsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = products.ListProductsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - response = client.list_products(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_products_rest_unset_required_fields(): - transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_products._get_unset_required_fields({}) - assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) - - -def test_list_products_rest_flattened(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = products.ListProductsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'accounts/sample1'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - # Convert return value to protobuf type - return_value = products.ListProductsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - - client.list_products(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1beta/{parent=accounts/*}/products" % client.transport._host, args[1]) - - -def test_list_products_rest_flattened_error(transport: str = 'rest'): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_products( - products.ListProductsRequest(), - parent='parent_value', - ) - - -def test_list_products_rest_pager(transport: str = 'rest'): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - products.Product(), - ], - next_page_token='abc', - ), - products.ListProductsResponse( - products=[], - next_page_token='def', - ), - products.ListProductsResponse( - products=[ - products.Product(), - ], - next_page_token='ghi', - ), - products.ListProductsResponse( - products=[ - products.Product(), - products.Product(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(products.ListProductsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'accounts/sample1'} - - pager = client.list_products(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, products.Product) - for i in results) - - pages = list(client.list_products(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ProductsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.ProductsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductsServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide an api_key and a transport instance. - transport = transports.ProductsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = ProductsServiceClient( - client_options=options, - transport=transport, - ) - - # It is an error to provide an api_key and a credential. - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = ProductsServiceClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.ProductsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ProductsServiceClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ProductsServiceClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ProductsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.ProductsServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.ProductsServiceGrpcTransport, - transports.ProductsServiceGrpcAsyncIOTransport, - transports.ProductsServiceRestTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -def test_transport_kind_grpc(): - transport = ProductsServiceClient.get_transport_class("grpc")( - credentials=ga_credentials.AnonymousCredentials() - ) - assert transport.kind == "grpc" - - -def test_initialize_client_w_grpc(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" - ) - assert client is not None - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_product_empty_call_grpc(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value = products.Product() - client.get_product(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = products.GetProductRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_products_empty_call_grpc(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = products.ListProductsResponse() - client.list_products(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = products.ListProductsRequest() - - assert args[0] == request_msg - - -def test_transport_kind_grpc_asyncio(): - transport = ProductsServiceAsyncClient.get_transport_class("grpc_asyncio")( - credentials=async_anonymous_credentials() - ) - assert transport.kind == "grpc_asyncio" - - -def test_initialize_client_w_grpc_asyncio(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" - ) - assert client is not None - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_product_empty_call_grpc_asyncio(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product( - name='name_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, - )) - await client.get_product(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = products.GetProductRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_products_empty_call_grpc_asyncio(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( - next_page_token='next_page_token_value', - )) - await client.list_products(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = products.ListProductsRequest() - - assert args[0] == request_msg - - -def test_transport_kind_rest(): - transport = ProductsServiceClient.get_transport_class("rest")( - credentials=ga_credentials.AnonymousCredentials() - ) - assert transport.kind == "rest" - - -def test_get_product_rest_bad_request(request_type=products.GetProductRequest): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/products/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = mock.Mock() - json_return_value = '' - response_value.json = mock.Mock(return_value={}) - response_value.status_code = 400 - response_value.request = mock.Mock() - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.get_product(request) - - -@pytest.mark.parametrize("request_type", [ - products.GetProductRequest, - dict, -]) -def test_get_product_rest_call_success(request_type): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/products/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = products.Product( - name='name_value', - channel=types.Channel.ChannelEnum.ONLINE, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, - ) - - # Wrap the value into a proper Response obj - response_value = mock.Mock() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = products.Product.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.get_product(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, products.Product) - assert response.name == 'name_value' - assert response.channel == types.Channel.ChannelEnum.ONLINE - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.data_source == 'data_source_value' - assert response.version_number == 1518 - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_product_rest_interceptors(null_interceptor): - transport = transports.ProductsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), - ) - client = ProductsServiceClient(transport=transport) - - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product") as post, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_get_product") as pre: - pre.assert_not_called() - post.assert_not_called() - post_with_metadata.assert_not_called() - pb_message = products.GetProductRequest.pb(products.GetProductRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = mock.Mock() - req.return_value.status_code = 200 - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = products.Product.to_json(products.Product()) - req.return_value.content = return_value - - request = products.GetProductRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = products.Product() - post_with_metadata.return_value = products.Product(), metadata - - client.get_product(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - post_with_metadata.assert_called_once() - - -def test_list_products_rest_bad_request(request_type=products.ListProductsRequest): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = mock.Mock() - json_return_value = '' - response_value.json = mock.Mock(return_value={}) - response_value.status_code = 400 - response_value.request = mock.Mock() - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - client.list_products(request) - - -@pytest.mark.parametrize("request_type", [ - products.ListProductsRequest, - dict, -]) -def test_list_products_rest_call_success(request_type): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = products.ListProductsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = mock.Mock() - response_value.status_code = 200 - - # Convert return value to protobuf type - return_value = products.ListProductsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') - req.return_value = response_value - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - response = client.list_products(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_products_rest_interceptors(null_interceptor): - transport = transports.ProductsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), - ) - client = ProductsServiceClient(transport=transport) - - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products") as post, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_list_products") as pre: - pre.assert_not_called() - post.assert_not_called() - post_with_metadata.assert_not_called() - pb_message = products.ListProductsRequest.pb(products.ListProductsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = mock.Mock() - req.return_value.status_code = 200 - req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = products.ListProductsResponse.to_json(products.ListProductsResponse()) - req.return_value.content = return_value - - request = products.ListProductsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = products.ListProductsResponse() - post_with_metadata.return_value = products.ListProductsResponse(), metadata - - client.list_products(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - post_with_metadata.assert_called_once() - -def test_initialize_client_w_rest(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - assert client is not None - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_product_empty_call_rest(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - client.get_product(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = products.GetProductRequest() - - assert args[0] == request_msg - - -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_products_empty_call_rest(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - client.list_products(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = products.ListProductsRequest() - - assert args[0] == request_msg - - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.ProductsServiceGrpcTransport, - ) - -def test_products_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ProductsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_products_service_base_transport(): - # Instantiate the base transport. - with mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.ProductsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'get_product', - 'list_products', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # Catch all for all remaining methods and properties - remainder = [ - 'kind', - ] - for r in remainder: - with pytest.raises(NotImplementedError): - getattr(transport, r)() - - -def test_products_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductsServiceTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - quota_project_id="octopus", - ) - - -def test_products_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1beta.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ProductsServiceTransport() - adc.assert_called_once() - - -def test_products_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ProductsServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductsServiceGrpcTransport, - transports.ProductsServiceGrpcAsyncIOTransport, - ], -) -def test_products_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/content',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ProductsServiceGrpcTransport, - transports.ProductsServiceGrpcAsyncIOTransport, - transports.ProductsServiceRestTransport, - ], -) -def test_products_service_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] - for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) - adc.return_value = (gdch_mock, None) - transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ProductsServiceGrpcTransport, grpc_helpers), - (transports.ProductsServiceGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_products_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "merchantapi.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/content', -), - scopes=["1", "2"], - default_host="merchantapi.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) -def test_products_service_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - -def test_products_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.ProductsServiceRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) - - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_products_service_host_no_port(transport_name): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), - transport=transport_name, - ) - assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com' - ) - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_products_service_host_with_port(transport_name): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), - transport=transport_name, - ) - assert client.transport._host == ( - 'merchantapi.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com:8000' - ) - -@pytest.mark.parametrize("transport_name", [ - "rest", -]) -def test_products_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() - client1 = ProductsServiceClient( - credentials=creds1, - transport=transport_name, - ) - client2 = ProductsServiceClient( - credentials=creds2, - transport=transport_name, - ) - session1 = client1.transport.get_product._session - session2 = client2.transport.get_product._session - assert session1 != session2 - session1 = client1.transport.list_products._session - session2 = client2.transport.list_products._session - assert session1 != session2 -def test_products_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductsServiceGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_products_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.ProductsServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) -def test_products_service_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) -def test_products_service_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_product_path(): - account = "squid" - product = "clam" - expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) - actual = ProductsServiceClient.product_path(account, product) - assert expected == actual - - -def test_parse_product_path(): - expected = { - "account": "whelk", - "product": "octopus", - } - path = ProductsServiceClient.product_path(**expected) - - # Check that the path construction is reversible. - actual = ProductsServiceClient.parse_product_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "oyster" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = ProductsServiceClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nudibranch", - } - path = ProductsServiceClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = ProductsServiceClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder, ) - actual = ProductsServiceClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "mussel", - } - path = ProductsServiceClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = ProductsServiceClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "winkle" - expected = "organizations/{organization}".format(organization=organization, ) - actual = ProductsServiceClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "nautilus", - } - path = ProductsServiceClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = ProductsServiceClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "scallop" - expected = "projects/{project}".format(project=project, ) - actual = ProductsServiceClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "abalone", - } - path = ProductsServiceClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = ProductsServiceClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "squid" - location = "clam" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = ProductsServiceClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "whelk", - "location": "octopus", - } - path = ProductsServiceClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = ProductsServiceClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_with_default_client_info(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: - transport_class = ProductsServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - -def test_transport_close_grpc(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" - ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - - -@pytest.mark.asyncio -async def test_transport_close_grpc_asyncio(): - client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" - ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - - -def test_transport_close_rest(): - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" - ) - with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - - -def test_client_ctx(): - transports = [ - 'rest', - 'grpc', - ] - for transport in transports: - client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() - -@pytest.mark.parametrize("client_class,transport_class", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport), -]) -def test_api_key_credentials(client_class, transport_class): - with mock.patch.object( - google.auth._default, "get_api_key_credentials", create=True - ) as get_api_key_credentials: - mock_cred = mock.Mock() - get_api_key_credentials.return_value = mock_cred - options = client_options.ClientOptions() - options.api_key = "api_key" - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=mock_cred, - credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) diff --git a/packages/google-shopping-merchant-products/docs/index.rst b/packages/google-shopping-merchant-products/docs/index.rst index b420f11ffe56..11f4b4065747 100644 --- a/packages/google-shopping-merchant-products/docs/index.rst +++ b/packages/google-shopping-merchant-products/docs/index.rst @@ -2,6 +2,9 @@ .. include:: multiprocessing.rst +This package includes clients for multiple versions of Merchant API. +By default, you will get version ``merchant_products_v1beta``. + API Reference ------------- @@ -11,6 +14,14 @@ API Reference merchant_products_v1beta/services_ merchant_products_v1beta/types_ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + merchant_products_v1/services_ + merchant_products_v1/types_ + Changelog --------- diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/product_inputs_service.rst b/packages/google-shopping-merchant-products/docs/merchant_products_v1/product_inputs_service.rst similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/product_inputs_service.rst rename to packages/google-shopping-merchant-products/docs/merchant_products_v1/product_inputs_service.rst diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/products_service.rst b/packages/google-shopping-merchant-products/docs/merchant_products_v1/products_service.rst similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/products_service.rst rename to packages/google-shopping-merchant-products/docs/merchant_products_v1/products_service.rst diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/services_.rst b/packages/google-shopping-merchant-products/docs/merchant_products_v1/services_.rst similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/services_.rst rename to packages/google-shopping-merchant-products/docs/merchant_products_v1/services_.rst diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/types_.rst b/packages/google-shopping-merchant-products/docs/merchant_products_v1/types_.rst similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/docs/merchant_products_v1/types_.rst rename to packages/google-shopping-merchant-products/docs/merchant_products_v1/types_.rst diff --git a/packages/google-shopping-merchant-products/google/shopping/merchant_products/gapic_version.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products/gapic_version.py index 9650dd3a514f..20a9cd975b02 100644 --- a/packages/google-shopping-merchant-products/google/shopping/merchant_products/gapic_version.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.2.6" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/__init__.py new file mode 100644 index 000000000000..1b367c14b8b3 --- /dev/null +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/__init__.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.shopping.merchant_products_v1 import gapic_version as package_version + +__version__ = package_version.__version__ + + +from .services.product_inputs_service import ( + ProductInputsServiceAsyncClient, + ProductInputsServiceClient, +) +from .services.products_service import ProductsServiceAsyncClient, ProductsServiceClient +from .types.productinputs import ( + DeleteProductInputRequest, + InsertProductInputRequest, + ProductInput, + UpdateProductInputRequest, +) +from .types.products import ( + GetProductRequest, + ListProductsRequest, + ListProductsResponse, + Product, +) +from .types.products_common import ( + AgeGroup, + AutomatedDiscounts, + Availability, + CertificationAuthority, + CertificationName, + CloudExportAdditionalProperties, + Condition, + CreditType, + DigitalSourceType, + EnergyEfficiencyClass, + FreeShippingThreshold, + Gender, + LoyaltyPoints, + LoyaltyProgram, + Pause, + PickupMethod, + PickupSla, + ProductAttributes, + ProductCertification, + ProductDetail, + ProductDimension, + ProductInstallment, + ProductStatus, + ProductSustainabilityIncentive, + ProductWeight, + Shipping, + ShippingDimension, + ShippingWeight, + SizeSystem, + SizeType, + StructuredDescription, + StructuredTitle, + SubscriptionCost, + SubscriptionPeriod, + UnitPricingBaseMeasure, + UnitPricingMeasure, +) + +__all__ = ( + "ProductInputsServiceAsyncClient", + "ProductsServiceAsyncClient", + "AgeGroup", + "AutomatedDiscounts", + "Availability", + "CertificationAuthority", + "CertificationName", + "CloudExportAdditionalProperties", + "Condition", + "CreditType", + "DeleteProductInputRequest", + "DigitalSourceType", + "EnergyEfficiencyClass", + "FreeShippingThreshold", + "Gender", + "GetProductRequest", + "InsertProductInputRequest", + "ListProductsRequest", + "ListProductsResponse", + "LoyaltyPoints", + "LoyaltyProgram", + "Pause", + "PickupMethod", + "PickupSla", + "Product", + "ProductAttributes", + "ProductCertification", + "ProductDetail", + "ProductDimension", + "ProductInput", + "ProductInputsServiceClient", + "ProductInstallment", + "ProductStatus", + "ProductSustainabilityIncentive", + "ProductWeight", + "ProductsServiceClient", + "Shipping", + "ShippingDimension", + "ShippingWeight", + "SizeSystem", + "SizeType", + "StructuredDescription", + "StructuredTitle", + "SubscriptionCost", + "SubscriptionPeriod", + "UnitPricingBaseMeasure", + "UnitPricingMeasure", + "UpdateProductInputRequest", +) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_metadata.json b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/gapic_metadata.json similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/gapic_metadata.json rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/gapic_metadata.json diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/gapic_version.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/gapic_version.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/gapic_version.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/gapic_version.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/py.typed b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/py.typed similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products/py.typed rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/py.typed diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/__init__.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/__init__.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/__init__.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py similarity index 90% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py index 570e3b7a9ffd..00604516d58f 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/__init__.py @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .client import ProductInputsServiceClient from .async_client import ProductInputsServiceAsyncClient +from .client import ProductInputsServiceClient __all__ = ( - 'ProductInputsServiceClient', - 'ProductInputsServiceAsyncClient', + "ProductInputsServiceClient", + "ProductInputsServiceAsyncClient", ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py similarity index 84% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py index 71715a222193..9ad2a02f221b 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/async_client.py @@ -13,21 +13,31 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging as std_logging from collections import OrderedDict +import logging as std_logging import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union - -from google.shopping.merchant_products_v1 import gapic_version as package_version +from typing import ( + Callable, + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) -from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore +from google.api_core.client_options import ClientOptions +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore import google.protobuf +from google.shopping.merchant_products_v1 import gapic_version as package_version try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] @@ -35,21 +45,24 @@ OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore from google.protobuf import field_mask_pb2 # type: ignore -from google.shopping.merchant_products_v1.types import productinputs -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types -from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport + +from google.shopping.merchant_products_v1.types import productinputs, products_common + from .client import ProductInputsServiceClient +from .transports.base import DEFAULT_CLIENT_INFO, ProductInputsServiceTransport +from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False _LOGGER = std_logging.getLogger(__name__) + class ProductInputsServiceAsyncClient: """Service to use ProductInput resource.""" @@ -65,17 +78,33 @@ class ProductInputsServiceAsyncClient: product_path = staticmethod(ProductInputsServiceClient.product_path) parse_product_path = staticmethod(ProductInputsServiceClient.parse_product_path) product_input_path = staticmethod(ProductInputsServiceClient.product_input_path) - parse_product_input_path = staticmethod(ProductInputsServiceClient.parse_product_input_path) - common_billing_account_path = staticmethod(ProductInputsServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductInputsServiceClient.parse_common_billing_account_path) + parse_product_input_path = staticmethod( + ProductInputsServiceClient.parse_product_input_path + ) + common_billing_account_path = staticmethod( + ProductInputsServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + ProductInputsServiceClient.parse_common_billing_account_path + ) common_folder_path = staticmethod(ProductInputsServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductInputsServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductInputsServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductInputsServiceClient.parse_common_organization_path) + parse_common_folder_path = staticmethod( + ProductInputsServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + ProductInputsServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + ProductInputsServiceClient.parse_common_organization_path + ) common_project_path = staticmethod(ProductInputsServiceClient.common_project_path) - parse_common_project_path = staticmethod(ProductInputsServiceClient.parse_common_project_path) + parse_common_project_path = staticmethod( + ProductInputsServiceClient.parse_common_project_path + ) common_location_path = staticmethod(ProductInputsServiceClient.common_location_path) - parse_common_location_path = staticmethod(ProductInputsServiceClient.parse_common_location_path) + parse_common_location_path = staticmethod( + ProductInputsServiceClient.parse_common_location_path + ) @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): @@ -111,7 +140,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): """Return the API endpoint and client cert source for mutual TLS. The client cert source is determined in the following order: @@ -174,12 +205,20 @@ def universe_domain(self) -> str: get_transport_class = ProductInputsServiceClient.get_transport_class - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[ + Union[ + str, + ProductInputsServiceTransport, + Callable[..., ProductInputsServiceTransport], + ] + ] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: """Instantiates the product inputs service async client. Args: @@ -234,30 +273,38 @@ def __init__(self, *, transport=transport, client_options=client_options, client_info=client_info, - ) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER _LOGGER.debug( "Created client `google.shopping.merchant.products_v1.ProductInputsServiceAsyncClient`.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", - "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._client._transport, "_credentials") else { + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "credentialsType": None, - } + }, ) - async def insert_product_input(self, - request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: + async def insert_product_input( + self, + request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: r"""`Uploads a product input to your Merchant Center account `__. You must have a products `data @@ -364,14 +411,14 @@ async def sample_insert_product_input(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.insert_product_input] + rpc = self._client._transport._wrapped_methods[ + self._client._transport.insert_product_input + ] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) # Validate the universe domain. @@ -388,15 +435,16 @@ async def sample_insert_product_input(): # Done; return the response. return response - async def update_product_input(self, - request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, - *, - product_input: Optional[productinputs.ProductInput] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: + async def update_product_input( + self, + request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, + *, + product_input: Optional[productinputs.ProductInput] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: r"""Updates the existing product input in your Merchant Center account. After inserting, updating, or deleting a product input, @@ -525,10 +573,14 @@ async def sample_update_product_input(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [product_input, update_mask] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -544,14 +596,16 @@ async def sample_update_product_input(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.update_product_input] + rpc = self._client._transport._wrapped_methods[ + self._client._transport.update_product_input + ] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_input.name", request.product_input.name), - )), + gapic_v1.routing_header.to_grpc_metadata( + (("product_input.name", request.product_input.name),) + ), ) # Validate the universe domain. @@ -568,14 +622,15 @@ async def sample_update_product_input(): # Done; return the response. return response - async def delete_product_input(self, - request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> None: + async def delete_product_input( + self, + request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: r"""Deletes a product input from your Merchant Center account. After inserting, updating, or deleting a product input, @@ -634,10 +689,14 @@ async def sample_delete_product_input(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -651,14 +710,14 @@ async def sample_delete_product_input(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.delete_product_input] + rpc = self._client._transport._wrapped_methods[ + self._client._transport.delete_product_input + ] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Validate the universe domain. @@ -678,12 +737,13 @@ async def __aenter__(self) -> "ProductInputsServiceAsyncClient": async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ -__all__ = ( - "ProductInputsServiceAsyncClient", -) +__all__ = ("ProductInputsServiceAsyncClient",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/client.py similarity index 81% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/client.py index 8d82ce3788da..017011c2f6ee 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/client.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/client.py @@ -19,22 +19,34 @@ import logging as std_logging import os import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast +from typing import ( + Callable, + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) import warnings -from google.shopping.merchant_products_v1 import gapic_version as package_version - from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.oauth2 import service_account # type: ignore import google.protobuf +from google.shopping.merchant_products_v1 import gapic_version as package_version + try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -42,6 +54,7 @@ try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -49,10 +62,11 @@ _LOGGER = std_logging.getLogger(__name__) from google.protobuf import field_mask_pb2 # type: ignore -from google.shopping.merchant_products_v1.types import productinputs -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types -from .transports.base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +from google.shopping.merchant_products_v1.types import productinputs, products_common + +from .transports.base import DEFAULT_CLIENT_INFO, ProductInputsServiceTransport from .transports.grpc import ProductInputsServiceGrpcTransport from .transports.grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport from .transports.rest import ProductInputsServiceRestTransport @@ -65,14 +79,18 @@ class ProductInputsServiceClientMeta(type): support objects (e.g. transport) without polluting the client instance objects. """ - _transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] + + _transport_registry = ( + OrderedDict() + ) # type: Dict[str, Type[ProductInputsServiceTransport]] _transport_registry["grpc"] = ProductInputsServiceGrpcTransport _transport_registry["grpc_asyncio"] = ProductInputsServiceGrpcAsyncIOTransport _transport_registry["rest"] = ProductInputsServiceRestTransport - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[ProductInputsServiceTransport]: + def get_transport_class( + cls, + label: Optional[str] = None, + ) -> Type[ProductInputsServiceTransport]: """Returns an appropriate transport class. Args: @@ -164,8 +182,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ProductInputsServiceClient: The constructed client. """ - credentials = service_account.Credentials.from_service_account_file( - filename) + credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials return cls(*args, **kwargs) @@ -182,84 +199,122 @@ def transport(self) -> ProductInputsServiceTransport: return self._transport @staticmethod - def product_path(account: str,product: str,) -> str: + def product_path( + account: str, + product: str, + ) -> str: """Returns a fully-qualified product string.""" - return "accounts/{account}/products/{product}".format(account=account, product=product, ) + return "accounts/{account}/products/{product}".format( + account=account, + product=product, + ) @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: + def parse_product_path(path: str) -> Dict[str, str]: """Parses a product path into its component segments.""" m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def product_input_path(account: str,productinput: str,) -> str: + def product_input_path( + account: str, + productinput: str, + ) -> str: """Returns a fully-qualified product_input string.""" - return "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) + return "accounts/{account}/productInputs/{productinput}".format( + account=account, + productinput=productinput, + ) @staticmethod - def parse_product_input_path(path: str) -> Dict[str,str]: + def parse_product_input_path(path: str) -> Dict[str, str]: """Parses a product_input path into its component segments.""" - m = re.match(r"^accounts/(?P.+?)/productInputs/(?P.+?)$", path) + m = re.match( + r"^accounts/(?P.+?)/productInputs/(?P.+?)$", path + ) return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: + def parse_common_billing_account_path(path: str) -> Dict[str, str]: """Parse a billing_account path into its component segments.""" m = re.match(r"^billingAccounts/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str, ) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: + def parse_common_folder_path(path: str) -> Dict[str, str]: """Parse a folder path into its component segments.""" m = re.match(r"^folders/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str, ) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: + def parse_common_organization_path(path: str) -> Dict[str, str]: """Parse a organization path into its component segments.""" m = re.match(r"^organizations/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str, ) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) + return "projects/{project}".format( + project=project, + ) @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: + def parse_common_project_path(path: str) -> Dict[str, str]: """Parse a project path into its component segments.""" m = re.match(r"^projects/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str, ) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) + return "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: + def parse_common_location_path(path: str) -> Dict[str, str]: """Parse a location path into its component segments.""" m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): """Deprecated. Return the API endpoint and client cert source for mutual TLS. The client cert source is determined in the following order: @@ -291,16 +346,22 @@ def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_optio google.auth.exceptions.MutualTLSChannelError: If any errors happen. """ - warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", - DeprecationWarning) + warnings.warn( + "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning, + ) if client_options is None: client_options = client_options_lib.ClientOptions() use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Figure out the client cert source to use. client_cert_source = None @@ -313,7 +374,9 @@ def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_optio # Figure out which api endpoint to use. if client_options.api_endpoint is not None: api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): api_endpoint = cls.DEFAULT_MTLS_ENDPOINT else: api_endpoint = cls.DEFAULT_ENDPOINT @@ -334,13 +397,19 @@ def _read_environment_variables(): google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT is not any of ["auto", "never", "always"]. """ - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() + use_client_cert = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) return use_client_cert == "true", use_mtls_endpoint, universe_domain_env @staticmethod @@ -363,7 +432,9 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint( + api_override, client_cert_source, universe_domain, use_mtls_endpoint + ): """Return the API endpoint used by the client. Args: @@ -379,17 +450,25 @@ def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtl """ if api_override is not None: api_endpoint = api_override - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): _default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE if universe_domain != _default_universe: - raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) api_endpoint = ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT else: - api_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) + api_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=universe_domain + ) return api_endpoint @staticmethod - def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: """Return the universe domain used by the client. Args: @@ -425,15 +504,18 @@ def _validate_universe_domain(self): return True def _add_cred_info_for_auth_errors( - self, - error: core_exceptions.GoogleAPICallError + self, error: core_exceptions.GoogleAPICallError ) -> None: """Adds credential info string to error details for 401/403/404 errors. Args: error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. """ - if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: + if error.code not in [ + HTTPStatus.UNAUTHORIZED, + HTTPStatus.FORBIDDEN, + HTTPStatus.NOT_FOUND, + ]: return cred = self._transport._credentials @@ -466,12 +548,20 @@ def universe_domain(self) -> str: """ return self._universe_domain - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductInputsServiceTransport, Callable[..., ProductInputsServiceTransport]]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[ + Union[ + str, + ProductInputsServiceTransport, + Callable[..., ProductInputsServiceTransport], + ] + ] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: """Instantiates the product inputs service client. Args: @@ -526,14 +616,24 @@ def __init__(self, *, self._client_options = client_options_lib.from_dict(self._client_options) if self._client_options is None: self._client_options = client_options_lib.ClientOptions() - self._client_options = cast(client_options_lib.ClientOptions, self._client_options) + self._client_options = cast( + client_options_lib.ClientOptions, self._client_options + ) - universe_domain_opt = getattr(self._client_options, 'universe_domain', None) + universe_domain_opt = getattr(self._client_options, "universe_domain", None) - self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductInputsServiceClient._read_environment_variables() - self._client_cert_source = ProductInputsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) - self._universe_domain = ProductInputsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = ProductInputsServiceClient._read_environment_variables() + self._client_cert_source = ProductInputsServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ProductInputsServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -544,7 +644,9 @@ def __init__(self, *, api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport @@ -553,8 +655,10 @@ def __init__(self, *, if transport_provided: # transport is a ProductInputsServiceTransport instance. if credentials or self._client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") + raise ValueError( + "When providing a transport instance, " + "provide its credentials directly." + ) if self._client_options.scopes: raise ValueError( "When providing a transport instance, provide its scopes " @@ -563,20 +667,30 @@ def __init__(self, *, self._transport = cast(ProductInputsServiceTransport, transport) self._api_endpoint = self._transport.host - self._api_endpoint = (self._api_endpoint or - ProductInputsServiceClient._get_api_endpoint( + self._api_endpoint = ( + self._api_endpoint + or ProductInputsServiceClient._get_api_endpoint( self._client_options.api_endpoint, self._client_cert_source, self._universe_domain, - self._use_mtls_endpoint)) + self._use_mtls_endpoint, + ) + ) if not transport_provided: import google.auth._default # type: ignore - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) - transport_init: Union[Type[ProductInputsServiceTransport], Callable[..., ProductInputsServiceTransport]] = ( + transport_init: Union[ + Type[ProductInputsServiceTransport], + Callable[..., ProductInputsServiceTransport], + ] = ( ProductInputsServiceClient.get_transport_class(transport) if isinstance(transport, str) or transport is None else cast(Callable[..., ProductInputsServiceTransport], transport) @@ -595,27 +709,36 @@ def __init__(self, *, ) if "async" not in str(self._transport): - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER _LOGGER.debug( "Created client `google.shopping.merchant.products_v1.ProductInputsServiceClient`.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", - "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._transport, "_credentials") else { + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "credentialsType": None, - } + }, ) - def insert_product_input(self, - request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: + def insert_product_input( + self, + request: Optional[Union[productinputs.InsertProductInputRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: r"""`Uploads a product input to your Merchant Center account `__. You must have a products `data @@ -727,9 +850,7 @@ def sample_insert_product_input(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) # Validate the universe domain. @@ -746,15 +867,16 @@ def sample_insert_product_input(): # Done; return the response. return response - def update_product_input(self, - request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, - *, - product_input: Optional[productinputs.ProductInput] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> productinputs.ProductInput: + def update_product_input( + self, + request: Optional[Union[productinputs.UpdateProductInputRequest, dict]] = None, + *, + product_input: Optional[productinputs.ProductInput] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: r"""Updates the existing product input in your Merchant Center account. After inserting, updating, or deleting a product input, @@ -883,10 +1005,14 @@ def sample_update_product_input(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [product_input, update_mask] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -906,9 +1032,9 @@ def sample_update_product_input(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("product_input.name", request.product_input.name), - )), + gapic_v1.routing_header.to_grpc_metadata( + (("product_input.name", request.product_input.name),) + ), ) # Validate the universe domain. @@ -925,14 +1051,15 @@ def sample_update_product_input(): # Done; return the response. return response - def delete_product_input(self, - request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> None: + def delete_product_input( + self, + request: Optional[Union[productinputs.DeleteProductInputRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: r"""Deletes a product input from your Merchant Center account. After inserting, updating, or deleting a product input, @@ -991,10 +1118,14 @@ def sample_delete_product_input(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -1012,9 +1143,7 @@ def sample_delete_product_input(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Validate the universe domain. @@ -1042,16 +1171,11 @@ def __exit__(self, type, value, traceback): self.transport.close() - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ -__all__ = ( - "ProductInputsServiceClient", -) +__all__ = ("ProductInputsServiceClient",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/README.rst diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py similarity index 59% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py index e9792827a667..7f7fc829ba01 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/__init__.py @@ -19,20 +19,20 @@ from .base import ProductInputsServiceTransport from .grpc import ProductInputsServiceGrpcTransport from .grpc_asyncio import ProductInputsServiceGrpcAsyncIOTransport -from .rest import ProductInputsServiceRestTransport -from .rest import ProductInputsServiceRestInterceptor - +from .rest import ProductInputsServiceRestInterceptor, ProductInputsServiceRestTransport # Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[ProductInputsServiceTransport]] -_transport_registry['grpc'] = ProductInputsServiceGrpcTransport -_transport_registry['grpc_asyncio'] = ProductInputsServiceGrpcAsyncIOTransport -_transport_registry['rest'] = ProductInputsServiceRestTransport +_transport_registry = ( + OrderedDict() +) # type: Dict[str, Type[ProductInputsServiceTransport]] +_transport_registry["grpc"] = ProductInputsServiceGrpcTransport +_transport_registry["grpc_asyncio"] = ProductInputsServiceGrpcAsyncIOTransport +_transport_registry["rest"] = ProductInputsServiceRestTransport __all__ = ( - 'ProductInputsServiceTransport', - 'ProductInputsServiceGrpcTransport', - 'ProductInputsServiceGrpcAsyncIOTransport', - 'ProductInputsServiceRestTransport', - 'ProductInputsServiceRestInterceptor', + "ProductInputsServiceTransport", + "ProductInputsServiceGrpcTransport", + "ProductInputsServiceGrpcAsyncIOTransport", + "ProductInputsServiceRestTransport", + "ProductInputsServiceRestInterceptor", ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py similarity index 67% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py index ba6fa5973d53..d6f01c2399a1 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/base.py @@ -16,21 +16,22 @@ import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -from google.shopping.merchant_products_v1 import gapic_version as package_version - -import google.auth # type: ignore import google.api_core from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore +from google.oauth2 import service_account # type: ignore import google.protobuf - from google.protobuf import empty_pb2 # type: ignore + +from google.shopping.merchant_products_v1 import gapic_version as package_version from google.shopping.merchant_products_v1.types import productinputs -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ @@ -39,24 +40,23 @@ class ProductInputsServiceTransport(abc.ABC): """Abstract transport class for ProductInputsService.""" - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/content', - ) + AUTH_SCOPES = ("https://www.googleapis.com/auth/content",) - DEFAULT_HOST: str = 'merchantapi.googleapis.com' + DEFAULT_HOST: str = "merchantapi.googleapis.com" def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: + self, + *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: """Instantiate the transport. Args: @@ -92,30 +92,38 @@ def __init__( # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) elif credentials is None and not self._ignore_credentials: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + credentials = credentials.with_gdch_audience( + api_audience if api_audience else host + ) # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): credentials = credentials.with_always_use_jwt_access(True) # Save the credentials. self._credentials = credentials # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' + if ":" not in host: + host += ":443" self._host = host @property @@ -140,42 +148,42 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), - } + } def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - Union[ - productinputs.ProductInput, - Awaitable[productinputs.ProductInput] - ]]: + def insert_product_input( + self, + ) -> Callable[ + [productinputs.InsertProductInputRequest], + Union[productinputs.ProductInput, Awaitable[productinputs.ProductInput]], + ]: raise NotImplementedError() @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - Union[ - productinputs.ProductInput, - Awaitable[productinputs.ProductInput] - ]]: + def update_product_input( + self, + ) -> Callable[ + [productinputs.UpdateProductInputRequest], + Union[productinputs.ProductInput, Awaitable[productinputs.ProductInput]], + ]: raise NotImplementedError() @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: + def delete_product_input( + self, + ) -> Callable[ + [productinputs.DeleteProductInputRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: raise NotImplementedError() @property @@ -183,6 +191,4 @@ def kind(self) -> str: raise NotImplementedError() -__all__ = ( - 'ProductInputsServiceTransport', -) +__all__ = ("ProductInputsServiceTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py similarity index 84% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py index 778073cda6d8..84d1b27aa1db 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc.py @@ -16,26 +16,26 @@ import json import logging as std_logging import pickle -import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import grpc_helpers -from google.api_core import gapic_v1 -import google.auth # type: ignore +from google.api_core import gapic_v1, grpc_helpers +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message - import grpc # type: ignore import proto # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.shopping.merchant_products_v1.types import productinputs -from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, ProductInputsServiceTransport try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -45,7 +45,9 @@ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) if logging_enabled: # pragma: NO COVER request_metadata = client_call_details.metadata if isinstance(request, proto.Message): @@ -66,7 +68,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): } _LOGGER.debug( f"Sending request for {client_call_details.method}", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": str(client_call_details.method), "request": grpc_request, @@ -77,7 +79,11 @@ def intercept_unary_unary(self, continuation, client_call_details, request): if logging_enabled: # pragma: NO COVER response_metadata = response.trailing_metadata() # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) result = response.result() if isinstance(result, proto.Message): response_payload = type(result).to_json(result) @@ -92,7 +98,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): } _LOGGER.debug( f"Received response for {client_call_details.method}.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": client_call_details.method, "response": grpc_response, @@ -114,23 +120,26 @@ class ProductInputsServiceGrpcTransport(ProductInputsServiceTransport): It sends protocol buffers over the wire using gRPC (which is built on top of HTTP/2); the ``grpcio`` package must be installed. """ + _stubs: Dict[str, Callable] - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: @@ -252,19 +261,23 @@ def __init__(self, *, ) self._interceptor = _LoggingClientInterceptor() - self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: + def create_channel( + cls, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: """Create and return a gRPC channel object. Args: host (Optional[str]): The host for the channel to use. @@ -299,19 +312,20 @@ def create_channel(cls, default_scopes=cls.AUTH_SCOPES, scopes=scopes, default_host=cls.DEFAULT_HOST, - **kwargs + **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - productinputs.ProductInput]: + def insert_product_input( + self, + ) -> Callable[ + [productinputs.InsertProductInputRequest], productinputs.ProductInput + ]: r"""Return a callable for the insert product input method over gRPC. `Uploads a product input to your Merchant Center @@ -339,18 +353,20 @@ def insert_product_input(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'insert_product_input' not in self._stubs: - self._stubs['insert_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductInputsService/InsertProductInput', + if "insert_product_input" not in self._stubs: + self._stubs["insert_product_input"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductInputsService/InsertProductInput", request_serializer=productinputs.InsertProductInputRequest.serialize, response_deserializer=productinputs.ProductInput.deserialize, ) - return self._stubs['insert_product_input'] + return self._stubs["insert_product_input"] @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - productinputs.ProductInput]: + def update_product_input( + self, + ) -> Callable[ + [productinputs.UpdateProductInputRequest], productinputs.ProductInput + ]: r"""Return a callable for the update product input method over gRPC. Updates the existing product input in your Merchant @@ -369,18 +385,18 @@ def update_product_input(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'update_product_input' not in self._stubs: - self._stubs['update_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductInputsService/UpdateProductInput', + if "update_product_input" not in self._stubs: + self._stubs["update_product_input"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductInputsService/UpdateProductInput", request_serializer=productinputs.UpdateProductInputRequest.serialize, response_deserializer=productinputs.ProductInput.deserialize, ) - return self._stubs['update_product_input'] + return self._stubs["update_product_input"] @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - empty_pb2.Empty]: + def delete_product_input( + self, + ) -> Callable[[productinputs.DeleteProductInputRequest], empty_pb2.Empty]: r"""Return a callable for the delete product input method over gRPC. Deletes a product input from your Merchant Center @@ -399,13 +415,13 @@ def delete_product_input(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'delete_product_input' not in self._stubs: - self._stubs['delete_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductInputsService/DeleteProductInput', + if "delete_product_input" not in self._stubs: + self._stubs["delete_product_input"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductInputsService/DeleteProductInput", request_serializer=productinputs.DeleteProductInputRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, ) - return self._stubs['delete_product_input'] + return self._stubs["delete_product_input"] def close(self): self._logged_channel.close() @@ -415,6 +431,4 @@ def kind(self) -> str: return "grpc" -__all__ = ( - 'ProductInputsServiceGrpcTransport', -) +__all__ = ("ProductInputsServiceGrpcTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py similarity index 83% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py index 99663b8f5b2a..9f8b0b184575 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/grpc_asyncio.py @@ -15,31 +15,31 @@ # import inspect import json -import pickle import logging as std_logging -import warnings +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, grpc_helpers_async from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore +from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message - -import grpc # type: ignore -import proto # type: ignore +import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.shopping.merchant_products_v1.types import productinputs -from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, ProductInputsServiceTransport from .grpc import ProductInputsServiceGrpcTransport try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -47,9 +47,13 @@ _LOGGER = std_logging.getLogger(__name__) -class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER async def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) if logging_enabled: # pragma: NO COVER request_metadata = client_call_details.metadata if isinstance(request, proto.Message): @@ -70,7 +74,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request } _LOGGER.debug( f"Sending request for {client_call_details.method}", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": str(client_call_details.method), "request": grpc_request, @@ -81,7 +85,11 @@ async def intercept_unary_unary(self, continuation, client_call_details, request if logging_enabled: # pragma: NO COVER response_metadata = await response.trailing_metadata() # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) result = await response if isinstance(result, proto.Message): response_payload = type(result).to_json(result) @@ -96,7 +104,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request } _LOGGER.debug( f"Received response to rpc {client_call_details.method}.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": str(client_call_details.method), "response": grpc_response, @@ -123,13 +131,15 @@ class ProductInputsServiceGrpcAsyncIOTransport(ProductInputsServiceTransport): _stubs: Dict[str, Callable] = {} @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: + def create_channel( + cls, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: host (Optional[str]): The host for the channel to use. @@ -159,24 +169,26 @@ def create_channel(cls, default_scopes=cls.AUTH_SCOPES, scopes=scopes, default_host=cls.DEFAULT_HOST, - **kwargs + **kwargs, ) - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: @@ -300,7 +312,9 @@ def __init__(self, *, self._interceptor = _LoggingClientAIOInterceptor() self._grpc_channel._unary_unary_interceptors.append(self._interceptor) self._logged_channel = self._grpc_channel - self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + self._wrap_with_kind = ( + "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + ) # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @@ -315,9 +329,11 @@ def grpc_channel(self) -> aio.Channel: return self._grpc_channel @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - Awaitable[productinputs.ProductInput]]: + def insert_product_input( + self, + ) -> Callable[ + [productinputs.InsertProductInputRequest], Awaitable[productinputs.ProductInput] + ]: r"""Return a callable for the insert product input method over gRPC. `Uploads a product input to your Merchant Center @@ -345,18 +361,20 @@ def insert_product_input(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'insert_product_input' not in self._stubs: - self._stubs['insert_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductInputsService/InsertProductInput', + if "insert_product_input" not in self._stubs: + self._stubs["insert_product_input"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductInputsService/InsertProductInput", request_serializer=productinputs.InsertProductInputRequest.serialize, response_deserializer=productinputs.ProductInput.deserialize, ) - return self._stubs['insert_product_input'] + return self._stubs["insert_product_input"] @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - Awaitable[productinputs.ProductInput]]: + def update_product_input( + self, + ) -> Callable[ + [productinputs.UpdateProductInputRequest], Awaitable[productinputs.ProductInput] + ]: r"""Return a callable for the update product input method over gRPC. Updates the existing product input in your Merchant @@ -375,18 +393,20 @@ def update_product_input(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'update_product_input' not in self._stubs: - self._stubs['update_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductInputsService/UpdateProductInput', + if "update_product_input" not in self._stubs: + self._stubs["update_product_input"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductInputsService/UpdateProductInput", request_serializer=productinputs.UpdateProductInputRequest.serialize, response_deserializer=productinputs.ProductInput.deserialize, ) - return self._stubs['update_product_input'] + return self._stubs["update_product_input"] @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - Awaitable[empty_pb2.Empty]]: + def delete_product_input( + self, + ) -> Callable[ + [productinputs.DeleteProductInputRequest], Awaitable[empty_pb2.Empty] + ]: r"""Return a callable for the delete product input method over gRPC. Deletes a product input from your Merchant Center @@ -405,16 +425,16 @@ def delete_product_input(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'delete_product_input' not in self._stubs: - self._stubs['delete_product_input'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductInputsService/DeleteProductInput', + if "delete_product_input" not in self._stubs: + self._stubs["delete_product_input"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductInputsService/DeleteProductInput", request_serializer=productinputs.DeleteProductInputRequest.serialize, response_deserializer=empty_pb2.Empty.FromString, ) - return self._stubs['delete_product_input'] + return self._stubs["delete_product_input"] def _prep_wrapped_messages(self, client_info): - """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" self._wrapped_methods = { self.insert_product_input: self._wrap_method( self.insert_product_input, @@ -446,6 +466,4 @@ def kind(self) -> str: return "grpc_asyncio" -__all__ = ( - 'ProductInputsServiceGrpcAsyncIOTransport', -) +__all__ = ("ProductInputsServiceGrpcAsyncIOTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py similarity index 73% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py index d9f0259e6b43..badfb5a6ac92 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest.py @@ -13,32 +13,26 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging +import dataclasses import json # type: ignore +import logging +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings -from google.auth.transport.requests import AuthorizedSession # type: ignore -from google.auth import credentials as ga_credentials # type: ignore from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, rest_helpers, rest_streaming from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import gapic_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.requests import AuthorizedSession # type: ignore import google.protobuf - +from google.protobuf import empty_pb2 # type: ignore from google.protobuf import json_format - from requests import __version__ as requests_version -import dataclasses -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - -from google.protobuf import empty_pb2 # type: ignore from google.shopping.merchant_products_v1.types import productinputs - -from .rest_base import _BaseProductInputsServiceRestTransport from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO +from .rest_base import _BaseProductInputsServiceRestTransport try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] @@ -47,6 +41,7 @@ try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -103,7 +98,14 @@ def post_update_product_input(self, response): """ - def pre_delete_product_input(self, request: productinputs.DeleteProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.DeleteProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + + def pre_delete_product_input( + self, + request: productinputs.DeleteProductInputRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + productinputs.DeleteProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for delete_product_input Override in a subclass to manipulate the request or metadata @@ -111,7 +113,13 @@ def pre_delete_product_input(self, request: productinputs.DeleteProductInputRequ """ return request, metadata - def pre_insert_product_input(self, request: productinputs.InsertProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.InsertProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + def pre_insert_product_input( + self, + request: productinputs.InsertProductInputRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + productinputs.InsertProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for insert_product_input Override in a subclass to manipulate the request or metadata @@ -119,7 +127,9 @@ def pre_insert_product_input(self, request: productinputs.InsertProductInputRequ """ return request, metadata - def post_insert_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: + def post_insert_product_input( + self, response: productinputs.ProductInput + ) -> productinputs.ProductInput: """Post-rpc interceptor for insert_product_input DEPRECATED. Please use the `post_insert_product_input_with_metadata` @@ -132,7 +142,11 @@ def post_insert_product_input(self, response: productinputs.ProductInput) -> pro """ return response - def post_insert_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: + def post_insert_product_input_with_metadata( + self, + response: productinputs.ProductInput, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: """Post-rpc interceptor for insert_product_input Override in a subclass to read or manipulate the response or metadata after it @@ -147,7 +161,13 @@ def post_insert_product_input_with_metadata(self, response: productinputs.Produc """ return response, metadata - def pre_update_product_input(self, request: productinputs.UpdateProductInputRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.UpdateProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + def pre_update_product_input( + self, + request: productinputs.UpdateProductInputRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + productinputs.UpdateProductInputRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: """Pre-rpc interceptor for update_product_input Override in a subclass to manipulate the request or metadata @@ -155,7 +175,9 @@ def pre_update_product_input(self, request: productinputs.UpdateProductInputRequ """ return request, metadata - def post_update_product_input(self, response: productinputs.ProductInput) -> productinputs.ProductInput: + def post_update_product_input( + self, response: productinputs.ProductInput + ) -> productinputs.ProductInput: """Post-rpc interceptor for update_product_input DEPRECATED. Please use the `post_update_product_input_with_metadata` @@ -168,7 +190,11 @@ def post_update_product_input(self, response: productinputs.ProductInput) -> pro """ return response - def post_update_product_input_with_metadata(self, response: productinputs.ProductInput, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: + def post_update_product_input_with_metadata( + self, + response: productinputs.ProductInput, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[productinputs.ProductInput, Sequence[Tuple[str, Union[str, bytes]]]]: """Post-rpc interceptor for update_product_input Override in a subclass to read or manipulate the response or metadata after it @@ -203,20 +229,21 @@ class ProductInputsServiceRestTransport(_BaseProductInputsServiceRestTransport): It sends JSON representations of protocol buffers over HTTP/1.1 """ - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[ProductInputsServiceRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = "https", + interceptor: Optional[ProductInputsServiceRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: @@ -259,16 +286,20 @@ def __init__(self, *, client_info=client_info, always_use_jwt_access=always_use_jwt_access, url_scheme=url_scheme, - api_audience=api_audience + api_audience=api_audience, ) self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) + self._credentials, default_host=self.DEFAULT_HOST + ) if client_cert_source_for_mtls: self._session.configure_mtls_channel(client_cert_source_for_mtls) self._interceptor = interceptor or ProductInputsServiceRestInterceptor() self._prep_wrapped_messages(client_info) - class _DeleteProductInput(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput, ProductInputsServiceRestStub): + class _DeleteProductInput( + _BaseProductInputsServiceRestTransport._BaseDeleteProductInput, + ProductInputsServiceRestStub, + ): def __hash__(self): return hash("ProductInputsServiceRestTransport.DeleteProductInput") @@ -280,26 +311,28 @@ def _get_response( session, timeout, transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] headers = dict(metadata) - headers['Content-Type'] = 'application/json' + headers["Content-Type"] = "application/json" response = getattr(session, method)( "{host}{uri}".format(host=host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), - ) + ) return response - def __call__(self, - request: productinputs.DeleteProductInputRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ): + def __call__( + self, + request: productinputs.DeleteProductInputRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ): r"""Call the delete product input method over HTTP. Args: @@ -315,30 +348,42 @@ def __call__(self, be of type `bytes`. """ - http_options = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_http_options() + http_options = ( + _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_http_options() + ) - request, metadata = self._interceptor.pre_delete_product_input(request, metadata) - transcoded_request = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_transcoded_request(http_options, request) + request, metadata = self._interceptor.pre_delete_product_input( + request, metadata + ) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] + query_params = _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] try: request_payload = json_format.MessageToJson(request) except: request_payload = None http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), } _LOGGER.debug( f"Sending request for google.shopping.merchant.products_v1.ProductInputsServiceClient.DeleteProductInput", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": "DeleteProductInput", "httpRequest": http_request, @@ -347,14 +392,26 @@ def __call__(self, ) # Send the request - response = ProductInputsServiceRestTransport._DeleteProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + response = ( + ProductInputsServiceRestTransport._DeleteProductInput._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) - class _InsertProductInput(_BaseProductInputsServiceRestTransport._BaseInsertProductInput, ProductInputsServiceRestStub): + class _InsertProductInput( + _BaseProductInputsServiceRestTransport._BaseInsertProductInput, + ProductInputsServiceRestStub, + ): def __hash__(self): return hash("ProductInputsServiceRestTransport.InsertProductInput") @@ -366,27 +423,29 @@ def _get_response( session, timeout, transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] headers = dict(metadata) - headers['Content-Type'] = 'application/json' + headers["Content-Type"] = "application/json" response = getattr(session, method)( "{host}{uri}".format(host=host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), data=body, - ) + ) return response - def __call__(self, - request: productinputs.InsertProductInputRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> productinputs.ProductInput: + def __call__( + self, + request: productinputs.InsertProductInputRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: r"""Call the insert product input method over HTTP. Args: @@ -440,32 +499,46 @@ def __call__(self, """ - http_options = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_http_options() + http_options = ( + _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_http_options() + ) - request, metadata = self._interceptor.pre_insert_product_input(request, metadata) - transcoded_request = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_transcoded_request(http_options, request) + request, metadata = self._interceptor.pre_insert_product_input( + request, metadata + ) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_transcoded_request( + http_options, request + ) - body = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_request_body_json(transcoded_request) + body = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_request_body_json( + transcoded_request + ) # Jsonify the query params - query_params = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] + query_params = _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] try: request_payload = type(request).to_json(request) except: request_payload = None http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), } _LOGGER.debug( f"Sending request for google.shopping.merchant.products_v1.ProductInputsServiceClient.InsertProductInput", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": "InsertProductInput", "httpRequest": http_request, @@ -474,7 +547,17 @@ def __call__(self, ) # Send the request - response = ProductInputsServiceRestTransport._InsertProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) + response = ( + ProductInputsServiceRestTransport._InsertProductInput._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -489,20 +572,24 @@ def __call__(self, resp = self._interceptor.post_insert_product_input(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_insert_product_input_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + resp, _ = self._interceptor.post_insert_product_input_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER try: response_payload = productinputs.ProductInput.to_json(response) except: response_payload = None http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, } _LOGGER.debug( "Received response for google.shopping.merchant.products_v1.ProductInputsServiceClient.insert_product_input", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": "InsertProductInput", "metadata": http_response["headers"], @@ -511,7 +598,10 @@ def __call__(self, ) return resp - class _UpdateProductInput(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput, ProductInputsServiceRestStub): + class _UpdateProductInput( + _BaseProductInputsServiceRestTransport._BaseUpdateProductInput, + ProductInputsServiceRestStub, + ): def __hash__(self): return hash("ProductInputsServiceRestTransport.UpdateProductInput") @@ -523,27 +613,29 @@ def _get_response( session, timeout, transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] headers = dict(metadata) - headers['Content-Type'] = 'application/json' + headers["Content-Type"] = "application/json" response = getattr(session, method)( "{host}{uri}".format(host=host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), data=body, - ) + ) return response - def __call__(self, - request: productinputs.UpdateProductInputRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> productinputs.ProductInput: + def __call__( + self, + request: productinputs.UpdateProductInputRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> productinputs.ProductInput: r"""Call the update product input method over HTTP. Args: @@ -602,32 +694,46 @@ def __call__(self, """ - http_options = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_http_options() + http_options = ( + _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_http_options() + ) - request, metadata = self._interceptor.pre_update_product_input(request, metadata) - transcoded_request = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_transcoded_request(http_options, request) + request, metadata = self._interceptor.pre_update_product_input( + request, metadata + ) + transcoded_request = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_transcoded_request( + http_options, request + ) - body = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_request_body_json(transcoded_request) + body = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_request_body_json( + transcoded_request + ) # Jsonify the query params - query_params = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] + query_params = _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] try: request_payload = type(request).to_json(request) except: request_payload = None http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), } _LOGGER.debug( f"Sending request for google.shopping.merchant.products_v1.ProductInputsServiceClient.UpdateProductInput", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": "UpdateProductInput", "httpRequest": http_request, @@ -636,7 +742,17 @@ def __call__(self, ) # Send the request - response = ProductInputsServiceRestTransport._UpdateProductInput._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request, body) + response = ( + ProductInputsServiceRestTransport._UpdateProductInput._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -651,20 +767,24 @@ def __call__(self, resp = self._interceptor.post_update_product_input(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_update_product_input_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + resp, _ = self._interceptor.post_update_product_input_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER try: response_payload = productinputs.ProductInput.to_json(response) except: response_payload = None http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, } _LOGGER.debug( "Received response for google.shopping.merchant.products_v1.ProductInputsServiceClient.update_product_input", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductInputsService", "rpcName": "UpdateProductInput", "metadata": http_response["headers"], @@ -674,28 +794,32 @@ def __call__(self, return resp @property - def delete_product_input(self) -> Callable[ - [productinputs.DeleteProductInputRequest], - empty_pb2.Empty]: + def delete_product_input( + self, + ) -> Callable[[productinputs.DeleteProductInputRequest], empty_pb2.Empty]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._DeleteProductInput(self._session, self._host, self._interceptor) # type: ignore + return self._DeleteProductInput(self._session, self._host, self._interceptor) # type: ignore @property - def insert_product_input(self) -> Callable[ - [productinputs.InsertProductInputRequest], - productinputs.ProductInput]: + def insert_product_input( + self, + ) -> Callable[ + [productinputs.InsertProductInputRequest], productinputs.ProductInput + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._InsertProductInput(self._session, self._host, self._interceptor) # type: ignore + return self._InsertProductInput(self._session, self._host, self._interceptor) # type: ignore @property - def update_product_input(self) -> Callable[ - [productinputs.UpdateProductInputRequest], - productinputs.ProductInput]: + def update_product_input( + self, + ) -> Callable[ + [productinputs.UpdateProductInputRequest], productinputs.ProductInput + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._UpdateProductInput(self._session, self._host, self._interceptor) # type: ignore + return self._UpdateProductInput(self._session, self._host, self._interceptor) # type: ignore @property def kind(self) -> str: @@ -705,6 +829,4 @@ def close(self): self._session.close() -__all__=( - 'ProductInputsServiceRestTransport', -) +__all__ = ("ProductInputsServiceRestTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py similarity index 61% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py index 7d00878ac5a9..d798b3166ebf 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/product_inputs_service/transports/rest_base.py @@ -14,19 +14,17 @@ # limitations under the License. # import json # type: ignore -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from .base import ProductInputsServiceTransport, DEFAULT_CLIENT_INFO - import re from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union - +from google.api_core import gapic_v1, path_template from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import json_format + from google.shopping.merchant_products_v1.types import productinputs +from .base import DEFAULT_CLIENT_INFO, ProductInputsServiceTransport + class _BaseProductInputsServiceRestTransport(ProductInputsServiceTransport): """Base REST backend transport for ProductInputsService. @@ -41,14 +39,16 @@ class _BaseProductInputsServiceRestTransport(ProductInputsServiceTransport): It sends JSON representations of protocol buffers over HTTP/1.1 """ - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[Any] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = "https", + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: host (Optional[str]): @@ -72,7 +72,9 @@ def __init__(self, *, # Run the base constructor maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + raise ValueError( + f"Unexpected hostname structure: {host}" + ) # pragma: NO COVER url_match_items = maybe_url_match.groupdict() @@ -83,26 +85,32 @@ def __init__(self, *, credentials=credentials, client_info=client_info, always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience + api_audience=api_audience, ) class _BaseDeleteProductInput: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "dataSource" : "", } + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource": "", + } @classmethod def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } @staticmethod def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/products/v1/{name=accounts/*/productInputs/*}', - }, + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/products/v1/{name=accounts/*/productInputs/*}", + }, ] return http_options @@ -114,11 +122,17 @@ def _get_transcoded_request(http_options, request): @staticmethod def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_unset_required_fields(query_params)) + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseProductInputsServiceRestTransport._BaseDeleteProductInput._get_unset_required_fields( + query_params + ) + ) query_params["$alt"] = "json;enum-encoding=int" return query_params @@ -127,20 +141,26 @@ class _BaseInsertProductInput: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "dataSource" : "", } + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource": "", + } @classmethod def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } @staticmethod def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/products/v1/{parent=accounts/*}/productInputs:insert', - 'body': 'product_input', - }, + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/products/v1/{parent=accounts/*}/productInputs:insert", + "body": "product_input", + }, ] return http_options @@ -155,17 +175,23 @@ def _get_request_body_json(transcoded_request): # Jsonify the request body body = json_format.MessageToJson( - transcoded_request['body'], - use_integers_for_enums=True + transcoded_request["body"], use_integers_for_enums=True ) return body + @staticmethod def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_unset_required_fields(query_params)) + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseProductInputsServiceRestTransport._BaseInsertProductInput._get_unset_required_fields( + query_params + ) + ) query_params["$alt"] = "json;enum-encoding=int" return query_params @@ -174,20 +200,26 @@ class _BaseUpdateProductInput: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "dataSource" : "", } + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "dataSource": "", + } @classmethod def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } @staticmethod def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/products/v1/{product_input.name=accounts/*/productInputs/*}', - 'body': 'product_input', - }, + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/products/v1/{product_input.name=accounts/*/productInputs/*}", + "body": "product_input", + }, ] return http_options @@ -202,22 +234,26 @@ def _get_request_body_json(transcoded_request): # Jsonify the request body body = json_format.MessageToJson( - transcoded_request['body'], - use_integers_for_enums=True + transcoded_request["body"], use_integers_for_enums=True ) return body + @staticmethod def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_unset_required_fields(query_params)) + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseProductInputsServiceRestTransport._BaseUpdateProductInput._get_unset_required_fields( + query_params + ) + ) query_params["$alt"] = "json;enum-encoding=int" return query_params -__all__=( - '_BaseProductInputsServiceRestTransport', -) +__all__ = ("_BaseProductInputsServiceRestTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/__init__.py similarity index 91% rename from owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/__init__.py index 4513749ea12b..bff0b432a505 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/products_service/__init__.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/__init__.py @@ -13,10 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .client import ProductsServiceClient from .async_client import ProductsServiceAsyncClient +from .client import ProductsServiceClient __all__ = ( - 'ProductsServiceClient', - 'ProductsServiceAsyncClient', + "ProductsServiceClient", + "ProductsServiceAsyncClient", ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/async_client.py similarity index 82% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/async_client.py index 760a5bd1b3bd..44821fd1e849 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/async_client.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/async_client.py @@ -13,43 +13,56 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging as std_logging from collections import OrderedDict +import logging as std_logging import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union - -from google.shopping.merchant_products_v1 import gapic_version as package_version +from typing import ( + Callable, + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, +) -from google.api_core.client_options import ClientOptions from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore +from google.api_core.client_options import ClientOptions +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore import google.protobuf +from google.shopping.merchant_products_v1 import gapic_version as package_version try: OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.shopping.merchant_products_v1.services.products_service import pagers -from google.shopping.merchant_products_v1.types import products -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types -from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport + +from google.shopping.merchant_products_v1.services.products_service import pagers +from google.shopping.merchant_products_v1.types import products, products_common + from .client import ProductsServiceClient +from .transports.base import DEFAULT_CLIENT_INFO, ProductsServiceTransport +from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False _LOGGER = std_logging.getLogger(__name__) + class ProductsServiceAsyncClient: """Service to use Product resource.""" @@ -64,16 +77,30 @@ class ProductsServiceAsyncClient: product_path = staticmethod(ProductsServiceClient.product_path) parse_product_path = staticmethod(ProductsServiceClient.parse_product_path) - common_billing_account_path = staticmethod(ProductsServiceClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(ProductsServiceClient.parse_common_billing_account_path) + common_billing_account_path = staticmethod( + ProductsServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + ProductsServiceClient.parse_common_billing_account_path + ) common_folder_path = staticmethod(ProductsServiceClient.common_folder_path) - parse_common_folder_path = staticmethod(ProductsServiceClient.parse_common_folder_path) - common_organization_path = staticmethod(ProductsServiceClient.common_organization_path) - parse_common_organization_path = staticmethod(ProductsServiceClient.parse_common_organization_path) + parse_common_folder_path = staticmethod( + ProductsServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + ProductsServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + ProductsServiceClient.parse_common_organization_path + ) common_project_path = staticmethod(ProductsServiceClient.common_project_path) - parse_common_project_path = staticmethod(ProductsServiceClient.parse_common_project_path) + parse_common_project_path = staticmethod( + ProductsServiceClient.parse_common_project_path + ) common_location_path = staticmethod(ProductsServiceClient.common_location_path) - parse_common_location_path = staticmethod(ProductsServiceClient.parse_common_location_path) + parse_common_location_path = staticmethod( + ProductsServiceClient.parse_common_location_path + ) @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): @@ -109,7 +136,9 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): """Return the API endpoint and client cert source for mutual TLS. The client cert source is determined in the following order: @@ -172,12 +201,18 @@ def universe_domain(self) -> str: get_transport_class = ProductsServiceClient.get_transport_class - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[ + Union[ + str, ProductsServiceTransport, Callable[..., ProductsServiceTransport] + ] + ] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: """Instantiates the products service async client. Args: @@ -232,31 +267,39 @@ def __init__(self, *, transport=transport, client_options=client_options, client_info=client_info, - ) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER _LOGGER.debug( "Created client `google.shopping.merchant.products_v1.ProductsServiceAsyncClient`.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", - "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "universeDomain": getattr( + self._client._transport._credentials, "universe_domain", "" + ), "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._client._transport, "_credentials") else { + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._client._transport, "_credentials") + else { "serviceName": "google.shopping.merchant.products.v1.ProductsService", "credentialsType": None, - } + }, ) - async def get_product(self, - request: Optional[Union[products.GetProductRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> products.Product: + async def get_product( + self, + request: Optional[Union[products.GetProductRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: r"""Retrieves the processed product from your Merchant Center account. After inserting, updating, or deleting a product input, @@ -341,10 +384,14 @@ async def sample_get_product(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -358,14 +405,14 @@ async def sample_get_product(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.get_product] + rpc = self._client._transport._wrapped_methods[ + self._client._transport.get_product + ] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Validate the universe domain. @@ -382,14 +429,15 @@ async def sample_get_product(): # Done; return the response. return response - async def list_products(self, - request: Optional[Union[products.ListProductsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> pagers.ListProductsAsyncPager: + async def list_products( + self, + request: Optional[Union[products.ListProductsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListProductsAsyncPager: r"""Lists the processed products in your Merchant Center account. The response might contain fewer items than specified by ``pageSize``. Rely on ``pageToken`` to determine if there are @@ -458,10 +506,14 @@ async def sample_list_products(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [parent] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -475,14 +527,14 @@ async def sample_list_products(): # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._client._transport._wrapped_methods[self._client._transport.list_products] + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_products + ] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) # Validate the universe domain. @@ -516,12 +568,13 @@ async def __aenter__(self) -> "ProductsServiceAsyncClient": async def __aexit__(self, exc_type, exc, tb): await self.transport.close() -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) -if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) + +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ -__all__ = ( - "ProductsServiceAsyncClient", -) +__all__ = ("ProductsServiceAsyncClient",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/client.py similarity index 79% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/client.py index c7cf6d50815d..4ff113915733 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/client.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/client.py @@ -19,22 +19,34 @@ import logging as std_logging import os import re -from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast +from typing import ( + Callable, + Dict, + Mapping, + MutableMapping, + MutableSequence, + Optional, + Sequence, + Tuple, + Type, + Union, + cast, +) import warnings -from google.shopping.merchant_products_v1 import gapic_version as package_version - from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.oauth2 import service_account # type: ignore import google.protobuf +from google.shopping.merchant_products_v1 import gapic_version as package_version + try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] except AttributeError: # pragma: NO COVER @@ -42,17 +54,19 @@ try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False _LOGGER = std_logging.getLogger(__name__) -from google.shopping.merchant_products_v1.services.products_service import pagers -from google.shopping.merchant_products_v1.types import products -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types -from .transports.base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +from google.shopping.merchant_products_v1.services.products_service import pagers +from google.shopping.merchant_products_v1.types import products, products_common + +from .transports.base import DEFAULT_CLIENT_INFO, ProductsServiceTransport from .transports.grpc import ProductsServiceGrpcTransport from .transports.grpc_asyncio import ProductsServiceGrpcAsyncIOTransport from .transports.rest import ProductsServiceRestTransport @@ -65,14 +79,18 @@ class ProductsServiceClientMeta(type): support objects (e.g. transport) without polluting the client instance objects. """ - _transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] + + _transport_registry = ( + OrderedDict() + ) # type: Dict[str, Type[ProductsServiceTransport]] _transport_registry["grpc"] = ProductsServiceGrpcTransport _transport_registry["grpc_asyncio"] = ProductsServiceGrpcAsyncIOTransport _transport_registry["rest"] = ProductsServiceRestTransport - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[ProductsServiceTransport]: + def get_transport_class( + cls, + label: Optional[str] = None, + ) -> Type[ProductsServiceTransport]: """Returns an appropriate transport class. Args: @@ -164,8 +182,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: ProductsServiceClient: The constructed client. """ - credentials = service_account.Credentials.from_service_account_file( - filename) + credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials return cls(*args, **kwargs) @@ -182,73 +199,103 @@ def transport(self) -> ProductsServiceTransport: return self._transport @staticmethod - def product_path(account: str,product: str,) -> str: + def product_path( + account: str, + product: str, + ) -> str: """Returns a fully-qualified product string.""" - return "accounts/{account}/products/{product}".format(account=account, product=product, ) + return "accounts/{account}/products/{product}".format( + account=account, + product=product, + ) @staticmethod - def parse_product_path(path: str) -> Dict[str,str]: + def parse_product_path(path: str) -> Dict[str, str]: """Parses a product path into its component segments.""" m = re.match(r"^accounts/(?P.+?)/products/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: + def common_billing_account_path( + billing_account: str, + ) -> str: """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: + def parse_common_billing_account_path(path: str) -> Dict[str, str]: """Parse a billing_account path into its component segments.""" m = re.match(r"^billingAccounts/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_folder_path(folder: str, ) -> str: + def common_folder_path( + folder: str, + ) -> str: """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) + return "folders/{folder}".format( + folder=folder, + ) @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: + def parse_common_folder_path(path: str) -> Dict[str, str]: """Parse a folder path into its component segments.""" m = re.match(r"^folders/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_organization_path(organization: str, ) -> str: + def common_organization_path( + organization: str, + ) -> str: """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: + def parse_common_organization_path(path: str) -> Dict[str, str]: """Parse a organization path into its component segments.""" m = re.match(r"^organizations/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_project_path(project: str, ) -> str: + def common_project_path( + project: str, + ) -> str: """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) + return "projects/{project}".format( + project=project, + ) @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: + def parse_common_project_path(path: str) -> Dict[str, str]: """Parse a project path into its component segments.""" m = re.match(r"^projects/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str, ) -> str: + def common_location_path( + project: str, + location: str, + ) -> str: """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) + return "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: + def parse_common_location_path(path: str) -> Dict[str, str]: """Parse a location path into its component segments.""" m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): """Deprecated. Return the API endpoint and client cert source for mutual TLS. The client cert source is determined in the following order: @@ -280,16 +327,22 @@ def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_optio google.auth.exceptions.MutualTLSChannelError: If any errors happen. """ - warnings.warn("get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", - DeprecationWarning) + warnings.warn( + "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", + DeprecationWarning, + ) if client_options is None: client_options = client_options_lib.ClientOptions() use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Figure out the client cert source to use. client_cert_source = None @@ -302,7 +355,9 @@ def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_optio # Figure out which api endpoint to use. if client_options.api_endpoint is not None: api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): api_endpoint = cls.DEFAULT_MTLS_ENDPOINT else: api_endpoint = cls.DEFAULT_ENDPOINT @@ -323,13 +378,19 @@ def _read_environment_variables(): google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT is not any of ["auto", "never", "always"]. """ - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false").lower() + use_client_cert = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) return use_client_cert == "true", use_mtls_endpoint, universe_domain_env @staticmethod @@ -352,7 +413,9 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint( + api_override, client_cert_source, universe_domain, use_mtls_endpoint + ): """Return the API endpoint used by the client. Args: @@ -368,17 +431,25 @@ def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtl """ if api_override is not None: api_endpoint = api_override - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): _default_universe = ProductsServiceClient._DEFAULT_UNIVERSE if universe_domain != _default_universe: - raise MutualTLSChannelError(f"mTLS is not supported in any universe other than {_default_universe}.") + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) api_endpoint = ProductsServiceClient.DEFAULT_MTLS_ENDPOINT else: - api_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=universe_domain) + api_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=universe_domain + ) return api_endpoint @staticmethod - def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str: + def _get_universe_domain( + client_universe_domain: Optional[str], universe_domain_env: Optional[str] + ) -> str: """Return the universe domain used by the client. Args: @@ -414,15 +485,18 @@ def _validate_universe_domain(self): return True def _add_cred_info_for_auth_errors( - self, - error: core_exceptions.GoogleAPICallError + self, error: core_exceptions.GoogleAPICallError ) -> None: """Adds credential info string to error details for 401/403/404 errors. Args: error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. """ - if error.code not in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN, HTTPStatus.NOT_FOUND]: + if error.code not in [ + HTTPStatus.UNAUTHORIZED, + HTTPStatus.FORBIDDEN, + HTTPStatus.NOT_FOUND, + ]: return cred = self._transport._credentials @@ -455,12 +529,18 @@ def universe_domain(self) -> str: """ return self._universe_domain - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, ProductsServiceTransport, Callable[..., ProductsServiceTransport]]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[ + Union[ + str, ProductsServiceTransport, Callable[..., ProductsServiceTransport] + ] + ] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: """Instantiates the products service client. Args: @@ -515,14 +595,24 @@ def __init__(self, *, self._client_options = client_options_lib.from_dict(self._client_options) if self._client_options is None: self._client_options = client_options_lib.ClientOptions() - self._client_options = cast(client_options_lib.ClientOptions, self._client_options) + self._client_options = cast( + client_options_lib.ClientOptions, self._client_options + ) - universe_domain_opt = getattr(self._client_options, 'universe_domain', None) + universe_domain_opt = getattr(self._client_options, "universe_domain", None) - self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ProductsServiceClient._read_environment_variables() - self._client_cert_source = ProductsServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) - self._universe_domain = ProductsServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = ProductsServiceClient._read_environment_variables() + self._client_cert_source = ProductsServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ProductsServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -533,7 +623,9 @@ def __init__(self, *, api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport @@ -542,8 +634,10 @@ def __init__(self, *, if transport_provided: # transport is a ProductsServiceTransport instance. if credentials or self._client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") + raise ValueError( + "When providing a transport instance, " + "provide its credentials directly." + ) if self._client_options.scopes: raise ValueError( "When providing a transport instance, provide its scopes " @@ -552,20 +646,29 @@ def __init__(self, *, self._transport = cast(ProductsServiceTransport, transport) self._api_endpoint = self._transport.host - self._api_endpoint = (self._api_endpoint or - ProductsServiceClient._get_api_endpoint( + self._api_endpoint = ( + self._api_endpoint + or ProductsServiceClient._get_api_endpoint( self._client_options.api_endpoint, self._client_cert_source, self._universe_domain, - self._use_mtls_endpoint)) + self._use_mtls_endpoint, + ) + ) if not transport_provided: import google.auth._default # type: ignore - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) - transport_init: Union[Type[ProductsServiceTransport], Callable[..., ProductsServiceTransport]] = ( + transport_init: Union[ + Type[ProductsServiceTransport], Callable[..., ProductsServiceTransport] + ] = ( ProductsServiceClient.get_transport_class(transport) if isinstance(transport, str) or transport is None else cast(Callable[..., ProductsServiceTransport], transport) @@ -584,28 +687,37 @@ def __init__(self, *, ) if "async" not in str(self._transport): - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ): # pragma: NO COVER _LOGGER.debug( "Created client `google.shopping.merchant.products_v1.ProductsServiceClient`.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", - "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "universeDomain": getattr( + self._transport._credentials, "universe_domain", "" + ), "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", - "credentialsInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), - } if hasattr(self._transport, "_credentials") else { + "credentialsInfo": getattr( + self.transport._credentials, "get_cred_info", lambda: None + )(), + } + if hasattr(self._transport, "_credentials") + else { "serviceName": "google.shopping.merchant.products.v1.ProductsService", "credentialsType": None, - } + }, ) - def get_product(self, - request: Optional[Union[products.GetProductRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> products.Product: + def get_product( + self, + request: Optional[Union[products.GetProductRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: r"""Retrieves the processed product from your Merchant Center account. After inserting, updating, or deleting a product input, @@ -690,10 +802,14 @@ def sample_get_product(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [name] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -711,9 +827,7 @@ def sample_get_product(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Validate the universe domain. @@ -730,14 +844,15 @@ def sample_get_product(): # Done; return the response. return response - def list_products(self, - request: Optional[Union[products.ListProductsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), - ) -> pagers.ListProductsPager: + def list_products( + self, + request: Optional[Union[products.ListProductsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> pagers.ListProductsPager: r"""Lists the processed products in your Merchant Center account. The response might contain fewer items than specified by ``pageSize``. Rely on ``pageToken`` to determine if there are @@ -806,10 +921,14 @@ def sample_list_products(): # - Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. flattened_params = [parent] - has_flattened_params = len([param for param in flattened_params if param is not None]) > 0 + has_flattened_params = ( + len([param for param in flattened_params if param is not None]) > 0 + ) if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) # - Use the request object if provided (there's no risk of modifying the input as # there are no flattened fields), or create one. @@ -827,9 +946,7 @@ def sample_list_products(): # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) # Validate the universe domain. @@ -871,16 +988,11 @@ def __exit__(self, type, value, traceback): self.transport.close() - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ -__all__ = ( - "ProductsServiceClient", -) +__all__ = ("ProductsServiceClient",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/pagers.py similarity index 79% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/pagers.py index be6870244cb5..02684eca9288 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/pagers.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/pagers.py @@ -13,13 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Iterator, + Optional, + Sequence, + Tuple, + Union, +) + from google.api_core import gapic_v1 from google.api_core import retry as retries from google.api_core import retry_async as retries_async -from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator, Union + try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] - OptionalAsyncRetry = Union[retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None] + OptionalAsyncRetry = Union[ + retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None + ] except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore @@ -44,14 +58,17 @@ class ListProductsPager: attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ - def __init__(self, - method: Callable[..., products.ListProductsResponse], - request: products.ListProductsRequest, - response: products.ListProductsResponse, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): + + def __init__( + self, + method: Callable[..., products.ListProductsResponse], + request: products.ListProductsRequest, + response: products.ListProductsResponse, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + ): """Instantiate the pager. Args: @@ -84,7 +101,12 @@ def pages(self) -> Iterator[products.ListProductsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) + self._response = self._method( + self._request, + retry=self._retry, + timeout=self._timeout, + metadata=self._metadata, + ) yield self._response def __iter__(self) -> Iterator[products.Product]: @@ -92,7 +114,7 @@ def __iter__(self) -> Iterator[products.Product]: yield from page.products def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) class ListProductsAsyncPager: @@ -112,14 +134,17 @@ class ListProductsAsyncPager: attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ - def __init__(self, - method: Callable[..., Awaitable[products.ListProductsResponse]], - request: products.ListProductsRequest, - response: products.ListProductsResponse, - *, - retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()): + + def __init__( + self, + method: Callable[..., Awaitable[products.ListProductsResponse]], + request: products.ListProductsRequest, + response: products.ListProductsResponse, + *, + retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = () + ): """Instantiates the pager. Args: @@ -152,8 +177,14 @@ async def pages(self) -> AsyncIterator[products.ListProductsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, retry=self._retry, timeout=self._timeout, metadata=self._metadata) + self._response = await self._method( + self._request, + retry=self._retry, + timeout=self._timeout, + metadata=self._metadata, + ) yield self._response + def __aiter__(self) -> AsyncIterator[products.Product]: async def async_generator(): async for page in self.pages: @@ -163,4 +194,4 @@ async def async_generator(): return async_generator() def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/README.rst b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/README.rst similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/README.rst rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/README.rst diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py similarity index 67% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py index 29d073519076..f299eca615ee 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/__init__.py @@ -19,20 +19,18 @@ from .base import ProductsServiceTransport from .grpc import ProductsServiceGrpcTransport from .grpc_asyncio import ProductsServiceGrpcAsyncIOTransport -from .rest import ProductsServiceRestTransport -from .rest import ProductsServiceRestInterceptor - +from .rest import ProductsServiceRestInterceptor, ProductsServiceRestTransport # Compile a registry of transports. _transport_registry = OrderedDict() # type: Dict[str, Type[ProductsServiceTransport]] -_transport_registry['grpc'] = ProductsServiceGrpcTransport -_transport_registry['grpc_asyncio'] = ProductsServiceGrpcAsyncIOTransport -_transport_registry['rest'] = ProductsServiceRestTransport +_transport_registry["grpc"] = ProductsServiceGrpcTransport +_transport_registry["grpc_asyncio"] = ProductsServiceGrpcAsyncIOTransport +_transport_registry["rest"] = ProductsServiceRestTransport __all__ = ( - 'ProductsServiceTransport', - 'ProductsServiceGrpcTransport', - 'ProductsServiceGrpcAsyncIOTransport', - 'ProductsServiceRestTransport', - 'ProductsServiceRestInterceptor', + "ProductsServiceTransport", + "ProductsServiceGrpcTransport", + "ProductsServiceGrpcAsyncIOTransport", + "ProductsServiceRestTransport", + "ProductsServiceRestInterceptor", ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/base.py similarity index 68% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/base.py index 69f23a4a98d5..bff20e3e4ca7 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/base.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/base.py @@ -16,20 +16,21 @@ import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -from google.shopping.merchant_products_v1 import gapic_version as package_version - -import google.auth # type: ignore import google.api_core from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import retry as retries +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore +from google.oauth2 import service_account # type: ignore import google.protobuf +from google.shopping.merchant_products_v1 import gapic_version as package_version from google.shopping.merchant_products_v1.types import products -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=package_version.__version__ +) if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ @@ -38,24 +39,23 @@ class ProductsServiceTransport(abc.ABC): """Abstract transport class for ProductsService.""" - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/content', - ) + AUTH_SCOPES = ("https://www.googleapis.com/auth/content",) - DEFAULT_HOST: str = 'merchantapi.googleapis.com' + DEFAULT_HOST: str = "merchantapi.googleapis.com" def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: + self, + *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: """Instantiate the transport. Args: @@ -91,30 +91,38 @@ def __init__( # If no credentials are provided, then determine the appropriate # defaults. if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) elif credentials is None and not self._ignore_credentials: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + credentials = credentials.with_gdch_audience( + api_audience if api_audience else host + ) # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): credentials = credentials.with_always_use_jwt_access(True) # Save the credentials. self._credentials = credentials # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' + if ":" not in host: + host += ":443" self._host = host @property @@ -134,33 +142,33 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), - } + } def close(self): """Closes resources associated with the transport. - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! """ raise NotImplementedError() @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - Union[ - products.Product, - Awaitable[products.Product] - ]]: + def get_product( + self, + ) -> Callable[ + [products.GetProductRequest], + Union[products.Product, Awaitable[products.Product]], + ]: raise NotImplementedError() @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - Union[ - products.ListProductsResponse, - Awaitable[products.ListProductsResponse] - ]]: + def list_products( + self, + ) -> Callable[ + [products.ListProductsRequest], + Union[products.ListProductsResponse, Awaitable[products.ListProductsResponse]], + ]: raise NotImplementedError() @property @@ -168,6 +176,4 @@ def kind(self) -> str: raise NotImplementedError() -__all__ = ( - 'ProductsServiceTransport', -) +__all__ = ("ProductsServiceTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py similarity index 85% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py index 8c65f4a1f35c..c96d0272bb43 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/grpc.py @@ -16,25 +16,25 @@ import json import logging as std_logging import pickle -import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import grpc_helpers -from google.api_core import gapic_v1 -import google.auth # type: ignore +from google.api_core import gapic_v1, grpc_helpers +import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message - import grpc # type: ignore import proto # type: ignore from google.shopping.merchant_products_v1.types import products -from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, ProductsServiceTransport try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -44,7 +44,9 @@ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) if logging_enabled: # pragma: NO COVER request_metadata = client_call_details.metadata if isinstance(request, proto.Message): @@ -65,7 +67,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): } _LOGGER.debug( f"Sending request for {client_call_details.method}", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": str(client_call_details.method), "request": grpc_request, @@ -76,7 +78,11 @@ def intercept_unary_unary(self, continuation, client_call_details, request): if logging_enabled: # pragma: NO COVER response_metadata = response.trailing_metadata() # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) result = response.result() if isinstance(result, proto.Message): response_payload = type(result).to_json(result) @@ -91,7 +97,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): } _LOGGER.debug( f"Received response for {client_call_details.method}.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": client_call_details.method, "response": grpc_response, @@ -113,23 +119,26 @@ class ProductsServiceGrpcTransport(ProductsServiceTransport): It sends protocol buffers over the wire using gRPC (which is built on top of HTTP/2); the ``grpcio`` package must be installed. """ + _stubs: Dict[str, Callable] - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: @@ -251,19 +260,23 @@ def __init__(self, *, ) self._interceptor = _LoggingClientInterceptor() - self._logged_channel = grpc.intercept_channel(self._grpc_channel, self._interceptor) + self._logged_channel = grpc.intercept_channel( + self._grpc_channel, self._interceptor + ) # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: + def create_channel( + cls, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: """Create and return a gRPC channel object. Args: host (Optional[str]): The host for the channel to use. @@ -298,19 +311,16 @@ def create_channel(cls, default_scopes=cls.AUTH_SCOPES, scopes=scopes, default_host=cls.DEFAULT_HOST, - **kwargs + **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - products.Product]: + def get_product(self) -> Callable[[products.GetProductRequest], products.Product]: r"""Return a callable for the get product method over gRPC. Retrieves the processed product from your Merchant @@ -329,18 +339,18 @@ def get_product(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'get_product' not in self._stubs: - self._stubs['get_product'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductsService/GetProduct', + if "get_product" not in self._stubs: + self._stubs["get_product"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductsService/GetProduct", request_serializer=products.GetProductRequest.serialize, response_deserializer=products.Product.deserialize, ) - return self._stubs['get_product'] + return self._stubs["get_product"] @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - products.ListProductsResponse]: + def list_products( + self, + ) -> Callable[[products.ListProductsRequest], products.ListProductsResponse]: r"""Return a callable for the list products method over gRPC. Lists the processed products in your Merchant Center account. @@ -362,13 +372,13 @@ def list_products(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'list_products' not in self._stubs: - self._stubs['list_products'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductsService/ListProducts', + if "list_products" not in self._stubs: + self._stubs["list_products"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductsService/ListProducts", request_serializer=products.ListProductsRequest.serialize, response_deserializer=products.ListProductsResponse.deserialize, ) - return self._stubs['list_products'] + return self._stubs["list_products"] def close(self): self._logged_channel.close() @@ -378,6 +388,4 @@ def kind(self) -> str: return "grpc" -__all__ = ( - 'ProductsServiceGrpcTransport', -) +__all__ = ("ProductsServiceGrpcTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py similarity index 84% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py index 76db9834d858..e52820712ed5 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/grpc_asyncio.py @@ -15,30 +15,30 @@ # import inspect import json -import pickle import logging as std_logging -import warnings +import pickle from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import warnings -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, grpc_helpers_async from google.api_core import retry_async as retries -from google.auth import credentials as ga_credentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.protobuf.json_format import MessageToJson import google.protobuf.message - -import grpc # type: ignore -import proto # type: ignore +import grpc # type: ignore from grpc.experimental import aio # type: ignore +import proto # type: ignore from google.shopping.merchant_products_v1.types import products -from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO + +from .base import DEFAULT_CLIENT_INFO, ProductsServiceTransport from .grpc import ProductsServiceGrpcTransport try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -46,9 +46,13 @@ _LOGGER = std_logging.getLogger(__name__) -class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pragma: NO COVER +class _LoggingClientAIOInterceptor( + grpc.aio.UnaryUnaryClientInterceptor +): # pragma: NO COVER async def intercept_unary_unary(self, continuation, client_call_details, request): - logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG) + logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + std_logging.DEBUG + ) if logging_enabled: # pragma: NO COVER request_metadata = client_call_details.metadata if isinstance(request, proto.Message): @@ -69,7 +73,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request } _LOGGER.debug( f"Sending request for {client_call_details.method}", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": str(client_call_details.method), "request": grpc_request, @@ -80,7 +84,11 @@ async def intercept_unary_unary(self, continuation, client_call_details, request if logging_enabled: # pragma: NO COVER response_metadata = await response.trailing_metadata() # Convert gRPC metadata `` to list of tuples - metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None + metadata = ( + dict([(k, str(v)) for k, v in response_metadata]) + if response_metadata + else None + ) result = await response if isinstance(result, proto.Message): response_payload = type(result).to_json(result) @@ -95,7 +103,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request } _LOGGER.debug( f"Received response to rpc {client_call_details.method}.", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": str(client_call_details.method), "response": grpc_response, @@ -122,13 +130,15 @@ class ProductsServiceGrpcAsyncIOTransport(ProductsServiceTransport): _stubs: Dict[str, Callable] = {} @classmethod - def create_channel(cls, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: + def create_channel( + cls, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: """Create and return a gRPC AsyncIO channel object. Args: host (Optional[str]): The host for the channel to use. @@ -158,24 +168,26 @@ def create_channel(cls, default_scopes=cls.AUTH_SCOPES, scopes=scopes, default_host=cls.DEFAULT_HOST, - **kwargs + **kwargs, ) - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: @@ -299,7 +311,9 @@ def __init__(self, *, self._interceptor = _LoggingClientAIOInterceptor() self._grpc_channel._unary_unary_interceptors.append(self._interceptor) self._logged_channel = self._grpc_channel - self._wrap_with_kind = "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + self._wrap_with_kind = ( + "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters + ) # Wrap messages. This must be done after self._logged_channel exists self._prep_wrapped_messages(client_info) @@ -314,9 +328,9 @@ def grpc_channel(self) -> aio.Channel: return self._grpc_channel @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - Awaitable[products.Product]]: + def get_product( + self, + ) -> Callable[[products.GetProductRequest], Awaitable[products.Product]]: r"""Return a callable for the get product method over gRPC. Retrieves the processed product from your Merchant @@ -335,18 +349,20 @@ def get_product(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'get_product' not in self._stubs: - self._stubs['get_product'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductsService/GetProduct', + if "get_product" not in self._stubs: + self._stubs["get_product"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductsService/GetProduct", request_serializer=products.GetProductRequest.serialize, response_deserializer=products.Product.deserialize, ) - return self._stubs['get_product'] + return self._stubs["get_product"] @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - Awaitable[products.ListProductsResponse]]: + def list_products( + self, + ) -> Callable[ + [products.ListProductsRequest], Awaitable[products.ListProductsResponse] + ]: r"""Return a callable for the list products method over gRPC. Lists the processed products in your Merchant Center account. @@ -368,16 +384,16 @@ def list_products(self) -> Callable[ # the request. # gRPC handles serialization and deserialization, so we just need # to pass in the functions for each. - if 'list_products' not in self._stubs: - self._stubs['list_products'] = self._logged_channel.unary_unary( - '/google.shopping.merchant.products.v1.ProductsService/ListProducts', + if "list_products" not in self._stubs: + self._stubs["list_products"] = self._logged_channel.unary_unary( + "/google.shopping.merchant.products.v1.ProductsService/ListProducts", request_serializer=products.ListProductsRequest.serialize, response_deserializer=products.ListProductsResponse.deserialize, ) - return self._stubs['list_products'] + return self._stubs["list_products"] def _prep_wrapped_messages(self, client_info): - """ Precompute the wrapped methods, overriding the base class method to use async wrappers.""" + """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" self._wrapped_methods = { self.get_product: self._wrap_method( self.get_product, @@ -404,6 +420,4 @@ def kind(self) -> str: return "grpc_asyncio" -__all__ = ( - 'ProductsServiceGrpcAsyncIOTransport', -) +__all__ = ("ProductsServiceGrpcAsyncIOTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/rest.py similarity index 75% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/rest.py index 28eb46e5dca5..dde4108aebb1 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/rest.py @@ -13,31 +13,25 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging +import dataclasses import json # type: ignore +import logging +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings -from google.auth.transport.requests import AuthorizedSession # type: ignore -from google.auth import credentials as ga_credentials # type: ignore from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1, rest_helpers, rest_streaming from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import gapic_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.requests import AuthorizedSession # type: ignore import google.protobuf - from google.protobuf import json_format - from requests import __version__ as requests_version -import dataclasses -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - from google.shopping.merchant_products_v1.types import products - -from .rest_base import _BaseProductsServiceRestTransport from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO +from .rest_base import _BaseProductsServiceRestTransport try: OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] @@ -46,6 +40,7 @@ try: from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER except ImportError: # pragma: NO COVER CLIENT_LOGGING_SUPPORTED = False @@ -98,7 +93,12 @@ def post_list_products(self, response): """ - def pre_get_product(self, request: products.GetProductRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.GetProductRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + + def pre_get_product( + self, + request: products.GetProductRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[products.GetProductRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for get_product Override in a subclass to manipulate the request or metadata @@ -119,7 +119,11 @@ def post_get_product(self, response: products.Product) -> products.Product: """ return response - def post_get_product_with_metadata(self, response: products.Product, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.Product, Sequence[Tuple[str, Union[str, bytes]]]]: + def post_get_product_with_metadata( + self, + response: products.Product, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[products.Product, Sequence[Tuple[str, Union[str, bytes]]]]: """Post-rpc interceptor for get_product Override in a subclass to read or manipulate the response or metadata after it @@ -134,7 +138,11 @@ def post_get_product_with_metadata(self, response: products.Product, metadata: S """ return response, metadata - def pre_list_products(self, request: products.ListProductsRequest, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: + def pre_list_products( + self, + request: products.ListProductsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[products.ListProductsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: """Pre-rpc interceptor for list_products Override in a subclass to manipulate the request or metadata @@ -142,7 +150,9 @@ def pre_list_products(self, request: products.ListProductsRequest, metadata: Seq """ return request, metadata - def post_list_products(self, response: products.ListProductsResponse) -> products.ListProductsResponse: + def post_list_products( + self, response: products.ListProductsResponse + ) -> products.ListProductsResponse: """Post-rpc interceptor for list_products DEPRECATED. Please use the `post_list_products_with_metadata` @@ -155,7 +165,11 @@ def post_list_products(self, response: products.ListProductsResponse) -> product """ return response - def post_list_products_with_metadata(self, response: products.ListProductsResponse, metadata: Sequence[Tuple[str, Union[str, bytes]]]) -> Tuple[products.ListProductsResponse, Sequence[Tuple[str, Union[str, bytes]]]]: + def post_list_products_with_metadata( + self, + response: products.ListProductsResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[products.ListProductsResponse, Sequence[Tuple[str, Union[str, bytes]]]]: """Post-rpc interceptor for list_products Override in a subclass to read or manipulate the response or metadata after it @@ -190,20 +204,21 @@ class ProductsServiceRestTransport(_BaseProductsServiceRestTransport): It sends JSON representations of protocol buffers over HTTP/1.1 """ - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[ProductsServiceRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = "https", + interceptor: Optional[ProductsServiceRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: @@ -246,16 +261,19 @@ def __init__(self, *, client_info=client_info, always_use_jwt_access=always_use_jwt_access, url_scheme=url_scheme, - api_audience=api_audience + api_audience=api_audience, ) self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) + self._credentials, default_host=self.DEFAULT_HOST + ) if client_cert_source_for_mtls: self._session.configure_mtls_channel(client_cert_source_for_mtls) self._interceptor = interceptor or ProductsServiceRestInterceptor() self._prep_wrapped_messages(client_info) - class _GetProduct(_BaseProductsServiceRestTransport._BaseGetProduct, ProductsServiceRestStub): + class _GetProduct( + _BaseProductsServiceRestTransport._BaseGetProduct, ProductsServiceRestStub + ): def __hash__(self): return hash("ProductsServiceRestTransport.GetProduct") @@ -267,26 +285,28 @@ def _get_response( session, timeout, transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] headers = dict(metadata) - headers['Content-Type'] = 'application/json' + headers["Content-Type"] = "application/json" response = getattr(session, method)( "{host}{uri}".format(host=host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), - ) + ) return response - def __call__(self, - request: products.GetProductRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> products.Product: + def __call__( + self, + request: products.GetProductRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.Product: r"""Call the get product method over HTTP. Args: @@ -322,30 +342,40 @@ def __call__(self, """ - http_options = _BaseProductsServiceRestTransport._BaseGetProduct._get_http_options() + http_options = ( + _BaseProductsServiceRestTransport._BaseGetProduct._get_http_options() + ) request, metadata = self._interceptor.pre_get_product(request, metadata) - transcoded_request = _BaseProductsServiceRestTransport._BaseGetProduct._get_transcoded_request(http_options, request) + transcoded_request = _BaseProductsServiceRestTransport._BaseGetProduct._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = _BaseProductsServiceRestTransport._BaseGetProduct._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] + query_params = _BaseProductsServiceRestTransport._BaseGetProduct._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] try: request_payload = type(request).to_json(request) except: request_payload = None http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), } _LOGGER.debug( f"Sending request for google.shopping.merchant.products_v1.ProductsServiceClient.GetProduct", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": "GetProduct", "httpRequest": http_request, @@ -354,7 +384,14 @@ def __call__(self, ) # Send the request - response = ProductsServiceRestTransport._GetProduct._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + response = ProductsServiceRestTransport._GetProduct._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -369,20 +406,24 @@ def __call__(self, resp = self._interceptor.post_get_product(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_get_product_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + resp, _ = self._interceptor.post_get_product_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER try: response_payload = products.Product.to_json(response) except: response_payload = None http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, } _LOGGER.debug( "Received response for google.shopping.merchant.products_v1.ProductsServiceClient.get_product", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": "GetProduct", "metadata": http_response["headers"], @@ -391,7 +432,9 @@ def __call__(self, ) return resp - class _ListProducts(_BaseProductsServiceRestTransport._BaseListProducts, ProductsServiceRestStub): + class _ListProducts( + _BaseProductsServiceRestTransport._BaseListProducts, ProductsServiceRestStub + ): def __hash__(self): return hash("ProductsServiceRestTransport.ListProducts") @@ -403,26 +446,28 @@ def _get_response( session, timeout, transcoded_request, - body=None): - - uri = transcoded_request['uri'] - method = transcoded_request['method'] + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] headers = dict(metadata) - headers['Content-Type'] = 'application/json' + headers["Content-Type"] = "application/json" response = getattr(session, method)( "{host}{uri}".format(host=host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params, strict=True), - ) + ) return response - def __call__(self, - request: products.ListProductsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, Union[str, bytes]]]=(), - ) -> products.ListProductsResponse: + def __call__( + self, + request: products.ListProductsRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> products.ListProductsResponse: r"""Call the list products method over HTTP. Args: @@ -444,30 +489,40 @@ def __call__(self, """ - http_options = _BaseProductsServiceRestTransport._BaseListProducts._get_http_options() + http_options = ( + _BaseProductsServiceRestTransport._BaseListProducts._get_http_options() + ) request, metadata = self._interceptor.pre_list_products(request, metadata) - transcoded_request = _BaseProductsServiceRestTransport._BaseListProducts._get_transcoded_request(http_options, request) + transcoded_request = _BaseProductsServiceRestTransport._BaseListProducts._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = _BaseProductsServiceRestTransport._BaseListProducts._get_query_params_json(transcoded_request) - - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER - request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri']) - method = transcoded_request['method'] + query_params = _BaseProductsServiceRestTransport._BaseListProducts._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] try: request_payload = type(request).to_json(request) except: request_payload = None http_request = { - "payload": request_payload, - "requestMethod": method, - "requestUrl": request_url, - "headers": dict(metadata), + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), } _LOGGER.debug( f"Sending request for google.shopping.merchant.products_v1.ProductsServiceClient.ListProducts", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": "ListProducts", "httpRequest": http_request, @@ -476,7 +531,14 @@ def __call__(self, ) # Send the request - response = ProductsServiceRestTransport._ListProducts._get_response(self._host, metadata, query_params, self._session, timeout, transcoded_request) + response = ProductsServiceRestTransport._ListProducts._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. @@ -491,20 +553,24 @@ def __call__(self, resp = self._interceptor.post_list_products(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - resp, _ = self._interceptor.post_list_products_with_metadata(resp, response_metadata) - if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + resp, _ = self._interceptor.post_list_products_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER try: response_payload = products.ListProductsResponse.to_json(response) except: response_payload = None http_response = { - "payload": response_payload, - "headers": dict(response.headers), - "status": response.status_code, + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, } _LOGGER.debug( "Received response for google.shopping.merchant.products_v1.ProductsServiceClient.list_products", - extra = { + extra={ "serviceName": "google.shopping.merchant.products.v1.ProductsService", "rpcName": "ListProducts", "metadata": http_response["headers"], @@ -514,20 +580,18 @@ def __call__(self, return resp @property - def get_product(self) -> Callable[ - [products.GetProductRequest], - products.Product]: + def get_product(self) -> Callable[[products.GetProductRequest], products.Product]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._GetProduct(self._session, self._host, self._interceptor) # type: ignore + return self._GetProduct(self._session, self._host, self._interceptor) # type: ignore @property - def list_products(self) -> Callable[ - [products.ListProductsRequest], - products.ListProductsResponse]: + def list_products( + self, + ) -> Callable[[products.ListProductsRequest], products.ListProductsResponse]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._ListProducts(self._session, self._host, self._interceptor) # type: ignore + return self._ListProducts(self._session, self._host, self._interceptor) # type: ignore @property def kind(self) -> str: @@ -537,6 +601,4 @@ def close(self): self._session.close() -__all__=( - 'ProductsServiceRestTransport', -) +__all__ = ("ProductsServiceRestTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py similarity index 65% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py index 5ec7d1f47516..f3ed6a6ffcf6 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/services/products_service/transports/rest_base.py @@ -14,18 +14,16 @@ # limitations under the License. # import json # type: ignore -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from .base import ProductsServiceTransport, DEFAULT_CLIENT_INFO - import re from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +from google.api_core import gapic_v1, path_template +from google.protobuf import json_format from google.shopping.merchant_products_v1.types import products +from .base import DEFAULT_CLIENT_INFO, ProductsServiceTransport + class _BaseProductsServiceRestTransport(ProductsServiceTransport): """Base REST backend transport for ProductsService. @@ -40,14 +38,16 @@ class _BaseProductsServiceRestTransport(ProductsServiceTransport): It sends JSON representations of protocol buffers over HTTP/1.1 """ - def __init__(self, *, - host: str = 'merchantapi.googleapis.com', - credentials: Optional[Any] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - api_audience: Optional[str] = None, - ) -> None: + def __init__( + self, + *, + host: str = "merchantapi.googleapis.com", + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = "https", + api_audience: Optional[str] = None, + ) -> None: """Instantiate the transport. Args: host (Optional[str]): @@ -71,7 +71,9 @@ def __init__(self, *, # Run the base constructor maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + raise ValueError( + f"Unexpected hostname structure: {host}" + ) # pragma: NO COVER url_match_items = maybe_url_match.groupdict() @@ -82,26 +84,30 @@ def __init__(self, *, credentials=credentials, client_info=client_info, always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience + api_audience=api_audience, ) class _BaseGetProduct: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @classmethod def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } @staticmethod def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/products/v1/{name=accounts/*/products/*}', - }, + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/products/v1/{name=accounts/*/products/*}", + }, ] return http_options @@ -113,11 +119,17 @@ def _get_transcoded_request(http_options, request): @staticmethod def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductsServiceRestTransport._BaseGetProduct._get_unset_required_fields(query_params)) + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseProductsServiceRestTransport._BaseGetProduct._get_unset_required_fields( + query_params + ) + ) query_params["$alt"] = "json;enum-encoding=int" return query_params @@ -126,19 +138,23 @@ class _BaseListProducts: def __hash__(self): # pragma: NO COVER return NotImplementedError("__hash__ must be implemented.") - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} @classmethod def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } @staticmethod def _get_http_options(): - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/products/v1/{parent=accounts/*}/products', - }, + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/products/v1/{parent=accounts/*}/products", + }, ] return http_options @@ -150,16 +166,20 @@ def _get_transcoded_request(http_options, request): @staticmethod def _get_query_params_json(transcoded_request): - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - use_integers_for_enums=True, - )) - query_params.update(_BaseProductsServiceRestTransport._BaseListProducts._get_unset_required_fields(query_params)) + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseProductsServiceRestTransport._BaseListProducts._get_unset_required_fields( + query_params + ) + ) query_params["$alt"] = "json;enum-encoding=int" return query_params -__all__=( - '_BaseProductsServiceRestTransport', -) +__all__ = ("_BaseProductsServiceRestTransport",) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/__init__.py similarity index 61% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/__init__.py index 3adb8060e978..0c8a62be54d8 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/__init__.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/__init__.py @@ -26,11 +26,23 @@ Product, ) from .products_common import ( + AgeGroup, AutomatedDiscounts, + Availability, + CertificationAuthority, + CertificationName, CloudExportAdditionalProperties, + Condition, + CreditType, + DigitalSourceType, + EnergyEfficiencyClass, FreeShippingThreshold, + Gender, LoyaltyPoints, LoyaltyProgram, + Pause, + PickupMethod, + PickupSla, ProductAttributes, ProductCertification, ProductDetail, @@ -42,71 +54,59 @@ Shipping, ShippingDimension, ShippingWeight, + SizeSystem, + SizeType, StructuredDescription, StructuredTitle, SubscriptionCost, + SubscriptionPeriod, UnitPricingBaseMeasure, UnitPricingMeasure, - AgeGroup, - Availability, - CertificationAuthority, - CertificationName, - Condition, - CreditType, - DigitalSourceType, - EnergyEfficiencyClass, - Gender, - Pause, - PickupMethod, - PickupSla, - SizeSystem, - SizeType, - SubscriptionPeriod, ) __all__ = ( - 'DeleteProductInputRequest', - 'InsertProductInputRequest', - 'ProductInput', - 'UpdateProductInputRequest', - 'GetProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', - 'Product', - 'AutomatedDiscounts', - 'CloudExportAdditionalProperties', - 'FreeShippingThreshold', - 'LoyaltyPoints', - 'LoyaltyProgram', - 'ProductAttributes', - 'ProductCertification', - 'ProductDetail', - 'ProductDimension', - 'ProductInstallment', - 'ProductStatus', - 'ProductSustainabilityIncentive', - 'ProductWeight', - 'Shipping', - 'ShippingDimension', - 'ShippingWeight', - 'StructuredDescription', - 'StructuredTitle', - 'SubscriptionCost', - 'UnitPricingBaseMeasure', - 'UnitPricingMeasure', - 'AgeGroup', - 'Availability', - 'CertificationAuthority', - 'CertificationName', - 'Condition', - 'CreditType', - 'DigitalSourceType', - 'EnergyEfficiencyClass', - 'Gender', - 'Pause', - 'PickupMethod', - 'PickupSla', - 'SizeSystem', - 'SizeType', - 'SubscriptionPeriod', + "DeleteProductInputRequest", + "InsertProductInputRequest", + "ProductInput", + "UpdateProductInputRequest", + "GetProductRequest", + "ListProductsRequest", + "ListProductsResponse", + "Product", + "AutomatedDiscounts", + "CloudExportAdditionalProperties", + "FreeShippingThreshold", + "LoyaltyPoints", + "LoyaltyProgram", + "ProductAttributes", + "ProductCertification", + "ProductDetail", + "ProductDimension", + "ProductInstallment", + "ProductStatus", + "ProductSustainabilityIncentive", + "ProductWeight", + "Shipping", + "ShippingDimension", + "ShippingWeight", + "StructuredDescription", + "StructuredTitle", + "SubscriptionCost", + "UnitPricingBaseMeasure", + "UnitPricingMeasure", + "AgeGroup", + "Availability", + "CertificationAuthority", + "CertificationName", + "Condition", + "CreditType", + "DigitalSourceType", + "EnergyEfficiencyClass", + "Gender", + "Pause", + "PickupMethod", + "PickupSla", + "SizeSystem", + "SizeType", + "SubscriptionPeriod", ) diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/productinputs.py similarity index 97% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/productinputs.py index ef9a740519b8..5f747bb6bb44 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/productinputs.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/productinputs.py @@ -17,20 +17,19 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.protobuf import field_mask_pb2 # type: ignore -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types +import proto # type: ignore +from google.shopping.merchant_products_v1.types import products_common __protobuf__ = proto.module( - package='google.shopping.merchant.products.v1', + package="google.shopping.merchant.products.v1", manifest={ - 'ProductInput', - 'InsertProductInputRequest', - 'UpdateProductInputRequest', - 'DeleteProductInputRequest', + "ProductInput", + "InsertProductInputRequest", + "UpdateProductInputRequest", + "DeleteProductInputRequest", }, ) @@ -215,10 +214,10 @@ class InsertProductInputRequest(proto.Message): proto.STRING, number=1, ) - product_input: 'ProductInput' = proto.Field( + product_input: "ProductInput" = proto.Field( proto.MESSAGE, number=2, - message='ProductInput', + message="ProductInput", ) data_source: str = proto.Field( proto.STRING, @@ -267,10 +266,10 @@ class UpdateProductInputRequest(proto.Message): example, ``accounts/123456/dataSources/104628``. """ - product_input: 'ProductInput' = proto.Field( + product_input: "ProductInput" = proto.Field( proto.MESSAGE, number=1, - message='ProductInput', + message="ProductInput", ) update_mask: field_mask_pb2.FieldMask = proto.Field( proto.MESSAGE, diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/products.py similarity index 97% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/products.py index 120e1e11d584..4962a9d7e043 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/products.py @@ -17,19 +17,18 @@ from typing import MutableMapping, MutableSequence +from google.shopping.type.types import types import proto # type: ignore from google.shopping.merchant_products_v1.types import products_common -from google.shopping.type.types import types - __protobuf__ = proto.module( - package='google.shopping.merchant.products.v1', + package="google.shopping.merchant.products.v1", manifest={ - 'Product', - 'GetProductRequest', - 'ListProductsRequest', - 'ListProductsResponse', + "Product", + "GetProductRequest", + "ListProductsRequest", + "ListProductsResponse", }, ) @@ -258,10 +257,10 @@ class ListProductsResponse(proto.Message): def raw_page(self): return self - products: MutableSequence['Product'] = proto.RepeatedField( + products: MutableSequence["Product"] = proto.RepeatedField( proto.MESSAGE, number=1, - message='Product', + message="Product", ) next_page_token: str = proto.Field( proto.STRING, diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/products_common.py similarity index 93% rename from owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py rename to packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/products_common.py index c85c38f94b0d..664b1edcb1ef 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/google/shopping/merchant_products_v1/types/products_common.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1/types/products_common.py @@ -17,52 +17,50 @@ from typing import MutableMapping, MutableSequence -import proto # type: ignore - from google.protobuf import timestamp_pb2 # type: ignore from google.shopping.type.types import types from google.type import interval_pb2 # type: ignore - +import proto # type: ignore __protobuf__ = proto.module( - package='google.shopping.merchant.products.v1', + package="google.shopping.merchant.products.v1", manifest={ - 'SubscriptionPeriod', - 'AgeGroup', - 'Availability', - 'Condition', - 'Gender', - 'CreditType', - 'SizeSystem', - 'SizeType', - 'EnergyEfficiencyClass', - 'PickupMethod', - 'PickupSla', - 'Pause', - 'CertificationAuthority', - 'CertificationName', - 'DigitalSourceType', - 'ProductAttributes', - 'ShippingWeight', - 'ShippingDimension', - 'UnitPricingBaseMeasure', - 'UnitPricingMeasure', - 'SubscriptionCost', - 'ProductInstallment', - 'LoyaltyPoints', - 'LoyaltyProgram', - 'Shipping', - 'FreeShippingThreshold', - 'ProductDetail', - 'ProductCertification', - 'StructuredTitle', - 'StructuredDescription', - 'ProductDimension', - 'ProductWeight', - 'ProductStatus', - 'CloudExportAdditionalProperties', - 'ProductSustainabilityIncentive', - 'AutomatedDiscounts', + "SubscriptionPeriod", + "AgeGroup", + "Availability", + "Condition", + "Gender", + "CreditType", + "SizeSystem", + "SizeType", + "EnergyEfficiencyClass", + "PickupMethod", + "PickupSla", + "Pause", + "CertificationAuthority", + "CertificationName", + "DigitalSourceType", + "ProductAttributes", + "ShippingWeight", + "ShippingDimension", + "UnitPricingBaseMeasure", + "UnitPricingMeasure", + "SubscriptionCost", + "ProductInstallment", + "LoyaltyPoints", + "LoyaltyProgram", + "Shipping", + "FreeShippingThreshold", + "ProductDetail", + "ProductCertification", + "StructuredTitle", + "StructuredDescription", + "ProductDimension", + "ProductWeight", + "ProductStatus", + "CloudExportAdditionalProperties", + "ProductSustainabilityIncentive", + "AutomatedDiscounts", }, ) @@ -1007,17 +1005,17 @@ class `__ number=17, optional=True, ) - age_group: 'AgeGroup' = proto.Field( + age_group: "AgeGroup" = proto.Field( proto.ENUM, number=18, optional=True, - enum='AgeGroup', + enum="AgeGroup", ) - availability: 'Availability' = proto.Field( + availability: "Availability" = proto.Field( proto.ENUM, number=19, optional=True, - enum='Availability', + enum="Availability", ) availability_date: timestamp_pb2.Timestamp = proto.Field( proto.MESSAGE, @@ -1034,17 +1032,17 @@ class `__ number=22, optional=True, ) - condition: 'Condition' = proto.Field( + condition: "Condition" = proto.Field( proto.ENUM, number=23, optional=True, - enum='Condition', + enum="Condition", ) - gender: 'Gender' = proto.Field( + gender: "Gender" = proto.Field( proto.ENUM, number=24, optional=True, - enum='Gender', + enum="Gender", ) google_product_category: str = proto.Field( proto.STRING, @@ -1085,25 +1083,25 @@ class `__ number=139, message=types.Price, ) - installment: 'ProductInstallment' = proto.Field( + installment: "ProductInstallment" = proto.Field( proto.MESSAGE, number=32, - message='ProductInstallment', + message="ProductInstallment", ) - subscription_cost: 'SubscriptionCost' = proto.Field( + subscription_cost: "SubscriptionCost" = proto.Field( proto.MESSAGE, number=33, - message='SubscriptionCost', + message="SubscriptionCost", ) - loyalty_points: 'LoyaltyPoints' = proto.Field( + loyalty_points: "LoyaltyPoints" = proto.Field( proto.MESSAGE, number=34, - message='LoyaltyPoints', + message="LoyaltyPoints", ) - loyalty_programs: MutableSequence['LoyaltyProgram'] = proto.RepeatedField( + loyalty_programs: MutableSequence["LoyaltyProgram"] = proto.RepeatedField( proto.MESSAGE, number=136, - message='LoyaltyProgram', + message="LoyaltyProgram", ) product_types: MutableSequence[str] = proto.RepeatedField( proto.STRING, @@ -1124,55 +1122,57 @@ class `__ number=38, optional=True, ) - product_height: 'ProductDimension' = proto.Field( + product_height: "ProductDimension" = proto.Field( proto.MESSAGE, number=119, - message='ProductDimension', + message="ProductDimension", ) - product_length: 'ProductDimension' = proto.Field( + product_length: "ProductDimension" = proto.Field( proto.MESSAGE, number=120, - message='ProductDimension', + message="ProductDimension", ) - product_width: 'ProductDimension' = proto.Field( + product_width: "ProductDimension" = proto.Field( proto.MESSAGE, number=121, - message='ProductDimension', + message="ProductDimension", ) - product_weight: 'ProductWeight' = proto.Field( + product_weight: "ProductWeight" = proto.Field( proto.MESSAGE, number=122, - message='ProductWeight', + message="ProductWeight", ) - shipping: MutableSequence['Shipping'] = proto.RepeatedField( + shipping: MutableSequence["Shipping"] = proto.RepeatedField( proto.MESSAGE, number=39, - message='Shipping', + message="Shipping", ) - free_shipping_threshold: MutableSequence['FreeShippingThreshold'] = proto.RepeatedField( + free_shipping_threshold: MutableSequence[ + "FreeShippingThreshold" + ] = proto.RepeatedField( proto.MESSAGE, number=135, - message='FreeShippingThreshold', + message="FreeShippingThreshold", ) - shipping_weight: 'ShippingWeight' = proto.Field( + shipping_weight: "ShippingWeight" = proto.Field( proto.MESSAGE, number=40, - message='ShippingWeight', + message="ShippingWeight", ) - shipping_length: 'ShippingDimension' = proto.Field( + shipping_length: "ShippingDimension" = proto.Field( proto.MESSAGE, number=41, - message='ShippingDimension', + message="ShippingDimension", ) - shipping_width: 'ShippingDimension' = proto.Field( + shipping_width: "ShippingDimension" = proto.Field( proto.MESSAGE, number=42, - message='ShippingDimension', + message="ShippingDimension", ) - shipping_height: 'ShippingDimension' = proto.Field( + shipping_height: "ShippingDimension" = proto.Field( proto.MESSAGE, number=43, - message='ShippingDimension', + message="ShippingDimension", ) max_handling_time: int = proto.Field( proto.INT64, @@ -1199,44 +1199,44 @@ class `__ number=48, optional=True, ) - size_system: 'SizeSystem' = proto.Field( + size_system: "SizeSystem" = proto.Field( proto.ENUM, number=49, optional=True, - enum='SizeSystem', + enum="SizeSystem", ) - size_types: MutableSequence['SizeType'] = proto.RepeatedField( + size_types: MutableSequence["SizeType"] = proto.RepeatedField( proto.ENUM, number=50, - enum='SizeType', + enum="SizeType", ) - energy_efficiency_class: 'EnergyEfficiencyClass' = proto.Field( + energy_efficiency_class: "EnergyEfficiencyClass" = proto.Field( proto.ENUM, number=53, optional=True, - enum='EnergyEfficiencyClass', + enum="EnergyEfficiencyClass", ) - min_energy_efficiency_class: 'EnergyEfficiencyClass' = proto.Field( + min_energy_efficiency_class: "EnergyEfficiencyClass" = proto.Field( proto.ENUM, number=54, optional=True, - enum='EnergyEfficiencyClass', + enum="EnergyEfficiencyClass", ) - max_energy_efficiency_class: 'EnergyEfficiencyClass' = proto.Field( + max_energy_efficiency_class: "EnergyEfficiencyClass" = proto.Field( proto.ENUM, number=55, optional=True, - enum='EnergyEfficiencyClass', + enum="EnergyEfficiencyClass", ) - unit_pricing_measure: 'UnitPricingMeasure' = proto.Field( + unit_pricing_measure: "UnitPricingMeasure" = proto.Field( proto.MESSAGE, number=56, - message='UnitPricingMeasure', + message="UnitPricingMeasure", ) - unit_pricing_base_measure: 'UnitPricingBaseMeasure' = proto.Field( + unit_pricing_base_measure: "UnitPricingBaseMeasure" = proto.Field( proto.MESSAGE, number=57, - message='UnitPricingBaseMeasure', + message="UnitPricingBaseMeasure", ) multipack: int = proto.Field( proto.INT64, @@ -1262,10 +1262,10 @@ class `__ number=62, message=types.Price, ) - product_details: MutableSequence['ProductDetail'] = proto.RepeatedField( + product_details: MutableSequence["ProductDetail"] = proto.RepeatedField( proto.MESSAGE, number=63, - message='ProductDetail', + message="ProductDetail", ) product_highlights: MutableSequence[str] = proto.RepeatedField( proto.STRING, @@ -1299,17 +1299,17 @@ class `__ proto.STRING, number=70, ) - pickup_method: 'PickupMethod' = proto.Field( + pickup_method: "PickupMethod" = proto.Field( proto.ENUM, number=80, optional=True, - enum='PickupMethod', + enum="PickupMethod", ) - pickup_sla: 'PickupSla' = proto.Field( + pickup_sla: "PickupSla" = proto.Field( proto.ENUM, number=81, optional=True, - enum='PickupSla', + enum="PickupSla", ) link_template: str = proto.Field( proto.STRING, @@ -1346,12 +1346,16 @@ class `__ number=75, optional=True, ) - included_destinations: MutableSequence[types.Destination.DestinationEnum] = proto.RepeatedField( + included_destinations: MutableSequence[ + types.Destination.DestinationEnum + ] = proto.RepeatedField( proto.ENUM, number=76, enum=types.Destination.DestinationEnum, ) - excluded_destinations: MutableSequence[types.Destination.DestinationEnum] = proto.RepeatedField( + excluded_destinations: MutableSequence[ + types.Destination.DestinationEnum + ] = proto.RepeatedField( proto.ENUM, number=77, enum=types.Destination.DestinationEnum, @@ -1365,52 +1369,56 @@ class `__ number=1, optional=True, ) - pause: 'Pause' = proto.Field( + pause: "Pause" = proto.Field( proto.ENUM, number=13, optional=True, - enum='Pause', + enum="Pause", ) lifestyle_image_links: MutableSequence[str] = proto.RepeatedField( proto.STRING, number=14, ) - cloud_export_additional_properties: MutableSequence['CloudExportAdditionalProperties'] = proto.RepeatedField( + cloud_export_additional_properties: MutableSequence[ + "CloudExportAdditionalProperties" + ] = proto.RepeatedField( proto.MESSAGE, number=84, - message='CloudExportAdditionalProperties', + message="CloudExportAdditionalProperties", ) virtual_model_link: str = proto.Field( proto.STRING, number=130, optional=True, ) - certifications: MutableSequence['ProductCertification'] = proto.RepeatedField( + certifications: MutableSequence["ProductCertification"] = proto.RepeatedField( proto.MESSAGE, number=123, - message='ProductCertification', + message="ProductCertification", ) - structured_title: 'StructuredTitle' = proto.Field( + structured_title: "StructuredTitle" = proto.Field( proto.MESSAGE, number=132, optional=True, - message='StructuredTitle', + message="StructuredTitle", ) - structured_description: 'StructuredDescription' = proto.Field( + structured_description: "StructuredDescription" = proto.Field( proto.MESSAGE, number=133, optional=True, - message='StructuredDescription', + message="StructuredDescription", ) auto_pricing_min_price: types.Price = proto.Field( proto.MESSAGE, number=124, message=types.Price, ) - sustainability_incentives: MutableSequence['ProductSustainabilityIncentive'] = proto.RepeatedField( + sustainability_incentives: MutableSequence[ + "ProductSustainabilityIncentive" + ] = proto.RepeatedField( proto.MESSAGE, number=138, - message='ProductSustainabilityIncentive', + message="ProductSustainabilityIncentive", ) @@ -1513,10 +1521,10 @@ class SubscriptionCost(proto.Message): subscription period. """ - period: 'SubscriptionPeriod' = proto.Field( + period: "SubscriptionPeriod" = proto.Field( proto.ENUM, number=1, - enum='SubscriptionPeriod', + enum="SubscriptionPeriod", ) period_length: int = proto.Field( proto.INT64, @@ -1566,11 +1574,11 @@ class ProductInstallment(proto.Message): optional=True, message=types.Price, ) - credit_type: 'CreditType' = proto.Field( + credit_type: "CreditType" = proto.Field( proto.ENUM, number=4, optional=True, - enum='CreditType', + enum="CreditType", ) @@ -1934,17 +1942,17 @@ class ProductCertification(proto.Message): This field is a member of `oneof`_ ``_certification_value``. """ - certification_authority: 'CertificationAuthority' = proto.Field( + certification_authority: "CertificationAuthority" = proto.Field( proto.ENUM, number=1, optional=True, - enum='CertificationAuthority', + enum="CertificationAuthority", ) - certification_name: 'CertificationName' = proto.Field( + certification_name: "CertificationName" = proto.Field( proto.ENUM, number=2, optional=True, - enum='CertificationName', + enum="CertificationName", ) certification_code: str = proto.Field( proto.STRING, @@ -1976,11 +1984,11 @@ class StructuredTitle(proto.Message): This field is a member of `oneof`_ ``_content``. """ - digital_source_type: 'DigitalSourceType' = proto.Field( + digital_source_type: "DigitalSourceType" = proto.Field( proto.ENUM, number=1, optional=True, - enum='DigitalSourceType', + enum="DigitalSourceType", ) content: str = proto.Field( proto.STRING, @@ -2009,11 +2017,11 @@ class StructuredDescription(proto.Message): This field is a member of `oneof`_ ``_content``. """ - digital_source_type: 'DigitalSourceType' = proto.Field( + digital_source_type: "DigitalSourceType" = proto.Field( proto.ENUM, number=1, optional=True, - enum='DigitalSourceType', + enum="DigitalSourceType", ) content: str = proto.Field( proto.STRING, @@ -2157,6 +2165,7 @@ class ItemLevelIssue(proto.Message): List of country codes (ISO 3166-1 alpha-2) where issue applies to the offer. """ + class Severity(proto.Enum): r"""How the issue affects the serving of the product. @@ -2181,10 +2190,10 @@ class Severity(proto.Enum): proto.STRING, number=1, ) - severity: 'ProductStatus.ItemLevelIssue.Severity' = proto.Field( + severity: "ProductStatus.ItemLevelIssue.Severity" = proto.Field( proto.ENUM, number=2, - enum='ProductStatus.ItemLevelIssue.Severity', + enum="ProductStatus.ItemLevelIssue.Severity", ) resolution: str = proto.Field( proto.STRING, @@ -2365,6 +2374,7 @@ class ProductSustainabilityIncentive(proto.Message): This field is a member of `oneof`_ ``_type``. """ + class Type(proto.Enum): r"""Types of supported sustainability incentive programs. @@ -2392,13 +2402,13 @@ class Type(proto.Enum): amount: types.Price = proto.Field( proto.MESSAGE, number=2, - oneof='value', + oneof="value", message=types.Price, ) percentage: float = proto.Field( proto.DOUBLE, number=3, - oneof='value', + oneof="value", ) type_: Type = proto.Field( proto.ENUM, diff --git a/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1beta/gapic_version.py b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1beta/gapic_version.py index 9650dd3a514f..20a9cd975b02 100644 --- a/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1beta/gapic_version.py +++ b/packages/google-shopping-merchant-products/google/shopping/merchant_products_v1beta/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.2.6" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_async.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_delete_product_input_sync.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_async.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_insert_product_input_sync.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_async.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_product_inputs_service_update_product_input_sync.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_async.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_get_product_sync.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_async.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py b/packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py rename to packages/google-shopping-merchant-products/samples/generated_samples/merchantapi_v1_generated_products_service_list_products_sync.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json b/packages/google-shopping-merchant-products/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json rename to packages/google-shopping-merchant-products/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1.json diff --git a/packages/google-shopping-merchant-products/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json b/packages/google-shopping-merchant-products/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json index 4f9524ef1ed4..efc245a8341b 100644 --- a/packages/google-shopping-merchant-products/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json +++ b/packages/google-shopping-merchant-products/samples/generated_samples/snippet_metadata_google.shopping.merchant.products.v1beta.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-shopping-merchant-products", - "version": "0.2.6" + "version": "0.1.0" }, "snippets": [ { diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/scripts/fixup_merchant_products_v1_keywords.py b/packages/google-shopping-merchant-products/scripts/fixup_merchant_products_v1_keywords.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1/scripts/fixup_merchant_products_v1_keywords.py rename to packages/google-shopping-merchant-products/scripts/fixup_merchant_products_v1_keywords.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/__init__.py b/packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/__init__.py similarity index 100% rename from owl-bot-staging/google-shopping-merchant-products/v1beta/google/shopping/merchant_products_v1beta/services/__init__.py rename to packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/__init__.py diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py b/packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py similarity index 61% rename from owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py rename to packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py index 5103ab754262..f124fcb45f65 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py +++ b/packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/test_product_inputs_service.py @@ -14,6 +14,7 @@ # limitations under the License. # import os + # try/except added for compatibility with python < 3.8 try: from unittest import mock @@ -21,49 +22,46 @@ except ImportError: # pragma: NO COVER import mock -import grpc -from grpc.experimental import aio -from collections.abc import Iterable, AsyncIterable -from google.protobuf import json_format +from collections.abc import AsyncIterable, Iterable import json import math -import pytest + from google.api_core import api_core_version -from proto.marshal.rules.dates import DurationRule, TimestampRule +from google.protobuf import json_format +import grpc +from grpc.experimental import aio from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest +from proto.marshal.rules.dates import DurationRule, TimestampRule +import pytest +from requests import PreparedRequest, Request, Response from requests.sessions import Session -from google.protobuf import json_format try: from google.auth.aio import credentials as ga_credentials_async + HAS_GOOGLE_AUTH_AIO = True -except ImportError: # pragma: NO COVER +except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False +from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import path_template from google.api_core import retry as retries +import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore -from google.shopping.merchant_products_v1.services.product_inputs_service import ProductInputsServiceAsyncClient -from google.shopping.merchant_products_v1.services.product_inputs_service import ProductInputsServiceClient -from google.shopping.merchant_products_v1.services.product_inputs_service import transports -from google.shopping.merchant_products_v1.types import productinputs -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types from google.type import interval_pb2 # type: ignore -import google.auth - +from google.shopping.merchant_products_v1.services.product_inputs_service import ( + ProductInputsServiceAsyncClient, + ProductInputsServiceClient, + transports, +) +from google.shopping.merchant_products_v1.types import productinputs, products_common CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -78,9 +76,11 @@ async def mock_async_gen(data, chunk_size=1): chunk = data[i : i + chunk_size] yield chunk.encode("utf-8") + def client_cert_source_callback(): return b"cert bytes", b"key bytes" + # TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. # See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. def async_anonymous_credentials(): @@ -88,17 +88,27 @@ def async_anonymous_credentials(): return ga_credentials_async.AnonymousCredentials() return ga_credentials.AnonymousCredentials() + # If default endpoint is localhost, then default mtls endpoint will be the same. # This method modifies the default endpoint so the client can produce a different # mtls endpoint for endpoint testing purposes. def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + # If default endpoint template is localhost, then default mtls endpoint will be the same. # This method modifies the default endpoint template so the client can produce a different # mtls endpoint for endpoint testing purposes. def modify_default_endpoint_template(client): - return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE + return ( + "test.{UNIVERSE_DOMAIN}" + if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) + else client._DEFAULT_ENDPOINT_TEMPLATE + ) def test__get_default_mtls_endpoint(): @@ -109,101 +119,243 @@ def test__get_default_mtls_endpoint(): non_googleapi = "api.example.com" assert ProductInputsServiceClient._get_default_mtls_endpoint(None) is None - assert ProductInputsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductInputsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ProductInputsServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + ProductInputsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + ProductInputsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + ProductInputsServiceClient._get_default_mtls_endpoint(non_googleapi) + == non_googleapi + ) + def test__read_environment_variables(): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + assert ProductInputsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - assert ProductInputsServiceClient._read_environment_variables() == (True, "auto", None) + assert ProductInputsServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + assert ProductInputsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): with pytest.raises(ValueError) as excinfo: ProductInputsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "never", None) + assert ProductInputsServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "always", None) + assert ProductInputsServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", None) + assert ProductInputsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError) as excinfo: ProductInputsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): - assert ProductInputsServiceClient._read_environment_variables() == (False, "auto", "foo.com") + assert ProductInputsServiceClient._read_environment_variables() == ( + False, + "auto", + "foo.com", + ) + def test__get_client_cert_source(): mock_provided_cert_source = mock.Mock() mock_default_cert_source = mock.Mock() assert ProductInputsServiceClient._get_client_cert_source(None, False) is None - assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None - assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source + assert ( + ProductInputsServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ProductInputsServiceClient._get_client_cert_source( + mock_provided_cert_source, True + ) + == mock_provided_cert_source + ) - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): - assert ProductInputsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source - assert ProductInputsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", return_value=True + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_default_cert_source, + ): + assert ( + ProductInputsServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ProductInputsServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) + +@mock.patch.object( + ProductInputsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceClient), +) +@mock.patch.object( + ProductInputsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceAsyncClient), +) def test__get_api_endpoint(): api_override = "foo.com" mock_client_cert_source = mock.Mock() default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) mock_universe = "bar.com" - mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) - assert ProductInputsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override - assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint - assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductInputsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint - assert ProductInputsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint + assert ( + ProductInputsServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ProductInputsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ProductInputsServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ProductInputsServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ProductInputsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ProductInputsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ProductInputsServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ProductInputsServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) with pytest.raises(MutualTLSChannelError) as excinfo: - ProductInputsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") - assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." + ProductInputsServiceClient._get_api_endpoint( + None, mock_client_cert_source, mock_universe, "auto" + ) + assert ( + str(excinfo.value) + == "mTLS is not supported in any universe other than googleapis.com." + ) def test__get_universe_domain(): client_universe_domain = "foo.com" universe_domain_env = "bar.com" - assert ProductInputsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain - assert ProductInputsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env - assert ProductInputsServiceClient._get_universe_domain(None, None) == ProductInputsServiceClient._DEFAULT_UNIVERSE + assert ( + ProductInputsServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ProductInputsServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ProductInputsServiceClient._get_universe_domain(None, None) + == ProductInputsServiceClient._DEFAULT_UNIVERSE + ) with pytest.raises(ValueError) as excinfo: ProductInputsServiceClient._get_universe_domain("", None) assert str(excinfo.value) == "Universe Domain cannot be an empty string." -@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ - (401, CRED_INFO_JSON, True), - (403, CRED_INFO_JSON, True), - (404, CRED_INFO_JSON, True), - (500, CRED_INFO_JSON, False), - (401, None, False), - (403, None, False), - (404, None, False), - (500, None, False) -]) + +@pytest.mark.parametrize( + "error_code,cred_info_json,show_cred_info", + [ + (401, CRED_INFO_JSON, True), + (403, CRED_INFO_JSON, True), + (404, CRED_INFO_JSON, True), + (500, CRED_INFO_JSON, False), + (401, None, False), + (403, None, False), + (404, None, False), + (500, None, False), + ], +) def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): cred = mock.Mock(["get_cred_info"]) cred.get_cred_info = mock.Mock(return_value=cred_info_json) @@ -219,7 +371,8 @@ def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_in else: assert error.details == ["foo"] -@pytest.mark.parametrize("error_code", [401,403,404,500]) + +@pytest.mark.parametrize("error_code", [401, 403, 404, 500]) def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): cred = mock.Mock([]) assert not hasattr(cred, "get_cred_info") @@ -232,14 +385,22 @@ def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): client._add_cred_info_for_auth_errors(error) assert error.details == [] -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductInputsServiceClient, "grpc"), - (ProductInputsServiceAsyncClient, "grpc_asyncio"), - (ProductInputsServiceClient, "rest"), -]) -def test_product_inputs_service_client_from_service_account_info(client_class, transport_name): + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ProductInputsServiceClient, "grpc"), + (ProductInputsServiceAsyncClient, "grpc_asyncio"), + (ProductInputsServiceClient, "rest"), + ], +) +def test_product_inputs_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: factory.return_value = creds info = {"valid": True} client = client_class.from_service_account_info(info, transport=transport_name) @@ -247,52 +408,70 @@ def test_product_inputs_service_client_from_service_account_info(client_class, t assert isinstance(client, client_class) assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' + "merchantapi.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com" ) -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductInputsServiceGrpcTransport, "grpc"), - (transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.ProductInputsServiceRestTransport, "rest"), -]) -def test_product_inputs_service_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.ProductInputsServiceGrpcTransport, "grpc"), + (transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.ProductInputsServiceRestTransport, "rest"), + ], +) +def test_product_inputs_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: creds = service_account.Credentials(None, None, None) transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: creds = service_account.Credentials(None, None, None) transport = transport_class(credentials=creds, always_use_jwt_access=False) use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductInputsServiceClient, "grpc"), - (ProductInputsServiceAsyncClient, "grpc_asyncio"), - (ProductInputsServiceClient, "rest"), -]) -def test_product_inputs_service_client_from_service_account_file(client_class, transport_name): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ProductInputsServiceClient, "grpc"), + (ProductInputsServiceAsyncClient, "grpc_asyncio"), + (ProductInputsServiceClient, "rest"), + ], +) +def test_product_inputs_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' + "merchantapi.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com" ) @@ -308,30 +487,53 @@ def test_product_inputs_service_client_get_transport_class(): assert transport == transports.ProductInputsServiceGrpcTransport -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), -]) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) -def test_product_inputs_service_client_client_options(client_class, transport_class, transport_name): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ProductInputsServiceClient, + transports.ProductInputsServiceGrpcTransport, + "grpc", + ), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ( + ProductInputsServiceClient, + transports.ProductInputsServiceRestTransport, + "rest", + ), + ], +) +@mock.patch.object( + ProductInputsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceClient), +) +@mock.patch.object( + ProductInputsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceAsyncClient), +) +def test_product_inputs_service_client_client_options( + client_class, transport_class, transport_name +): # Check that if channel is provided we won't create a new one. - with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) + with mock.patch.object(ProductInputsServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() # Check that if channel is provided via str we will create a new one. - with mock.patch.object(ProductInputsServiceClient, 'get_transport_class') as gtc: + with mock.patch.object(ProductInputsServiceClient, "get_transport_class") as gtc: client = client_class(transport=transport_name) gtc.assert_called() # Check the case api_endpoint is provided. options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( @@ -349,13 +551,15 @@ def test_product_inputs_service_client_client_options(client_class, transport_cl # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "never". with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -367,7 +571,7 @@ def test_product_inputs_service_client_client_options(client_class, transport_cl # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "always". with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name) patched.assert_called_once_with( @@ -387,23 +591,33 @@ def test_product_inputs_service_client_client_options(client_class, transport_cl with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError) as excinfo: client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): with pytest.raises(ValueError) as excinfo: client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id="octopus", @@ -412,48 +626,102 @@ def test_product_inputs_service_client_client_options(client_class, transport_cl api_audience=None, ) # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: + options = client_options.ClientOptions( + api_audience="https://language.googleapis.com" + ) + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "true"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", "false"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "true"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", "false"), -]) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) + api_audience="https://language.googleapis.com", + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + ProductInputsServiceClient, + transports.ProductInputsServiceGrpcTransport, + "grpc", + "true", + ), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + ProductInputsServiceClient, + transports.ProductInputsServiceGrpcTransport, + "grpc", + "false", + ), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ( + ProductInputsServiceClient, + transports.ProductInputsServiceRestTransport, + "rest", + "true", + ), + ( + ProductInputsServiceClient, + transports.ProductInputsServiceRestTransport, + "rest", + "false", + ), + ], +) +@mock.patch.object( + ProductInputsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceClient), +) +@mock.patch.object( + ProductInputsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceAsyncClient), +) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_product_inputs_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): +def test_product_inputs_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. # Check the case client_cert_source is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ) else: expected_client_cert_source = client_cert_source_callback expected_host = client.DEFAULT_MTLS_ENDPOINT @@ -472,12 +740,22 @@ def test_product_inputs_service_client_mtls_env_auto(client_class, transport_cla # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): if use_client_cert_env == "false": - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ) expected_client_cert_source = None else: expected_host = client.DEFAULT_MTLS_ENDPOINT @@ -498,15 +776,22 @@ def test_product_inputs_service_client_mtls_env_auto(client_class, transport_cla ) # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): patched.return_value = None client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -516,19 +801,31 @@ def test_product_inputs_service_client_mtls_env_auto(client_class, transport_cla ) -@pytest.mark.parametrize("client_class", [ - ProductInputsServiceClient, ProductInputsServiceAsyncClient -]) -@mock.patch.object(ProductInputsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductInputsServiceAsyncClient)) +@pytest.mark.parametrize( + "client_class", [ProductInputsServiceClient, ProductInputsServiceAsyncClient] +) +@mock.patch.object( + ProductInputsServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductInputsServiceClient), +) +@mock.patch.object( + ProductInputsServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductInputsServiceAsyncClient), +) def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_class): mock_client_cert_source = mock.Mock() # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) assert api_endpoint == mock_api_endpoint assert cert_source == mock_client_cert_source @@ -536,8 +833,12 @@ def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): mock_client_cert_source = mock.Mock() mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) assert api_endpoint == mock_api_endpoint assert cert_source is None @@ -555,16 +856,28 @@ def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_ # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() assert api_endpoint == client_class.DEFAULT_ENDPOINT assert cert_source is None # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -574,34 +887,62 @@ def test_product_inputs_service_client_get_mtls_endpoint_and_cert_source(client_ with pytest.raises(MutualTLSChannelError) as excinfo: client_class.get_mtls_endpoint_and_cert_source() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): with pytest.raises(ValueError) as excinfo: client_class.get_mtls_endpoint_and_cert_source() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + -@pytest.mark.parametrize("client_class", [ - ProductInputsServiceClient, ProductInputsServiceAsyncClient -]) -@mock.patch.object(ProductInputsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceClient)) -@mock.patch.object(ProductInputsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductInputsServiceAsyncClient)) +@pytest.mark.parametrize( + "client_class", [ProductInputsServiceClient, ProductInputsServiceAsyncClient] +) +@mock.patch.object( + ProductInputsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceClient), +) +@mock.patch.object( + ProductInputsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductInputsServiceAsyncClient), +) def test_product_inputs_service_client_client_api_endpoint(client_class): mock_client_cert_source = client_cert_source_callback api_override = "foo.com" default_universe = ProductInputsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + default_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) mock_universe = "bar.com" - mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + mock_endpoint = ProductInputsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", # use ClientOptions.api_endpoint as the api endpoint regardless. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + with mock.patch( + "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" + ): + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=api_override + ) + client = client_class( + client_options=options, + credentials=ga_credentials.AnonymousCredentials(), + ) assert client.api_endpoint == api_override # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", @@ -624,11 +965,19 @@ def test_product_inputs_service_client_client_api_endpoint(client_class): universe_exists = hasattr(options, "universe_domain") if universe_exists: options = client_options.ClientOptions(universe_domain=mock_universe) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) else: - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) - assert client.universe_domain == (mock_universe if universe_exists else default_universe) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + assert client.api_endpoint == ( + mock_endpoint if universe_exists else default_endpoint + ) + assert client.universe_domain == ( + mock_universe if universe_exists else default_universe + ) # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. @@ -636,27 +985,48 @@ def test_product_inputs_service_client_client_api_endpoint(client_class): if hasattr(options, "universe_domain"): delattr(options, "universe_domain") with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) assert client.api_endpoint == default_endpoint -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc"), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest"), -]) -def test_product_inputs_service_client_client_options_scopes(client_class, transport_class, transport_name): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ProductInputsServiceClient, + transports.ProductInputsServiceGrpcTransport, + "grpc", + ), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ( + ProductInputsServiceClient, + transports.ProductInputsServiceRestTransport, + "rest", + ), + ], +) +def test_product_inputs_service_client_client_options_scopes( + client_class, transport_class, transport_name +): # Check the case scopes are provided. options = client_options.ClientOptions( scopes=["1", "2"], ) - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=["1", "2"], client_cert_source_for_mtls=None, quota_project_id=None, @@ -665,24 +1035,45 @@ def test_product_inputs_service_client_client_options_scopes(client_class, trans api_audience=None, ) -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (ProductInputsServiceClient, transports.ProductInputsServiceRestTransport, "rest", None), -]) -def test_product_inputs_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductInputsServiceClient, + transports.ProductInputsServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ( + ProductInputsServiceClient, + transports.ProductInputsServiceRestTransport, + "rest", + None, + ), + ], +) +def test_product_inputs_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) + options = client_options.ClientOptions(credentials_file="credentials.json") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -691,11 +1082,14 @@ def test_product_inputs_service_client_client_options_credentials_file(client_cl api_audience=None, ) + def test_product_inputs_service_client_client_options_from_dict(): - with mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceGrpcTransport.__init__') as grpc_transport: + with mock.patch( + "google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceGrpcTransport.__init__" + ) as grpc_transport: grpc_transport.return_value = None client = ProductInputsServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} + client_options={"api_endpoint": "squid.clam.whelk"} ) grpc_transport.assert_called_once_with( credentials=None, @@ -710,23 +1104,38 @@ def test_product_inputs_service_client_client_options_from_dict(): ) -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_product_inputs_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductInputsServiceClient, + transports.ProductInputsServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_product_inputs_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) + options = client_options.ClientOptions(credentials_file="credentials.json") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -753,9 +1162,7 @@ def test_product_inputs_service_client_create_channel_credentials_file(client_cl credentials=file_creds, credentials_file=None, quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), scopes=None, default_host="merchantapi.googleapis.com", ssl_credentials=None, @@ -766,11 +1173,14 @@ def test_product_inputs_service_client_create_channel_credentials_file(client_cl ) -@pytest.mark.parametrize("request_type", [ - productinputs.InsertProductInputRequest, - dict, -]) -def test_insert_product_input(request_type, transport: str = 'grpc'): +@pytest.mark.parametrize( + "request_type", + [ + productinputs.InsertProductInputRequest, + dict, + ], +) +def test_insert_product_input(request_type, transport: str = "grpc"): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -782,16 +1192,16 @@ def test_insert_product_input(request_type, transport: str = 'grpc'): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: + type(client.transport.insert_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = productinputs.ProductInput( - name='name_value', - product='product_value', + name="name_value", + product="product_value", legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", version_number=1518, ) response = client.insert_product_input(request) @@ -804,12 +1214,12 @@ def test_insert_product_input(request_type, transport: str = 'grpc'): # Establish that the response is the type that we expect. assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' + assert response.name == "name_value" + assert response.product == "product_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" assert response.version_number == 1518 @@ -818,30 +1228,33 @@ def test_insert_product_input_non_empty_request_with_auto_populated_field(): # automatically populated, according to AIP-4235, with non-empty requests. client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', + transport="grpc", ) # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. request = productinputs.InsertProductInputRequest( - parent='parent_value', - data_source='data_source_value', + parent="parent_value", + data_source="data_source_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + type(client.transport.insert_product_input), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.insert_product_input(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == productinputs.InsertProductInputRequest( - parent='parent_value', - data_source='data_source_value', + parent="parent_value", + data_source="data_source_value", ) + def test_insert_product_input_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -856,12 +1269,18 @@ def test_insert_product_input_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.insert_product_input in client._transport._wrapped_methods + assert ( + client._transport.insert_product_input in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.insert_product_input + ] = mock_rpc request = {} client.insert_product_input(request) @@ -874,8 +1293,11 @@ def test_insert_product_input_use_cached_wrapped_rpc(): assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_insert_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_insert_product_input_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -889,12 +1311,17 @@ async def test_insert_product_input_async_use_cached_wrapped_rpc(transport: str wrapper_fn.reset_mock() # Ensure method has been cached - assert client._client._transport.insert_product_input in client._client._transport._wrapped_methods + assert ( + client._client._transport.insert_product_input + in client._client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.insert_product_input] = mock_rpc + client._client._transport._wrapped_methods[ + client._client._transport.insert_product_input + ] = mock_rpc request = {} await client.insert_product_input(request) @@ -908,8 +1335,12 @@ async def test_insert_product_input_async_use_cached_wrapped_rpc(transport: str assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_insert_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.InsertProductInputRequest): +async def test_insert_product_input_async( + transport: str = "grpc_asyncio", + request_type=productinputs.InsertProductInputRequest, +): client = ProductInputsServiceAsyncClient( credentials=async_anonymous_credentials(), transport=transport, @@ -921,18 +1352,20 @@ async def test_insert_product_input_async(transport: str = 'grpc_asyncio', reque # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: + type(client.transport.insert_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput( + name="name_value", + product="product_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + version_number=1518, + ) + ) response = await client.insert_product_input(request) # Establish that the underlying gRPC stub method was called. @@ -943,12 +1376,12 @@ async def test_insert_product_input_async(transport: str = 'grpc_asyncio', reque # Establish that the response is the type that we expect. assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' + assert response.name == "name_value" + assert response.product == "product_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" assert response.version_number == 1518 @@ -956,6 +1389,7 @@ async def test_insert_product_input_async(transport: str = 'grpc_asyncio', reque async def test_insert_product_input_async_from_dict(): await test_insert_product_input_async(request_type=dict) + def test_insert_product_input_field_headers(): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -965,12 +1399,12 @@ def test_insert_product_input_field_headers(): # a field header. Set these to a non-empty value. request = productinputs.InsertProductInputRequest() - request.parent = 'parent_value' + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: + type(client.transport.insert_product_input), "__call__" + ) as call: call.return_value = productinputs.ProductInput() client.insert_product_input(request) @@ -982,9 +1416,9 @@ def test_insert_product_input_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -997,13 +1431,15 @@ async def test_insert_product_input_field_headers_async(): # a field header. Set these to a non-empty value. request = productinputs.InsertProductInputRequest() - request.parent = 'parent_value' + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + type(client.transport.insert_product_input), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput() + ) await client.insert_product_input(request) # Establish that the underlying gRPC stub method was called. @@ -1014,16 +1450,19 @@ async def test_insert_product_input_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -@pytest.mark.parametrize("request_type", [ - productinputs.UpdateProductInputRequest, - dict, -]) -def test_update_product_input(request_type, transport: str = 'grpc'): +@pytest.mark.parametrize( + "request_type", + [ + productinputs.UpdateProductInputRequest, + dict, + ], +) +def test_update_product_input(request_type, transport: str = "grpc"): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1035,16 +1474,16 @@ def test_update_product_input(request_type, transport: str = 'grpc'): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = productinputs.ProductInput( - name='name_value', - product='product_value', + name="name_value", + product="product_value", legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", version_number=1518, ) response = client.update_product_input(request) @@ -1057,12 +1496,12 @@ def test_update_product_input(request_type, transport: str = 'grpc'): # Establish that the response is the type that we expect. assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' + assert response.name == "name_value" + assert response.product == "product_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" assert response.version_number == 1518 @@ -1071,28 +1510,31 @@ def test_update_product_input_non_empty_request_with_auto_populated_field(): # automatically populated, according to AIP-4235, with non-empty requests. client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', + transport="grpc", ) # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. request = productinputs.UpdateProductInputRequest( - data_source='data_source_value', + data_source="data_source_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + type(client.transport.update_product_input), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.update_product_input(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == productinputs.UpdateProductInputRequest( - data_source='data_source_value', + data_source="data_source_value", ) + def test_update_product_input_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -1107,12 +1549,18 @@ def test_update_product_input_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_product_input in client._transport._wrapped_methods + assert ( + client._transport.update_product_input in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_product_input + ] = mock_rpc request = {} client.update_product_input(request) @@ -1125,8 +1573,11 @@ def test_update_product_input_use_cached_wrapped_rpc(): assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_update_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_update_product_input_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -1140,12 +1591,17 @@ async def test_update_product_input_async_use_cached_wrapped_rpc(transport: str wrapper_fn.reset_mock() # Ensure method has been cached - assert client._client._transport.update_product_input in client._client._transport._wrapped_methods + assert ( + client._client._transport.update_product_input + in client._client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.update_product_input] = mock_rpc + client._client._transport._wrapped_methods[ + client._client._transport.update_product_input + ] = mock_rpc request = {} await client.update_product_input(request) @@ -1159,8 +1615,12 @@ async def test_update_product_input_async_use_cached_wrapped_rpc(transport: str assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_update_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.UpdateProductInputRequest): +async def test_update_product_input_async( + transport: str = "grpc_asyncio", + request_type=productinputs.UpdateProductInputRequest, +): client = ProductInputsServiceAsyncClient( credentials=async_anonymous_credentials(), transport=transport, @@ -1172,18 +1632,20 @@ async def test_update_product_input_async(transport: str = 'grpc_asyncio', reque # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput( + name="name_value", + product="product_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + version_number=1518, + ) + ) response = await client.update_product_input(request) # Establish that the underlying gRPC stub method was called. @@ -1194,12 +1656,12 @@ async def test_update_product_input_async(transport: str = 'grpc_asyncio', reque # Establish that the response is the type that we expect. assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' + assert response.name == "name_value" + assert response.product == "product_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" assert response.version_number == 1518 @@ -1207,6 +1669,7 @@ async def test_update_product_input_async(transport: str = 'grpc_asyncio', reque async def test_update_product_input_async_from_dict(): await test_update_product_input_async(request_type=dict) + def test_update_product_input_field_headers(): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1216,12 +1679,12 @@ def test_update_product_input_field_headers(): # a field header. Set these to a non-empty value. request = productinputs.UpdateProductInputRequest() - request.product_input.name = 'name_value' + request.product_input.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: call.return_value = productinputs.ProductInput() client.update_product_input(request) @@ -1233,9 +1696,9 @@ def test_update_product_input_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'product_input.name=name_value', - ) in kw['metadata'] + "x-goog-request-params", + "product_input.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1248,13 +1711,15 @@ async def test_update_product_input_field_headers_async(): # a field header. Set these to a non-empty value. request = productinputs.UpdateProductInputRequest() - request.product_input.name = 'name_value' + request.product_input.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + type(client.transport.update_product_input), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput() + ) await client.update_product_input(request) # Establish that the underlying gRPC stub method was called. @@ -1265,9 +1730,9 @@ async def test_update_product_input_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'product_input.name=name_value', - ) in kw['metadata'] + "x-goog-request-params", + "product_input.name=name_value", + ) in kw["metadata"] def test_update_product_input_flattened(): @@ -1277,15 +1742,15 @@ def test_update_product_input_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = productinputs.ProductInput() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.update_product_input( - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + product_input=productinputs.ProductInput(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected @@ -1293,10 +1758,10 @@ def test_update_product_input_flattened(): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] arg = args[0].product_input - mock_val = productinputs.ProductInput(name='name_value') + mock_val = productinputs.ProductInput(name="name_value") assert arg == mock_val arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val @@ -1310,10 +1775,11 @@ def test_update_product_input_flattened_error(): with pytest.raises(ValueError): client.update_product_input( productinputs.UpdateProductInputRequest(), - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + product_input=productinputs.ProductInput(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) + @pytest.mark.asyncio async def test_update_product_input_flattened_async(): client = ProductInputsServiceAsyncClient( @@ -1322,17 +1788,19 @@ async def test_update_product_input_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = productinputs.ProductInput() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.update_product_input( - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + product_input=productinputs.ProductInput(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected @@ -1340,12 +1808,13 @@ async def test_update_product_input_flattened_async(): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] arg = args[0].product_input - mock_val = productinputs.ProductInput(name='name_value') + mock_val = productinputs.ProductInput(name="name_value") assert arg == mock_val arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) assert arg == mock_val + @pytest.mark.asyncio async def test_update_product_input_flattened_error_async(): client = ProductInputsServiceAsyncClient( @@ -1357,16 +1826,19 @@ async def test_update_product_input_flattened_error_async(): with pytest.raises(ValueError): await client.update_product_input( productinputs.UpdateProductInputRequest(), - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + product_input=productinputs.ProductInput(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -@pytest.mark.parametrize("request_type", [ - productinputs.DeleteProductInputRequest, - dict, -]) -def test_delete_product_input(request_type, transport: str = 'grpc'): +@pytest.mark.parametrize( + "request_type", + [ + productinputs.DeleteProductInputRequest, + dict, + ], +) +def test_delete_product_input(request_type, transport: str = "grpc"): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1378,8 +1850,8 @@ def test_delete_product_input(request_type, transport: str = 'grpc'): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = None response = client.delete_product_input(request) @@ -1399,30 +1871,33 @@ def test_delete_product_input_non_empty_request_with_auto_populated_field(): # automatically populated, according to AIP-4235, with non-empty requests. client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', + transport="grpc", ) # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. request = productinputs.DeleteProductInputRequest( - name='name_value', - data_source='data_source_value', + name="name_value", + data_source="data_source_value", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + type(client.transport.delete_product_input), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.delete_product_input(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == productinputs.DeleteProductInputRequest( - name='name_value', - data_source='data_source_value', + name="name_value", + data_source="data_source_value", ) + def test_delete_product_input_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -1437,12 +1912,18 @@ def test_delete_product_input_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_product_input in client._transport._wrapped_methods + assert ( + client._transport.delete_product_input in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_product_input + ] = mock_rpc request = {} client.delete_product_input(request) @@ -1455,8 +1936,11 @@ def test_delete_product_input_use_cached_wrapped_rpc(): assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_delete_product_input_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_delete_product_input_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -1470,12 +1954,17 @@ async def test_delete_product_input_async_use_cached_wrapped_rpc(transport: str wrapper_fn.reset_mock() # Ensure method has been cached - assert client._client._transport.delete_product_input in client._client._transport._wrapped_methods + assert ( + client._client._transport.delete_product_input + in client._client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.delete_product_input] = mock_rpc + client._client._transport._wrapped_methods[ + client._client._transport.delete_product_input + ] = mock_rpc request = {} await client.delete_product_input(request) @@ -1489,8 +1978,12 @@ async def test_delete_product_input_async_use_cached_wrapped_rpc(transport: str assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_delete_product_input_async(transport: str = 'grpc_asyncio', request_type=productinputs.DeleteProductInputRequest): +async def test_delete_product_input_async( + transport: str = "grpc_asyncio", + request_type=productinputs.DeleteProductInputRequest, +): client = ProductInputsServiceAsyncClient( credentials=async_anonymous_credentials(), transport=transport, @@ -1502,8 +1995,8 @@ async def test_delete_product_input_async(transport: str = 'grpc_asyncio', reque # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) response = await client.delete_product_input(request) @@ -1522,6 +2015,7 @@ async def test_delete_product_input_async(transport: str = 'grpc_asyncio', reque async def test_delete_product_input_async_from_dict(): await test_delete_product_input_async(request_type=dict) + def test_delete_product_input_field_headers(): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1531,12 +2025,12 @@ def test_delete_product_input_field_headers(): # a field header. Set these to a non-empty value. request = productinputs.DeleteProductInputRequest() - request.name = 'name_value' + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: call.return_value = None client.delete_product_input(request) @@ -1548,9 +2042,9 @@ def test_delete_product_input_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1563,12 +2057,12 @@ async def test_delete_product_input_field_headers_async(): # a field header. Set these to a non-empty value. request = productinputs.DeleteProductInputRequest() - request.name = 'name_value' + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_product_input(request) @@ -1580,9 +2074,9 @@ async def test_delete_product_input_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_product_input_flattened(): @@ -1592,14 +2086,14 @@ def test_delete_product_input_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.delete_product_input( - name='name_value', + name="name_value", ) # Establish that the underlying call was made with the expected @@ -1607,7 +2101,7 @@ def test_delete_product_input_flattened(): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] arg = args[0].name - mock_val = 'name_value' + mock_val = "name_value" assert arg == mock_val @@ -1621,9 +2115,10 @@ def test_delete_product_input_flattened_error(): with pytest.raises(ValueError): client.delete_product_input( productinputs.DeleteProductInputRequest(), - name='name_value', + name="name_value", ) + @pytest.mark.asyncio async def test_delete_product_input_flattened_async(): client = ProductInputsServiceAsyncClient( @@ -1632,8 +2127,8 @@ async def test_delete_product_input_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1641,7 +2136,7 @@ async def test_delete_product_input_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.delete_product_input( - name='name_value', + name="name_value", ) # Establish that the underlying call was made with the expected @@ -1649,9 +2144,10 @@ async def test_delete_product_input_flattened_async(): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] arg = args[0].name - mock_val = 'name_value' + mock_val = "name_value" assert arg == mock_val + @pytest.mark.asyncio async def test_delete_product_input_flattened_error_async(): client = ProductInputsServiceAsyncClient( @@ -1663,7 +2159,7 @@ async def test_delete_product_input_flattened_error_async(): with pytest.raises(ValueError): await client.delete_product_input( productinputs.DeleteProductInputRequest(), - name='name_value', + name="name_value", ) @@ -1681,12 +2177,18 @@ def test_insert_product_input_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.insert_product_input in client._transport._wrapped_methods + assert ( + client._transport.insert_product_input in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.insert_product_input] = mock_rpc + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.insert_product_input + ] = mock_rpc request = {} client.insert_product_input(request) @@ -1701,7 +2203,9 @@ def test_insert_product_input_rest_use_cached_wrapped_rpc(): assert mock_rpc.call_count == 2 -def test_insert_product_input_rest_required_fields(request_type=productinputs.InsertProductInputRequest): +def test_insert_product_input_rest_required_fields( + request_type=productinputs.InsertProductInputRequest, +): transport_class = transports.ProductInputsServiceRestTransport request_init = {} @@ -1709,58 +2213,61 @@ def test_insert_product_input_rest_required_fields(request_type=productinputs.In request_init["data_source"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) # verify fields with default values are dropped assert "dataSource" not in jsonified_request - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).insert_product_input._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present assert "dataSource" in jsonified_request assert jsonified_request["dataSource"] == request_init["data_source"] - jsonified_request["parent"] = 'parent_value' - jsonified_request["dataSource"] = 'data_source_value' + jsonified_request["parent"] = "parent_value" + jsonified_request["dataSource"] = "data_source_value" - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).insert_product_input._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).insert_product_input._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("data_source", )) + assert not set(unset_fields) - set(("data_source",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' + assert jsonified_request["parent"] == "parent_value" assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == 'data_source_value' + assert jsonified_request["dataSource"] == "data_source_value" client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='rest', + transport="rest", ) request = request_type(**request_init) # Designate an appropriate value for the returned response. return_value = productinputs.ProductInput() # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: + with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values # for required fields will fail the real version if the http_options # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: + with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. pb_request = request_type.pb(request) transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, } - transcode_result['body'] = pb_request + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -1770,7 +2277,7 @@ def test_insert_product_input_rest_required_fields(request_type=productinputs.In return_value = productinputs.ProductInput.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -1781,17 +2288,28 @@ def test_insert_product_input_rest_required_fields(request_type=productinputs.In "dataSource", "", ), - ('$alt', 'json;enum-encoding=int') + ("$alt", "json;enum-encoding=int"), ] - actual_params = req.call_args.kwargs['params'] + actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params def test_insert_product_input_rest_unset_required_fields(): - transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) unset_fields = transport.insert_product_input._get_unset_required_fields({}) - assert set(unset_fields) == (set(("dataSource", )) & set(("parent", "productInput", "dataSource", ))) + assert set(unset_fields) == ( + set(("dataSource",)) + & set( + ( + "parent", + "productInput", + "dataSource", + ) + ) + ) def test_update_product_input_rest_use_cached_wrapped_rpc(): @@ -1808,12 +2326,18 @@ def test_update_product_input_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.update_product_input in client._transport._wrapped_methods + assert ( + client._transport.update_product_input in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.update_product_input] = mock_rpc + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_product_input + ] = mock_rpc request = {} client.update_product_input(request) @@ -1828,62 +2352,72 @@ def test_update_product_input_rest_use_cached_wrapped_rpc(): assert mock_rpc.call_count == 2 -def test_update_product_input_rest_required_fields(request_type=productinputs.UpdateProductInputRequest): +def test_update_product_input_rest_required_fields( + request_type=productinputs.UpdateProductInputRequest, +): transport_class = transports.ProductInputsServiceRestTransport request_init = {} request_init["data_source"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) # verify fields with default values are dropped assert "dataSource" not in jsonified_request - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_product_input._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present assert "dataSource" in jsonified_request assert jsonified_request["dataSource"] == request_init["data_source"] - jsonified_request["dataSource"] = 'data_source_value' + jsonified_request["dataSource"] = "data_source_value" - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_product_input._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_product_input._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("data_source", "update_mask", )) + assert not set(unset_fields) - set( + ( + "data_source", + "update_mask", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == 'data_source_value' + assert jsonified_request["dataSource"] == "data_source_value" client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='rest', + transport="rest", ) request = request_type(**request_init) # Designate an appropriate value for the returned response. return_value = productinputs.ProductInput() # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: + with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values # for required fields will fail the real version if the http_options # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: + with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. pb_request = request_type.pb(request) transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, } - transcode_result['body'] = pb_request + transcode_result["body"] = pb_request transcode.return_value = transcode_result response_value = Response() @@ -1893,7 +2427,7 @@ def test_update_product_input_rest_required_fields(request_type=productinputs.Up return_value = productinputs.ProductInput.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -1904,17 +2438,32 @@ def test_update_product_input_rest_required_fields(request_type=productinputs.Up "dataSource", "", ), - ('$alt', 'json;enum-encoding=int') + ("$alt", "json;enum-encoding=int"), ] - actual_params = req.call_args.kwargs['params'] + actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params def test_update_product_input_rest_unset_required_fields(): - transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) unset_fields = transport.update_product_input._get_unset_required_fields({}) - assert set(unset_fields) == (set(("dataSource", "updateMask", )) & set(("productInput", "dataSource", ))) + assert set(unset_fields) == ( + set( + ( + "dataSource", + "updateMask", + ) + ) + & set( + ( + "productInput", + "dataSource", + ) + ) + ) def test_update_product_input_rest_flattened(): @@ -1924,17 +2473,19 @@ def test_update_product_input_rest_flattened(): ) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = productinputs.ProductInput() # get arguments that satisfy an http rule for this method - sample_request = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + sample_request = { + "product_input": {"name": "accounts/sample1/productInputs/sample2"} + } # get truthy value for each flattened field mock_args = dict( - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + product_input=productinputs.ProductInput(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) mock_args.update(sample_request) @@ -1944,7 +2495,7 @@ def test_update_product_input_rest_flattened(): # Convert return value to protobuf type return_value = productinputs.ProductInput.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -1954,10 +2505,14 @@ def test_update_product_input_rest_flattened(): # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1/{product_input.name=accounts/*/productInputs/*}" % client.transport._host, args[1]) + assert path_template.validate( + "%s/products/v1/{product_input.name=accounts/*/productInputs/*}" + % client.transport._host, + args[1], + ) -def test_update_product_input_rest_flattened_error(transport: str = 'rest'): +def test_update_product_input_rest_flattened_error(transport: str = "rest"): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1968,8 +2523,8 @@ def test_update_product_input_rest_flattened_error(transport: str = 'rest'): with pytest.raises(ValueError): client.update_product_input( productinputs.UpdateProductInputRequest(), - product_input=productinputs.ProductInput(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + product_input=productinputs.ProductInput(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @@ -1987,12 +2542,18 @@ def test_delete_product_input_rest_use_cached_wrapped_rpc(): wrapper_fn.reset_mock() # Ensure method has been cached - assert client._transport.delete_product_input in client._transport._wrapped_methods + assert ( + client._transport.delete_product_input in client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. - client._transport._wrapped_methods[client._transport.delete_product_input] = mock_rpc + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_product_input + ] = mock_rpc request = {} client.delete_product_input(request) @@ -2007,7 +2568,9 @@ def test_delete_product_input_rest_use_cached_wrapped_rpc(): assert mock_rpc.call_count == 2 -def test_delete_product_input_rest_required_fields(request_type=productinputs.DeleteProductInputRequest): +def test_delete_product_input_rest_required_fields( + request_type=productinputs.DeleteProductInputRequest, +): transport_class = transports.ProductInputsServiceRestTransport request_init = {} @@ -2015,64 +2578,67 @@ def test_delete_product_input_rest_required_fields(request_type=productinputs.De request_init["data_source"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) # verify fields with default values are dropped assert "dataSource" not in jsonified_request - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_product_input._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present assert "dataSource" in jsonified_request assert jsonified_request["dataSource"] == request_init["data_source"] - jsonified_request["name"] = 'name_value' - jsonified_request["dataSource"] = 'data_source_value' + jsonified_request["name"] = "name_value" + jsonified_request["dataSource"] = "data_source_value" - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_product_input._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_product_input._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("data_source", )) + assert not set(unset_fields) - set(("data_source",)) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' + assert jsonified_request["name"] == "name_value" assert "dataSource" in jsonified_request - assert jsonified_request["dataSource"] == 'data_source_value' + assert jsonified_request["dataSource"] == "data_source_value" client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='rest', + transport="rest", ) request = request_type(**request_init) # Designate an appropriate value for the returned response. return_value = None # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: + with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values # for required fields will fail the real version if the http_options # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: + with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. pb_request = request_type.pb(request) transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, } transcode.return_value = transcode_result response_value = Response() response_value.status_code = 200 - json_return_value = '' + json_return_value = "" - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -2083,17 +2649,27 @@ def test_delete_product_input_rest_required_fields(request_type=productinputs.De "dataSource", "", ), - ('$alt', 'json;enum-encoding=int') + ("$alt", "json;enum-encoding=int"), ] - actual_params = req.call_args.kwargs['params'] + actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params def test_delete_product_input_rest_unset_required_fields(): - transport = transports.ProductInputsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + transport = transports.ProductInputsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) unset_fields = transport.delete_product_input._get_unset_required_fields({}) - assert set(unset_fields) == (set(("dataSource", )) & set(("name", "dataSource", ))) + assert set(unset_fields) == ( + set(("dataSource",)) + & set( + ( + "name", + "dataSource", + ) + ) + ) def test_delete_product_input_rest_flattened(): @@ -2103,24 +2679,24 @@ def test_delete_product_input_rest_flattened(): ) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = None # get arguments that satisfy an http rule for this method - sample_request = {'name': 'accounts/sample1/productInputs/sample2'} + sample_request = {"name": "accounts/sample1/productInputs/sample2"} # get truthy value for each flattened field mock_args = dict( - name='name_value', + name="name_value", ) mock_args.update(sample_request) # Wrap the value into a proper Response obj response_value = Response() response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') + json_return_value = "" + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -2130,10 +2706,13 @@ def test_delete_product_input_rest_flattened(): # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1/{name=accounts/*/productInputs/*}" % client.transport._host, args[1]) + assert path_template.validate( + "%s/products/v1/{name=accounts/*/productInputs/*}" % client.transport._host, + args[1], + ) -def test_delete_product_input_rest_flattened_error(transport: str = 'rest'): +def test_delete_product_input_rest_flattened_error(transport: str = "rest"): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -2144,7 +2723,7 @@ def test_delete_product_input_rest_flattened_error(transport: str = 'rest'): with pytest.raises(ValueError): client.delete_product_input( productinputs.DeleteProductInputRequest(), - name='name_value', + name="name_value", ) @@ -2186,8 +2765,7 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = ProductInputsServiceClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) # It is an error to provide scopes and a transport instance. @@ -2209,6 +2787,7 @@ def test_transport_instance(): client = ProductInputsServiceClient(transport=transport) assert client.transport is transport + def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ProductInputsServiceGrpcTransport( @@ -2223,18 +2802,23 @@ def test_transport_get_channel(): channel = transport.grpc_channel assert channel -@pytest.mark.parametrize("transport_class", [ - transports.ProductInputsServiceGrpcTransport, - transports.ProductInputsServiceGrpcAsyncIOTransport, - transports.ProductInputsServiceRestTransport, -]) + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + transports.ProductInputsServiceRestTransport, + ], +) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() + def test_transport_kind_grpc(): transport = ProductInputsServiceClient.get_transport_class("grpc")( credentials=ga_credentials.AnonymousCredentials() @@ -2244,8 +2828,7 @@ def test_transport_kind_grpc(): def test_initialize_client_w_grpc(): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" + credentials=ga_credentials.AnonymousCredentials(), transport="grpc" ) assert client is not None @@ -2260,8 +2843,8 @@ def test_insert_product_input_empty_call_grpc(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: + type(client.transport.insert_product_input), "__call__" + ) as call: call.return_value = productinputs.ProductInput() client.insert_product_input(request=None) @@ -2283,8 +2866,8 @@ def test_update_product_input_empty_call_grpc(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: call.return_value = productinputs.ProductInput() client.update_product_input(request=None) @@ -2306,8 +2889,8 @@ def test_delete_product_input_empty_call_grpc(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: call.return_value = None client.delete_product_input(request=None) @@ -2328,8 +2911,7 @@ def test_transport_kind_grpc_asyncio(): def test_initialize_client_w_grpc_asyncio(): client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" + credentials=async_anonymous_credentials(), transport="grpc_asyncio" ) assert client is not None @@ -2345,18 +2927,20 @@ async def test_insert_product_input_empty_call_grpc_asyncio(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: + type(client.transport.insert_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput( + name="name_value", + product="product_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + version_number=1518, + ) + ) await client.insert_product_input(request=None) # Establish that the underlying stub method was called. @@ -2378,18 +2962,20 @@ async def test_update_product_input_empty_call_grpc_asyncio(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(productinputs.ProductInput( - name='name_value', - product='product_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + productinputs.ProductInput( + name="name_value", + product="product_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + version_number=1518, + ) + ) await client.update_product_input(request=None) # Establish that the underlying stub method was called. @@ -2411,8 +2997,8 @@ async def test_delete_product_input_empty_call_grpc_asyncio(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_product_input(request=None) @@ -2432,20 +3018,23 @@ def test_transport_kind_rest(): assert transport.kind == "rest" -def test_insert_product_input_rest_bad_request(request_type=productinputs.InsertProductInputRequest): +def test_insert_product_input_rest_bad_request( + request_type=productinputs.InsertProductInputRequest, +): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} + request_init = {"parent": "accounts/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): # Wrap the value into a proper Response obj response_value = mock.Mock() - json_return_value = '' + json_return_value = "" response_value.json = mock.Mock(return_value={}) response_value.status_code = 400 response_value.request = mock.Mock() @@ -2454,19 +3043,205 @@ def test_insert_product_input_rest_bad_request(request_type=productinputs.Insert client.insert_product_input(request) -@pytest.mark.parametrize("request_type", [ - productinputs.InsertProductInputRequest, - dict, -]) +@pytest.mark.parametrize( + "request_type", + [ + productinputs.InsertProductInputRequest, + dict, + ], +) def test_insert_product_input_rest_call_success(request_type): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} - request_init["product_input"] = {'name': 'name_value', 'product': 'product_value', 'legacy_local': True, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'product_attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 1, 'availability': 1, 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 1, 'gender': 1, 'google_product_category': 'google_product_category_value', 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 1}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 1, 'size_types': [1], 'energy_efficiency_class': 1, 'min_energy_efficiency_class': 1, 'max_energy_efficiency_class': 1, 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 1, 'pickup_sla': 1, 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': [1], 'excluded_destinations': [1], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 1, 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 1, 'certification_name': 1, 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 1, 'content': 'content_value'}, 'structured_description': {'digital_source_type': 1, 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} + request_init = {"parent": "accounts/sample1"} + request_init["product_input"] = { + "name": "name_value", + "product": "product_value", + "legacy_local": True, + "offer_id": "offer_id_value", + "content_language": "content_language_value", + "feed_label": "feed_label_value", + "version_number": 1518, + "product_attributes": { + "identifier_exists": True, + "is_bundle": True, + "title": "title_value", + "description": "description_value", + "link": "link_value", + "mobile_link": "mobile_link_value", + "canonical_link": "canonical_link_value", + "image_link": "image_link_value", + "additional_image_links": [ + "additional_image_links_value1", + "additional_image_links_value2", + ], + "expiration_date": {"seconds": 751, "nanos": 543}, + "disclosure_date": {}, + "adult": True, + "age_group": 1, + "availability": 1, + "availability_date": {}, + "brand": "brand_value", + "color": "color_value", + "condition": 1, + "gender": 1, + "google_product_category": "google_product_category_value", + "gtins": ["gtins_value1", "gtins_value2"], + "item_group_id": "item_group_id_value", + "material": "material_value", + "mpn": "mpn_value", + "pattern": "pattern_value", + "price": {"amount_micros": 1408, "currency_code": "currency_code_value"}, + "maximum_retail_price": {}, + "installment": { + "months": 665, + "amount": {}, + "downpayment": {}, + "credit_type": 1, + }, + "subscription_cost": {"period": 1, "period_length": 1380, "amount": {}}, + "loyalty_points": { + "name": "name_value", + "points_value": 1305, + "ratio": 0.543, + }, + "loyalty_programs": [ + { + "program_label": "program_label_value", + "tier_label": "tier_label_value", + "price": {}, + "cashback_for_future_use": {}, + "loyalty_points": 1546, + "member_price_effective_date": {"start_time": {}, "end_time": {}}, + "shipping_label": "shipping_label_value", + } + ], + "product_types": ["product_types_value1", "product_types_value2"], + "sale_price": {}, + "sale_price_effective_date": {}, + "sell_on_google_quantity": 2470, + "product_height": {"value": 0.541, "unit": "unit_value"}, + "product_length": {}, + "product_width": {}, + "product_weight": {"value": 0.541, "unit": "unit_value"}, + "shipping": [ + { + "price": {}, + "country": "country_value", + "region": "region_value", + "service": "service_value", + "location_id": 1157, + "location_group_name": "location_group_name_value", + "postal_code": "postal_code_value", + "min_handling_time": 1782, + "max_handling_time": 1784, + "min_transit_time": 1718, + "max_transit_time": 1720, + } + ], + "free_shipping_threshold": [ + {"country": "country_value", "price_threshold": {}} + ], + "shipping_weight": {"value": 0.541, "unit": "unit_value"}, + "shipping_length": {"value": 0.541, "unit": "unit_value"}, + "shipping_width": {}, + "shipping_height": {}, + "max_handling_time": 1784, + "min_handling_time": 1782, + "shipping_label": "shipping_label_value", + "transit_time_label": "transit_time_label_value", + "size": "size_value", + "size_system": 1, + "size_types": [1], + "energy_efficiency_class": 1, + "min_energy_efficiency_class": 1, + "max_energy_efficiency_class": 1, + "unit_pricing_measure": {"value": 0.541, "unit": "unit_value"}, + "unit_pricing_base_measure": {"value": 541, "unit": "unit_value"}, + "multipack": 970, + "ads_grouping": "ads_grouping_value", + "ads_labels": ["ads_labels_value1", "ads_labels_value2"], + "ads_redirect": "ads_redirect_value", + "cost_of_goods_sold": {}, + "product_details": [ + { + "section_name": "section_name_value", + "attribute_name": "attribute_name_value", + "attribute_value": "attribute_value_value", + } + ], + "product_highlights": [ + "product_highlights_value1", + "product_highlights_value2", + ], + "display_ads_id": "display_ads_id_value", + "display_ads_similar_ids": [ + "display_ads_similar_ids_value1", + "display_ads_similar_ids_value2", + ], + "display_ads_title": "display_ads_title_value", + "display_ads_link": "display_ads_link_value", + "display_ads_value": 0.1801, + "promotion_ids": ["promotion_ids_value1", "promotion_ids_value2"], + "pickup_method": 1, + "pickup_sla": 1, + "link_template": "link_template_value", + "mobile_link_template": "mobile_link_template_value", + "custom_label_0": "custom_label_0_value", + "custom_label_1": "custom_label_1_value", + "custom_label_2": "custom_label_2_value", + "custom_label_3": "custom_label_3_value", + "custom_label_4": "custom_label_4_value", + "included_destinations": [1], + "excluded_destinations": [1], + "shopping_ads_excluded_countries": [ + "shopping_ads_excluded_countries_value1", + "shopping_ads_excluded_countries_value2", + ], + "external_seller_id": "external_seller_id_value", + "pause": 1, + "lifestyle_image_links": [ + "lifestyle_image_links_value1", + "lifestyle_image_links_value2", + ], + "cloud_export_additional_properties": [ + { + "property_name": "property_name_value", + "text_value": ["text_value_value1", "text_value_value2"], + "bool_value": True, + "int_value": [968, 969], + "float_value": [0.11710000000000001, 0.11720000000000001], + "min_value": 0.96, + "max_value": 0.962, + "unit_code": "unit_code_value", + } + ], + "virtual_model_link": "virtual_model_link_value", + "certifications": [ + { + "certification_authority": 1, + "certification_name": 1, + "certification_code": "certification_code_value", + "certification_value": "certification_value_value", + } + ], + "structured_title": {"digital_source_type": 1, "content": "content_value"}, + "structured_description": { + "digital_source_type": 1, + "content": "content_value", + }, + "auto_pricing_min_price": {}, + "sustainability_incentives": [ + {"amount": {}, "percentage": 0.10540000000000001, "type_": 1} + ], + }, + "custom_attributes": [ + {"name": "name_value", "value": "value_value", "group_values": {}} + ], + } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 @@ -2486,7 +3261,7 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -2500,7 +3275,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["product_input"].items(): # pragma: NO COVER + for field, value in request_init["product_input"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -2515,12 +3290,16 @@ def get_message_fields(field): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: subfields_not_in_runtime.append( - {"field": field, "subfield": subfield, "is_repeated": is_repeated} + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } ) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -2533,16 +3312,16 @@ def get_message_fields(field): request = request_type(**request_init) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = productinputs.ProductInput( - name='name_value', - product='product_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, + name="name_value", + product="product_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + version_number=1518, ) # Wrap the value into a proper Response obj @@ -2552,19 +3331,19 @@ def get_message_fields(field): # Convert return value to protobuf type return_value = productinputs.ProductInput.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') + response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.insert_product_input(request) # Establish that the response is the type that we expect. assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' + assert response.name == "name_value" + assert response.product == "product_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" assert response.version_number == 1518 @@ -2572,19 +3351,30 @@ def get_message_fields(field): def test_insert_product_input_rest_interceptors(null_interceptor): transport = transports.ProductInputsServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), - ) + interceptor=None + if null_interceptor + else transports.ProductInputsServiceRestInterceptor(), + ) client = ProductInputsServiceClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input") as post, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_insert_product_input_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_insert_product_input") as pre: + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, "post_insert_product_input" + ) as post, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, + "post_insert_product_input_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, "pre_insert_product_input" + ) as pre: pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = productinputs.InsertProductInputRequest.pb(productinputs.InsertProductInputRequest()) + pb_message = productinputs.InsertProductInputRequest.pb( + productinputs.InsertProductInputRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -2599,7 +3389,7 @@ def test_insert_product_input_rest_interceptors(null_interceptor): req.return_value.content = return_value request = productinputs.InsertProductInputRequest() - metadata =[ + metadata = [ ("key", "val"), ("cephalopod", "squid"), ] @@ -2607,27 +3397,36 @@ def test_insert_product_input_rest_interceptors(null_interceptor): post.return_value = productinputs.ProductInput() post_with_metadata.return_value = productinputs.ProductInput(), metadata - client.insert_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + client.insert_product_input( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) pre.assert_called_once() post.assert_called_once() post_with_metadata.assert_called_once() -def test_update_product_input_rest_bad_request(request_type=productinputs.UpdateProductInputRequest): +def test_update_product_input_rest_bad_request( + request_type=productinputs.UpdateProductInputRequest, +): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} + request_init = {"product_input": {"name": "accounts/sample1/productInputs/sample2"}} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): # Wrap the value into a proper Response obj response_value = mock.Mock() - json_return_value = '' + json_return_value = "" response_value.json = mock.Mock(return_value={}) response_value.status_code = 400 response_value.request = mock.Mock() @@ -2636,19 +3435,205 @@ def test_update_product_input_rest_bad_request(request_type=productinputs.Update client.update_product_input(request) -@pytest.mark.parametrize("request_type", [ - productinputs.UpdateProductInputRequest, - dict, -]) +@pytest.mark.parametrize( + "request_type", + [ + productinputs.UpdateProductInputRequest, + dict, + ], +) def test_update_product_input_rest_call_success(request_type): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'product_input': {'name': 'accounts/sample1/productInputs/sample2'}} - request_init["product_input"] = {'name': 'accounts/sample1/productInputs/sample2', 'product': 'product_value', 'legacy_local': True, 'offer_id': 'offer_id_value', 'content_language': 'content_language_value', 'feed_label': 'feed_label_value', 'version_number': 1518, 'product_attributes': {'identifier_exists': True, 'is_bundle': True, 'title': 'title_value', 'description': 'description_value', 'link': 'link_value', 'mobile_link': 'mobile_link_value', 'canonical_link': 'canonical_link_value', 'image_link': 'image_link_value', 'additional_image_links': ['additional_image_links_value1', 'additional_image_links_value2'], 'expiration_date': {'seconds': 751, 'nanos': 543}, 'disclosure_date': {}, 'adult': True, 'age_group': 1, 'availability': 1, 'availability_date': {}, 'brand': 'brand_value', 'color': 'color_value', 'condition': 1, 'gender': 1, 'google_product_category': 'google_product_category_value', 'gtins': ['gtins_value1', 'gtins_value2'], 'item_group_id': 'item_group_id_value', 'material': 'material_value', 'mpn': 'mpn_value', 'pattern': 'pattern_value', 'price': {'amount_micros': 1408, 'currency_code': 'currency_code_value'}, 'maximum_retail_price': {}, 'installment': {'months': 665, 'amount': {}, 'downpayment': {}, 'credit_type': 1}, 'subscription_cost': {'period': 1, 'period_length': 1380, 'amount': {}}, 'loyalty_points': {'name': 'name_value', 'points_value': 1305, 'ratio': 0.543}, 'loyalty_programs': [{'program_label': 'program_label_value', 'tier_label': 'tier_label_value', 'price': {}, 'cashback_for_future_use': {}, 'loyalty_points': 1546, 'member_price_effective_date': {'start_time': {}, 'end_time': {}}, 'shipping_label': 'shipping_label_value'}], 'product_types': ['product_types_value1', 'product_types_value2'], 'sale_price': {}, 'sale_price_effective_date': {}, 'sell_on_google_quantity': 2470, 'product_height': {'value': 0.541, 'unit': 'unit_value'}, 'product_length': {}, 'product_width': {}, 'product_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping': [{'price': {}, 'country': 'country_value', 'region': 'region_value', 'service': 'service_value', 'location_id': 1157, 'location_group_name': 'location_group_name_value', 'postal_code': 'postal_code_value', 'min_handling_time': 1782, 'max_handling_time': 1784, 'min_transit_time': 1718, 'max_transit_time': 1720}], 'free_shipping_threshold': [{'country': 'country_value', 'price_threshold': {}}], 'shipping_weight': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_length': {'value': 0.541, 'unit': 'unit_value'}, 'shipping_width': {}, 'shipping_height': {}, 'max_handling_time': 1784, 'min_handling_time': 1782, 'shipping_label': 'shipping_label_value', 'transit_time_label': 'transit_time_label_value', 'size': 'size_value', 'size_system': 1, 'size_types': [1], 'energy_efficiency_class': 1, 'min_energy_efficiency_class': 1, 'max_energy_efficiency_class': 1, 'unit_pricing_measure': {'value': 0.541, 'unit': 'unit_value'}, 'unit_pricing_base_measure': {'value': 541, 'unit': 'unit_value'}, 'multipack': 970, 'ads_grouping': 'ads_grouping_value', 'ads_labels': ['ads_labels_value1', 'ads_labels_value2'], 'ads_redirect': 'ads_redirect_value', 'cost_of_goods_sold': {}, 'product_details': [{'section_name': 'section_name_value', 'attribute_name': 'attribute_name_value', 'attribute_value': 'attribute_value_value'}], 'product_highlights': ['product_highlights_value1', 'product_highlights_value2'], 'display_ads_id': 'display_ads_id_value', 'display_ads_similar_ids': ['display_ads_similar_ids_value1', 'display_ads_similar_ids_value2'], 'display_ads_title': 'display_ads_title_value', 'display_ads_link': 'display_ads_link_value', 'display_ads_value': 0.1801, 'promotion_ids': ['promotion_ids_value1', 'promotion_ids_value2'], 'pickup_method': 1, 'pickup_sla': 1, 'link_template': 'link_template_value', 'mobile_link_template': 'mobile_link_template_value', 'custom_label_0': 'custom_label_0_value', 'custom_label_1': 'custom_label_1_value', 'custom_label_2': 'custom_label_2_value', 'custom_label_3': 'custom_label_3_value', 'custom_label_4': 'custom_label_4_value', 'included_destinations': [1], 'excluded_destinations': [1], 'shopping_ads_excluded_countries': ['shopping_ads_excluded_countries_value1', 'shopping_ads_excluded_countries_value2'], 'external_seller_id': 'external_seller_id_value', 'pause': 1, 'lifestyle_image_links': ['lifestyle_image_links_value1', 'lifestyle_image_links_value2'], 'cloud_export_additional_properties': [{'property_name': 'property_name_value', 'text_value': ['text_value_value1', 'text_value_value2'], 'bool_value': True, 'int_value': [968, 969], 'float_value': [0.11710000000000001, 0.11720000000000001], 'min_value': 0.96, 'max_value': 0.962, 'unit_code': 'unit_code_value'}], 'virtual_model_link': 'virtual_model_link_value', 'certifications': [{'certification_authority': 1, 'certification_name': 1, 'certification_code': 'certification_code_value', 'certification_value': 'certification_value_value'}], 'structured_title': {'digital_source_type': 1, 'content': 'content_value'}, 'structured_description': {'digital_source_type': 1, 'content': 'content_value'}, 'auto_pricing_min_price': {}, 'sustainability_incentives': [{'amount': {}, 'percentage': 0.10540000000000001, 'type_': 1}]}, 'custom_attributes': [{'name': 'name_value', 'value': 'value_value', 'group_values': {}}]} + request_init = {"product_input": {"name": "accounts/sample1/productInputs/sample2"}} + request_init["product_input"] = { + "name": "accounts/sample1/productInputs/sample2", + "product": "product_value", + "legacy_local": True, + "offer_id": "offer_id_value", + "content_language": "content_language_value", + "feed_label": "feed_label_value", + "version_number": 1518, + "product_attributes": { + "identifier_exists": True, + "is_bundle": True, + "title": "title_value", + "description": "description_value", + "link": "link_value", + "mobile_link": "mobile_link_value", + "canonical_link": "canonical_link_value", + "image_link": "image_link_value", + "additional_image_links": [ + "additional_image_links_value1", + "additional_image_links_value2", + ], + "expiration_date": {"seconds": 751, "nanos": 543}, + "disclosure_date": {}, + "adult": True, + "age_group": 1, + "availability": 1, + "availability_date": {}, + "brand": "brand_value", + "color": "color_value", + "condition": 1, + "gender": 1, + "google_product_category": "google_product_category_value", + "gtins": ["gtins_value1", "gtins_value2"], + "item_group_id": "item_group_id_value", + "material": "material_value", + "mpn": "mpn_value", + "pattern": "pattern_value", + "price": {"amount_micros": 1408, "currency_code": "currency_code_value"}, + "maximum_retail_price": {}, + "installment": { + "months": 665, + "amount": {}, + "downpayment": {}, + "credit_type": 1, + }, + "subscription_cost": {"period": 1, "period_length": 1380, "amount": {}}, + "loyalty_points": { + "name": "name_value", + "points_value": 1305, + "ratio": 0.543, + }, + "loyalty_programs": [ + { + "program_label": "program_label_value", + "tier_label": "tier_label_value", + "price": {}, + "cashback_for_future_use": {}, + "loyalty_points": 1546, + "member_price_effective_date": {"start_time": {}, "end_time": {}}, + "shipping_label": "shipping_label_value", + } + ], + "product_types": ["product_types_value1", "product_types_value2"], + "sale_price": {}, + "sale_price_effective_date": {}, + "sell_on_google_quantity": 2470, + "product_height": {"value": 0.541, "unit": "unit_value"}, + "product_length": {}, + "product_width": {}, + "product_weight": {"value": 0.541, "unit": "unit_value"}, + "shipping": [ + { + "price": {}, + "country": "country_value", + "region": "region_value", + "service": "service_value", + "location_id": 1157, + "location_group_name": "location_group_name_value", + "postal_code": "postal_code_value", + "min_handling_time": 1782, + "max_handling_time": 1784, + "min_transit_time": 1718, + "max_transit_time": 1720, + } + ], + "free_shipping_threshold": [ + {"country": "country_value", "price_threshold": {}} + ], + "shipping_weight": {"value": 0.541, "unit": "unit_value"}, + "shipping_length": {"value": 0.541, "unit": "unit_value"}, + "shipping_width": {}, + "shipping_height": {}, + "max_handling_time": 1784, + "min_handling_time": 1782, + "shipping_label": "shipping_label_value", + "transit_time_label": "transit_time_label_value", + "size": "size_value", + "size_system": 1, + "size_types": [1], + "energy_efficiency_class": 1, + "min_energy_efficiency_class": 1, + "max_energy_efficiency_class": 1, + "unit_pricing_measure": {"value": 0.541, "unit": "unit_value"}, + "unit_pricing_base_measure": {"value": 541, "unit": "unit_value"}, + "multipack": 970, + "ads_grouping": "ads_grouping_value", + "ads_labels": ["ads_labels_value1", "ads_labels_value2"], + "ads_redirect": "ads_redirect_value", + "cost_of_goods_sold": {}, + "product_details": [ + { + "section_name": "section_name_value", + "attribute_name": "attribute_name_value", + "attribute_value": "attribute_value_value", + } + ], + "product_highlights": [ + "product_highlights_value1", + "product_highlights_value2", + ], + "display_ads_id": "display_ads_id_value", + "display_ads_similar_ids": [ + "display_ads_similar_ids_value1", + "display_ads_similar_ids_value2", + ], + "display_ads_title": "display_ads_title_value", + "display_ads_link": "display_ads_link_value", + "display_ads_value": 0.1801, + "promotion_ids": ["promotion_ids_value1", "promotion_ids_value2"], + "pickup_method": 1, + "pickup_sla": 1, + "link_template": "link_template_value", + "mobile_link_template": "mobile_link_template_value", + "custom_label_0": "custom_label_0_value", + "custom_label_1": "custom_label_1_value", + "custom_label_2": "custom_label_2_value", + "custom_label_3": "custom_label_3_value", + "custom_label_4": "custom_label_4_value", + "included_destinations": [1], + "excluded_destinations": [1], + "shopping_ads_excluded_countries": [ + "shopping_ads_excluded_countries_value1", + "shopping_ads_excluded_countries_value2", + ], + "external_seller_id": "external_seller_id_value", + "pause": 1, + "lifestyle_image_links": [ + "lifestyle_image_links_value1", + "lifestyle_image_links_value2", + ], + "cloud_export_additional_properties": [ + { + "property_name": "property_name_value", + "text_value": ["text_value_value1", "text_value_value2"], + "bool_value": True, + "int_value": [968, 969], + "float_value": [0.11710000000000001, 0.11720000000000001], + "min_value": 0.96, + "max_value": 0.962, + "unit_code": "unit_code_value", + } + ], + "virtual_model_link": "virtual_model_link_value", + "certifications": [ + { + "certification_authority": 1, + "certification_name": 1, + "certification_code": "certification_code_value", + "certification_value": "certification_value_value", + } + ], + "structured_title": {"digital_source_type": 1, "content": "content_value"}, + "structured_description": { + "digital_source_type": 1, + "content": "content_value", + }, + "auto_pricing_min_price": {}, + "sustainability_incentives": [ + {"amount": {}, "percentage": 0.10540000000000001, "type_": 1} + ], + }, + "custom_attributes": [ + {"name": "name_value", "value": "value_value", "group_values": {}} + ], + } # The version of a generated dependency at test runtime may differ from the version used during generation. # Delete any fields which are not present in the current runtime dependency # See https://github.com/googleapis/gapic-generator-python/issues/1748 @@ -2668,7 +3653,7 @@ def get_message_fields(field): if is_field_type_proto_plus_type: message_fields = field.message.meta.fields.values() # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types - else: # pragma: NO COVER + else: # pragma: NO COVER message_fields = field.message.DESCRIPTOR.fields return message_fields @@ -2682,7 +3667,7 @@ def get_message_fields(field): # For each item in the sample request, create a list of sub fields which are not present at runtime # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for field, value in request_init["product_input"].items(): # pragma: NO COVER + for field, value in request_init["product_input"].items(): # pragma: NO COVER result = None is_repeated = False # For repeated fields @@ -2697,12 +3682,16 @@ def get_message_fields(field): for subfield in result.keys(): if (field, subfield) not in runtime_nested_fields: subfields_not_in_runtime.append( - {"field": field, "subfield": subfield, "is_repeated": is_repeated} + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } ) # Remove fields from the sample request which are not present in the runtime version of the dependency # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime - for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER field = subfield_to_delete.get("field") field_repeated = subfield_to_delete.get("is_repeated") subfield = subfield_to_delete.get("subfield") @@ -2715,16 +3704,16 @@ def get_message_fields(field): request = request_type(**request_init) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = productinputs.ProductInput( - name='name_value', - product='product_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - version_number=1518, + name="name_value", + product="product_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + version_number=1518, ) # Wrap the value into a proper Response obj @@ -2734,19 +3723,19 @@ def get_message_fields(field): # Convert return value to protobuf type return_value = productinputs.ProductInput.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') + response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.update_product_input(request) # Establish that the response is the type that we expect. assert isinstance(response, productinputs.ProductInput) - assert response.name == 'name_value' - assert response.product == 'product_value' + assert response.name == "name_value" + assert response.product == "product_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" assert response.version_number == 1518 @@ -2754,19 +3743,30 @@ def get_message_fields(field): def test_update_product_input_rest_interceptors(null_interceptor): transport = transports.ProductInputsServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), - ) + interceptor=None + if null_interceptor + else transports.ProductInputsServiceRestInterceptor(), + ) client = ProductInputsServiceClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input") as post, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "post_update_product_input_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_update_product_input") as pre: + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, "post_update_product_input" + ) as post, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, + "post_update_product_input_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, "pre_update_product_input" + ) as pre: pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() - pb_message = productinputs.UpdateProductInputRequest.pb(productinputs.UpdateProductInputRequest()) + pb_message = productinputs.UpdateProductInputRequest.pb( + productinputs.UpdateProductInputRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -2781,7 +3781,7 @@ def test_update_product_input_rest_interceptors(null_interceptor): req.return_value.content = return_value request = productinputs.UpdateProductInputRequest() - metadata =[ + metadata = [ ("key", "val"), ("cephalopod", "squid"), ] @@ -2789,27 +3789,36 @@ def test_update_product_input_rest_interceptors(null_interceptor): post.return_value = productinputs.ProductInput() post_with_metadata.return_value = productinputs.ProductInput(), metadata - client.update_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + client.update_product_input( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) pre.assert_called_once() post.assert_called_once() post_with_metadata.assert_called_once() -def test_delete_product_input_rest_bad_request(request_type=productinputs.DeleteProductInputRequest): +def test_delete_product_input_rest_bad_request( + request_type=productinputs.DeleteProductInputRequest, +): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/productInputs/sample2'} + request_init = {"name": "accounts/sample1/productInputs/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): # Wrap the value into a proper Response obj response_value = mock.Mock() - json_return_value = '' + json_return_value = "" response_value.json = mock.Mock(return_value={}) response_value.status_code = 400 response_value.request = mock.Mock() @@ -2818,30 +3827,32 @@ def test_delete_product_input_rest_bad_request(request_type=productinputs.Delete client.delete_product_input(request) -@pytest.mark.parametrize("request_type", [ - productinputs.DeleteProductInputRequest, - dict, -]) +@pytest.mark.parametrize( + "request_type", + [ + productinputs.DeleteProductInputRequest, + dict, + ], +) def test_delete_product_input_rest_call_success(request_type): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/productInputs/sample2'} + request_init = {"name": "accounts/sample1/productInputs/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = None # Wrap the value into a proper Response obj response_value = mock.Mock() response_value.status_code = 200 - json_return_value = '' - response_value.content = json_return_value.encode('UTF-8') + json_return_value = "" + response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.delete_product_input(request) @@ -2854,15 +3865,23 @@ def test_delete_product_input_rest_call_success(request_type): def test_delete_product_input_rest_interceptors(null_interceptor): transport = transports.ProductInputsServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductInputsServiceRestInterceptor(), - ) + interceptor=None + if null_interceptor + else transports.ProductInputsServiceRestInterceptor(), + ) client = ProductInputsServiceClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductInputsServiceRestInterceptor, "pre_delete_product_input") as pre: + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.ProductInputsServiceRestInterceptor, "pre_delete_product_input" + ) as pre: pre.assert_not_called() - pb_message = productinputs.DeleteProductInputRequest.pb(productinputs.DeleteProductInputRequest()) + pb_message = productinputs.DeleteProductInputRequest.pb( + productinputs.DeleteProductInputRequest() + ) transcode.return_value = { "method": "post", "uri": "my_uri", @@ -2875,20 +3894,26 @@ def test_delete_product_input_rest_interceptors(null_interceptor): req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} request = productinputs.DeleteProductInputRequest() - metadata =[ + metadata = [ ("key", "val"), ("cephalopod", "squid"), ] pre.return_value = request, metadata - client.delete_product_input(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + client.delete_product_input( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) pre.assert_called_once() + def test_initialize_client_w_rest(): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) assert client is not None @@ -2903,8 +3928,8 @@ def test_insert_product_input_empty_call_rest(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.insert_product_input), - '__call__') as call: + type(client.transport.insert_product_input), "__call__" + ) as call: client.insert_product_input(request=None) # Establish that the underlying stub method was called. @@ -2925,8 +3950,8 @@ def test_update_product_input_empty_call_rest(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.update_product_input), - '__call__') as call: + type(client.transport.update_product_input), "__call__" + ) as call: client.update_product_input(request=None) # Establish that the underlying stub method was called. @@ -2947,8 +3972,8 @@ def test_delete_product_input_empty_call_rest(): # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.delete_product_input), - '__call__') as call: + type(client.transport.delete_product_input), "__call__" + ) as call: client.delete_product_input(request=None) # Establish that the underlying stub method was called. @@ -2969,18 +3994,21 @@ def test_transport_grpc_default(): transports.ProductInputsServiceGrpcTransport, ) + def test_product_inputs_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ProductInputsServiceTransport( credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" + credentials_file="credentials.json", ) def test_product_inputs_service_base_transport(): # Instantiate the base transport. - with mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport.__init__') as Transport: + with mock.patch( + "google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport.__init__" + ) as Transport: Transport.return_value = None transport = transports.ProductInputsServiceTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2989,9 +4017,9 @@ def test_product_inputs_service_base_transport(): # Every method on the transport should just blindly # raise NotImplementedError. methods = ( - 'insert_product_input', - 'update_product_input', - 'delete_product_input', + "insert_product_input", + "update_product_input", + "delete_product_input", ) for method in methods: with pytest.raises(NotImplementedError): @@ -3002,7 +4030,7 @@ def test_product_inputs_service_base_transport(): # Catch all for all remaining methods and properties remainder = [ - 'kind', + "kind", ] for r in remainder: with pytest.raises(NotImplementedError): @@ -3011,25 +4039,30 @@ def test_product_inputs_service_base_transport(): def test_product_inputs_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages" + ) as Transport: Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductInputsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) - load_creds.assert_called_once_with("credentials.json", + load_creds.assert_called_once_with( + "credentials.json", scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), quota_project_id="octopus", ) def test_product_inputs_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages') as Transport: + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.shopping.merchant_products_v1.services.product_inputs_service.transports.ProductInputsServiceTransport._prep_wrapped_messages" + ) as Transport: Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductInputsServiceTransport() @@ -3038,14 +4071,12 @@ def test_product_inputs_service_base_transport_with_adc(): def test_product_inputs_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: + with mock.patch.object(google.auth, "default", autospec=True) as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) ProductInputsServiceClient() adc.assert_called_once_with( scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), quota_project_id=None, ) @@ -3060,12 +4091,12 @@ def test_product_inputs_service_auth_adc(): def test_product_inputs_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: + with mock.patch.object(google.auth, "default", autospec=True) as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/content',), + default_scopes=("https://www.googleapis.com/auth/content",), quota_project_id="octopus", ) @@ -3079,48 +4110,45 @@ def test_product_inputs_service_transport_auth_adc(transport_class): ], ) def test_product_inputs_service_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] + host = "https://language.com" + api_audience_tests = [None, "https://language2.com"] + api_audience_expect = [host, "https://language2.com"] for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: + with mock.patch.object(google.auth, "default", autospec=True) as adc: gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + type(gdch_mock).with_gdch_audience = mock.PropertyMock( + return_value=gdch_mock + ) adc.return_value = (gdch_mock, None) transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) + gdch_mock.with_gdch_audience.assert_called_once_with(e) @pytest.mark.parametrize( "transport_class,grpc_helpers", [ (transports.ProductInputsServiceGrpcTransport, grpc_helpers), - (transports.ProductInputsServiceGrpcAsyncIOTransport, grpc_helpers_async) + (transports.ProductInputsServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) def test_product_inputs_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( "merchantapi.googleapis.com:443", credentials=creds, credentials_file=None, quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), scopes=["1", "2"], default_host="merchantapi.googleapis.com", ssl_credentials=None, @@ -3131,9 +4159,15 @@ def test_product_inputs_service_transport_create_channel(transport_class, grpc_h ) -@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + ], +) def test_product_inputs_service_grpc_transport_client_cert_source_for_mtls( - transport_class + transport_class, ): cred = ga_credentials.AnonymousCredentials() @@ -3143,7 +4177,7 @@ def test_product_inputs_service_grpc_transport_client_cert_source_for_mtls( transport_class( host="squid.clam.whelk", credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds + ssl_channel_credentials=mock_ssl_channel_creds, ) mock_create_channel.assert_called_once_with( "squid.clam.whelk:443", @@ -3164,61 +4198,77 @@ def test_product_inputs_service_grpc_transport_client_cert_source_for_mtls( with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: transport_class( credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback + client_cert_source_for_mtls=client_cert_source_callback, ) expected_cert, expected_key = client_cert_source_callback() mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key + certificate_chain=expected_cert, private_key=expected_key ) + def test_product_inputs_service_http_transport_client_cert_source_for_mtls(): cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.ProductInputsServiceRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback + with mock.patch( + "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" + ) as mock_configure_mtls_channel: + transports.ProductInputsServiceRestTransport( + credentials=cred, client_cert_source_for_mtls=client_cert_source_callback ) mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + "rest", + ], +) def test_product_inputs_service_host_no_port(transport_name): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), - transport=transport_name, + client_options=client_options.ClientOptions( + api_endpoint="merchantapi.googleapis.com" + ), + transport=transport_name, ) assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com' + "merchantapi.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com" ) -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + "rest", + ], +) def test_product_inputs_service_host_with_port(transport_name): client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), + client_options=client_options.ClientOptions( + api_endpoint="merchantapi.googleapis.com:8000" + ), transport=transport_name, ) assert client.transport._host == ( - 'merchantapi.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com:8000' + "merchantapi.googleapis.com:8000" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com:8000" ) -@pytest.mark.parametrize("transport_name", [ - "rest", -]) + +@pytest.mark.parametrize( + "transport_name", + [ + "rest", + ], +) def test_product_inputs_service_client_transport_session_collision(transport_name): creds1 = ga_credentials.AnonymousCredentials() creds2 = ga_credentials.AnonymousCredentials() @@ -3239,8 +4289,10 @@ def test_product_inputs_service_client_transport_session_collision(transport_nam session1 = client1.transport.delete_product_input._session session2 = client2.transport.delete_product_input._session assert session1 != session2 + + def test_product_inputs_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductInputsServiceGrpcTransport( @@ -3253,7 +4305,7 @@ def test_product_inputs_service_grpc_transport_channel(): def test_product_inputs_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductInputsServiceGrpcAsyncIOTransport( @@ -3267,12 +4319,22 @@ def test_product_inputs_service_grpc_asyncio_transport_channel(): # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are # removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + ], +) def test_product_inputs_service_transport_channel_mtls_with_client_cert_source( - transport_class + transport_class, ): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -3281,7 +4343,7 @@ def test_product_inputs_service_transport_channel_mtls_with_client_cert_source( cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -3311,17 +4373,23 @@ def test_product_inputs_service_transport_channel_mtls_with_client_cert_source( # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are # removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductInputsServiceGrpcTransport, transports.ProductInputsServiceGrpcAsyncIOTransport]) -def test_product_inputs_service_transport_channel_mtls_with_adc( - transport_class -): +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductInputsServiceGrpcTransport, + transports.ProductInputsServiceGrpcAsyncIOTransport, + ], +) +def test_product_inputs_service_transport_channel_mtls_with_adc(transport_class): mock_ssl_cred = mock.Mock() with mock.patch.multiple( "google.auth.transport.grpc.SslCredentials", __init__=mock.Mock(return_value=None), ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel mock_cred = mock.Mock() @@ -3352,7 +4420,10 @@ def test_product_inputs_service_transport_channel_mtls_with_adc( def test_product_path(): account = "squid" product = "clam" - expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) + expected = "accounts/{account}/products/{product}".format( + account=account, + product=product, + ) actual = ProductInputsServiceClient.product_path(account, product) assert expected == actual @@ -3368,10 +4439,14 @@ def test_parse_product_path(): actual = ProductInputsServiceClient.parse_product_path(path) assert expected == actual + def test_product_input_path(): account = "oyster" productinput = "nudibranch" - expected = "accounts/{account}/productInputs/{productinput}".format(account=account, productinput=productinput, ) + expected = "accounts/{account}/productInputs/{productinput}".format( + account=account, + productinput=productinput, + ) actual = ProductInputsServiceClient.product_input_path(account, productinput) assert expected == actual @@ -3387,9 +4462,12 @@ def test_parse_product_input_path(): actual = ProductInputsServiceClient.parse_product_input_path(path) assert expected == actual + def test_common_billing_account_path(): billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) actual = ProductInputsServiceClient.common_billing_account_path(billing_account) assert expected == actual @@ -3404,9 +4482,12 @@ def test_parse_common_billing_account_path(): actual = ProductInputsServiceClient.parse_common_billing_account_path(path) assert expected == actual + def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder, ) + expected = "folders/{folder}".format( + folder=folder, + ) actual = ProductInputsServiceClient.common_folder_path(folder) assert expected == actual @@ -3421,9 +4502,12 @@ def test_parse_common_folder_path(): actual = ProductInputsServiceClient.parse_common_folder_path(path) assert expected == actual + def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization, ) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = ProductInputsServiceClient.common_organization_path(organization) assert expected == actual @@ -3438,9 +4522,12 @@ def test_parse_common_organization_path(): actual = ProductInputsServiceClient.parse_common_organization_path(path) assert expected == actual + def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project, ) + expected = "projects/{project}".format( + project=project, + ) actual = ProductInputsServiceClient.common_project_path(project) assert expected == actual @@ -3455,10 +4542,14 @@ def test_parse_common_project_path(): actual = ProductInputsServiceClient.parse_common_project_path(path) assert expected == actual + def test_common_location_path(): project = "oyster" location = "nudibranch" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) actual = ProductInputsServiceClient.common_location_path(project, location) assert expected == actual @@ -3478,14 +4569,18 @@ def test_parse_common_location_path(): def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: + with mock.patch.object( + transports.ProductInputsServiceTransport, "_prep_wrapped_messages" + ) as prep: client = ProductInputsServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) - with mock.patch.object(transports.ProductInputsServiceTransport, '_prep_wrapped_messages') as prep: + with mock.patch.object( + transports.ProductInputsServiceTransport, "_prep_wrapped_messages" + ) as prep: transport_class = ProductInputsServiceClient.get_transport_class() transport = transport_class( credentials=ga_credentials.AnonymousCredentials(), @@ -3496,10 +4591,11 @@ def test_client_with_default_client_info(): def test_transport_close_grpc(): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" + credentials=ga_credentials.AnonymousCredentials(), transport="grpc" ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with mock.patch.object( + type(getattr(client.transport, "_grpc_channel")), "close" + ) as close: with client: close.assert_not_called() close.assert_called_once() @@ -3508,10 +4604,11 @@ def test_transport_close_grpc(): @pytest.mark.asyncio async def test_transport_close_grpc_asyncio(): client = ProductInputsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" + credentials=async_anonymous_credentials(), transport="grpc_asyncio" ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with mock.patch.object( + type(getattr(client.transport, "_grpc_channel")), "close" + ) as close: async with client: close.assert_not_called() close.assert_called_once() @@ -3519,10 +4616,11 @@ async def test_transport_close_grpc_asyncio(): def test_transport_close_rest(): client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: + with mock.patch.object( + type(getattr(client.transport, "_session")), "close" + ) as close: with client: close.assert_not_called() close.assert_called_once() @@ -3530,13 +4628,12 @@ def test_transport_close_rest(): def test_client_ctx(): transports = [ - 'rest', - 'grpc', + "rest", + "grpc", ] for transport in transports: client = ProductInputsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3545,10 +4642,17 @@ def test_client_ctx(): pass close.assert_called() -@pytest.mark.parametrize("client_class,transport_class", [ - (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport), - (ProductInputsServiceAsyncClient, transports.ProductInputsServiceGrpcAsyncIOTransport), -]) + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ProductInputsServiceClient, transports.ProductInputsServiceGrpcTransport), + ( + ProductInputsServiceAsyncClient, + transports.ProductInputsServiceGrpcAsyncIOTransport, + ), + ], +) def test_api_key_credentials(client_class, transport_class): with mock.patch.object( google.auth._default, "get_api_key_credentials", create=True @@ -3563,7 +4667,9 @@ def test_api_key_credentials(client_class, transport_class): patched.assert_called_once_with( credentials=mock_cred, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, diff --git a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py b/packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/test_products_service.py similarity index 68% rename from owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py rename to packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/test_products_service.py index 63ae6fc1b949..21e9a8631644 100644 --- a/owl-bot-staging/google-shopping-merchant-products/v1/tests/unit/gapic/merchant_products_v1/test_products_service.py +++ b/packages/google-shopping-merchant-products/tests/unit/gapic/merchant_products_v1/test_products_service.py @@ -14,6 +14,7 @@ # limitations under the License. # import os + # try/except added for compatibility with python < 3.8 try: from unittest import mock @@ -21,47 +22,44 @@ except ImportError: # pragma: NO COVER import mock -import grpc -from grpc.experimental import aio -from collections.abc import Iterable, AsyncIterable -from google.protobuf import json_format +from collections.abc import AsyncIterable, Iterable import json import math -import pytest + from google.api_core import api_core_version -from proto.marshal.rules.dates import DurationRule, TimestampRule +from google.protobuf import json_format +import grpc +from grpc.experimental import aio from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest +from proto.marshal.rules.dates import DurationRule, TimestampRule +import pytest +from requests import PreparedRequest, Request, Response from requests.sessions import Session -from google.protobuf import json_format try: from google.auth.aio import credentials as ga_credentials_async + HAS_GOOGLE_AUTH_AIO = True -except ImportError: # pragma: NO COVER +except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False +from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template from google.api_core import client_options from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import path_template from google.api_core import retry as retries +import google.auth from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.oauth2 import service_account -from google.shopping.merchant_products_v1.services.products_service import ProductsServiceAsyncClient -from google.shopping.merchant_products_v1.services.products_service import ProductsServiceClient -from google.shopping.merchant_products_v1.services.products_service import pagers -from google.shopping.merchant_products_v1.services.products_service import transports -from google.shopping.merchant_products_v1.types import products -from google.shopping.merchant_products_v1.types import products_common from google.shopping.type.types import types -import google.auth - +from google.shopping.merchant_products_v1.services.products_service import ( + ProductsServiceAsyncClient, + ProductsServiceClient, + pagers, + transports, +) +from google.shopping.merchant_products_v1.types import products, products_common CRED_INFO_JSON = { "credential_source": "/path/to/file", @@ -76,9 +74,11 @@ async def mock_async_gen(data, chunk_size=1): chunk = data[i : i + chunk_size] yield chunk.encode("utf-8") + def client_cert_source_callback(): return b"cert bytes", b"key bytes" + # TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded. # See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107. def async_anonymous_credentials(): @@ -86,17 +86,27 @@ def async_anonymous_credentials(): return ga_credentials_async.AnonymousCredentials() return ga_credentials.AnonymousCredentials() + # If default endpoint is localhost, then default mtls endpoint will be the same. # This method modifies the default endpoint so the client can produce a different # mtls endpoint for endpoint testing purposes. def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + # If default endpoint template is localhost, then default mtls endpoint will be the same. # This method modifies the default endpoint template so the client can produce a different # mtls endpoint for endpoint testing purposes. def modify_default_endpoint_template(client): - return "test.{UNIVERSE_DOMAIN}" if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) else client._DEFAULT_ENDPOINT_TEMPLATE + return ( + "test.{UNIVERSE_DOMAIN}" + if ("localhost" in client._DEFAULT_ENDPOINT_TEMPLATE) + else client._DEFAULT_ENDPOINT_TEMPLATE + ) def test__get_default_mtls_endpoint(): @@ -107,101 +117,228 @@ def test__get_default_mtls_endpoint(): non_googleapi = "api.example.com" assert ProductsServiceClient._get_default_mtls_endpoint(None) is None - assert ProductsServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert ProductsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ( + ProductsServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + ProductsServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + ProductsServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + ProductsServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + ProductsServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + ) + def test__read_environment_variables(): assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - assert ProductsServiceClient._read_environment_variables() == (True, "auto", None) + assert ProductsServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + assert ProductsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): with pytest.raises(ValueError) as excinfo: ProductsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - assert ProductsServiceClient._read_environment_variables() == (False, "never", None) + assert ProductsServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - assert ProductsServiceClient._read_environment_variables() == (False, "always", None) + assert ProductsServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", None) + assert ProductsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError) as excinfo: ProductsServiceClient._read_environment_variables() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}): - assert ProductsServiceClient._read_environment_variables() == (False, "auto", "foo.com") + assert ProductsServiceClient._read_environment_variables() == ( + False, + "auto", + "foo.com", + ) + def test__get_client_cert_source(): mock_provided_cert_source = mock.Mock() mock_default_cert_source = mock.Mock() assert ProductsServiceClient._get_client_cert_source(None, False) is None - assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, False) is None - assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, True) == mock_provided_cert_source + assert ( + ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, True) + == mock_provided_cert_source + ) + + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", return_value=True + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_default_cert_source, + ): + assert ( + ProductsServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ProductsServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_default_cert_source): - assert ProductsServiceClient._get_client_cert_source(None, True) is mock_default_cert_source - assert ProductsServiceClient._get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +@mock.patch.object( + ProductsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceClient), +) +@mock.patch.object( + ProductsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceAsyncClient), +) def test__get_api_endpoint(): api_override = "foo.com" mock_client_cert_source = mock.Mock() default_universe = ProductsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) mock_universe = "bar.com" - mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) - assert ProductsServiceClient._get_api_endpoint(api_override, mock_client_cert_source, default_universe, "always") == api_override - assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "auto") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "auto") == default_endpoint - assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, default_universe, "always") == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT - assert ProductsServiceClient._get_api_endpoint(None, None, mock_universe, "never") == mock_endpoint - assert ProductsServiceClient._get_api_endpoint(None, None, default_universe, "never") == default_endpoint + assert ( + ProductsServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ProductsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ProductsServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ProductsServiceClient._get_api_endpoint(None, None, default_universe, "always") + == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ProductsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ProductsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ProductsServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ProductsServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) with pytest.raises(MutualTLSChannelError) as excinfo: - ProductsServiceClient._get_api_endpoint(None, mock_client_cert_source, mock_universe, "auto") - assert str(excinfo.value) == "mTLS is not supported in any universe other than googleapis.com." + ProductsServiceClient._get_api_endpoint( + None, mock_client_cert_source, mock_universe, "auto" + ) + assert ( + str(excinfo.value) + == "mTLS is not supported in any universe other than googleapis.com." + ) def test__get_universe_domain(): client_universe_domain = "foo.com" universe_domain_env = "bar.com" - assert ProductsServiceClient._get_universe_domain(client_universe_domain, universe_domain_env) == client_universe_domain - assert ProductsServiceClient._get_universe_domain(None, universe_domain_env) == universe_domain_env - assert ProductsServiceClient._get_universe_domain(None, None) == ProductsServiceClient._DEFAULT_UNIVERSE + assert ( + ProductsServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ProductsServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ProductsServiceClient._get_universe_domain(None, None) + == ProductsServiceClient._DEFAULT_UNIVERSE + ) with pytest.raises(ValueError) as excinfo: ProductsServiceClient._get_universe_domain("", None) assert str(excinfo.value) == "Universe Domain cannot be an empty string." -@pytest.mark.parametrize("error_code,cred_info_json,show_cred_info", [ - (401, CRED_INFO_JSON, True), - (403, CRED_INFO_JSON, True), - (404, CRED_INFO_JSON, True), - (500, CRED_INFO_JSON, False), - (401, None, False), - (403, None, False), - (404, None, False), - (500, None, False) -]) + +@pytest.mark.parametrize( + "error_code,cred_info_json,show_cred_info", + [ + (401, CRED_INFO_JSON, True), + (403, CRED_INFO_JSON, True), + (404, CRED_INFO_JSON, True), + (500, CRED_INFO_JSON, False), + (401, None, False), + (403, None, False), + (404, None, False), + (500, None, False), + ], +) def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_info): cred = mock.Mock(["get_cred_info"]) cred.get_cred_info = mock.Mock(return_value=cred_info_json) @@ -217,7 +354,8 @@ def test__add_cred_info_for_auth_errors(error_code, cred_info_json, show_cred_in else: assert error.details == ["foo"] -@pytest.mark.parametrize("error_code", [401,403,404,500]) + +@pytest.mark.parametrize("error_code", [401, 403, 404, 500]) def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): cred = mock.Mock([]) assert not hasattr(cred, "get_cred_info") @@ -230,14 +368,22 @@ def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): client._add_cred_info_for_auth_errors(error) assert error.details == [] -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductsServiceClient, "grpc"), - (ProductsServiceAsyncClient, "grpc_asyncio"), - (ProductsServiceClient, "rest"), -]) -def test_products_service_client_from_service_account_info(client_class, transport_name): + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ProductsServiceClient, "grpc"), + (ProductsServiceAsyncClient, "grpc_asyncio"), + (ProductsServiceClient, "rest"), + ], +) +def test_products_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: factory.return_value = creds info = {"valid": True} client = client_class.from_service_account_info(info, transport=transport_name) @@ -245,52 +391,70 @@ def test_products_service_client_from_service_account_info(client_class, transpo assert isinstance(client, client_class) assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' + "merchantapi.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com" ) -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.ProductsServiceGrpcTransport, "grpc"), - (transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.ProductsServiceRestTransport, "rest"), -]) -def test_products_service_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.ProductsServiceGrpcTransport, "grpc"), + (transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.ProductsServiceRestTransport, "rest"), + ], +) +def test_products_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: creds = service_account.Credentials(None, None, None) transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: creds = service_account.Credentials(None, None, None) transport = transport_class(credentials=creds, always_use_jwt_access=False) use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class,transport_name", [ - (ProductsServiceClient, "grpc"), - (ProductsServiceAsyncClient, "grpc_asyncio"), - (ProductsServiceClient, "rest"), -]) -def test_products_service_client_from_service_account_file(client_class, transport_name): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ProductsServiceClient, "grpc"), + (ProductsServiceAsyncClient, "grpc_asyncio"), + (ProductsServiceClient, "rest"), + ], +) +def test_products_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://merchantapi.googleapis.com' + "merchantapi.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com" ) @@ -306,30 +470,45 @@ def test_products_service_client_get_transport_class(): assert transport == transports.ProductsServiceGrpcTransport -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), -]) -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) -def test_products_service_client_client_options(client_class, transport_class, transport_name): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), + ( + ProductsServiceAsyncClient, + transports.ProductsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), + ], +) +@mock.patch.object( + ProductsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceClient), +) +@mock.patch.object( + ProductsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceAsyncClient), +) +def test_products_service_client_client_options( + client_class, transport_class, transport_name +): # Check that if channel is provided we won't create a new one. - with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) + with mock.patch.object(ProductsServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() # Check that if channel is provided via str we will create a new one. - with mock.patch.object(ProductsServiceClient, 'get_transport_class') as gtc: + with mock.patch.object(ProductsServiceClient, "get_transport_class") as gtc: client = client_class(transport=transport_name) gtc.assert_called() # Check the case api_endpoint is provided. options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( @@ -347,13 +526,15 @@ def test_products_service_client_client_options(client_class, transport_class, t # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "never". with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -365,7 +546,7 @@ def test_products_service_client_client_options(client_class, transport_class, t # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is # "always". with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(transport=transport_name) patched.assert_called_once_with( @@ -385,23 +566,33 @@ def test_products_service_client_client_options(client_class, transport_class, t with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError) as excinfo: client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): with pytest.raises(ValueError) as excinfo: client = client_class(transport=transport_name) - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id="octopus", @@ -410,48 +601,102 @@ def test_products_service_client_client_options(client_class, transport_class, t api_audience=None, ) # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: + options = client_options.ClientOptions( + api_audience="https://language.googleapis.com" + ) + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "true"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", "false"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "true"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", "false"), -]) -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) + api_audience="https://language.googleapis.com", + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + ProductsServiceClient, + transports.ProductsServiceGrpcTransport, + "grpc", + "true", + ), + ( + ProductsServiceAsyncClient, + transports.ProductsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + ProductsServiceClient, + transports.ProductsServiceGrpcTransport, + "grpc", + "false", + ), + ( + ProductsServiceAsyncClient, + transports.ProductsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ( + ProductsServiceClient, + transports.ProductsServiceRestTransport, + "rest", + "true", + ), + ( + ProductsServiceClient, + transports.ProductsServiceRestTransport, + "rest", + "false", + ), + ], +) +@mock.patch.object( + ProductsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceClient), +) +@mock.patch.object( + ProductsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceAsyncClient), +) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_products_service_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): +def test_products_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. # Check the case client_cert_source is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ) else: expected_client_cert_source = client_cert_source_callback expected_host = client.DEFAULT_MTLS_ENDPOINT @@ -470,12 +715,22 @@ def test_products_service_client_mtls_env_auto(client_class, transport_class, tr # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): if use_client_cert_env == "false": - expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE) + expected_host = client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ) expected_client_cert_source = None else: expected_host = client.DEFAULT_MTLS_ENDPOINT @@ -496,15 +751,22 @@ def test_products_service_client_mtls_env_auto(client_class, transport_class, tr ) # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): patched.return_value = None client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -514,19 +776,31 @@ def test_products_service_client_mtls_env_auto(client_class, transport_class, tr ) -@pytest.mark.parametrize("client_class", [ - ProductsServiceClient, ProductsServiceAsyncClient -]) -@mock.patch.object(ProductsServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ProductsServiceAsyncClient)) +@pytest.mark.parametrize( + "client_class", [ProductsServiceClient, ProductsServiceAsyncClient] +) +@mock.patch.object( + ProductsServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductsServiceClient), +) +@mock.patch.object( + ProductsServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ProductsServiceAsyncClient), +) def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class): mock_client_cert_source = mock.Mock() # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) assert api_endpoint == mock_api_endpoint assert cert_source == mock_client_cert_source @@ -534,8 +808,12 @@ def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class) with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): mock_client_cert_source = mock.Mock() mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) assert api_endpoint == mock_api_endpoint assert cert_source is None @@ -553,16 +831,28 @@ def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class) # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() assert api_endpoint == client_class.DEFAULT_ENDPOINT assert cert_source is None # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source @@ -572,34 +862,62 @@ def test_products_service_client_get_mtls_endpoint_and_cert_source(client_class) with pytest.raises(MutualTLSChannelError) as excinfo: client_class.get_mtls_endpoint_and_cert_source() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): with pytest.raises(ValueError) as excinfo: client_class.get_mtls_endpoint_and_cert_source() - assert str(excinfo.value) == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + assert ( + str(excinfo.value) + == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + -@pytest.mark.parametrize("client_class", [ - ProductsServiceClient, ProductsServiceAsyncClient -]) -@mock.patch.object(ProductsServiceClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceClient)) -@mock.patch.object(ProductsServiceAsyncClient, "_DEFAULT_ENDPOINT_TEMPLATE", modify_default_endpoint_template(ProductsServiceAsyncClient)) +@pytest.mark.parametrize( + "client_class", [ProductsServiceClient, ProductsServiceAsyncClient] +) +@mock.patch.object( + ProductsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceClient), +) +@mock.patch.object( + ProductsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ProductsServiceAsyncClient), +) def test_products_service_client_client_api_endpoint(client_class): mock_client_cert_source = client_cert_source_callback api_override = "foo.com" default_universe = ProductsServiceClient._DEFAULT_UNIVERSE - default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=default_universe) + default_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) mock_universe = "bar.com" - mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=mock_universe) + mock_endpoint = ProductsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) # If ClientOptions.api_endpoint is set and GOOGLE_API_USE_CLIENT_CERTIFICATE="true", # use ClientOptions.api_endpoint as the api endpoint regardless. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel"): - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=api_override) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + with mock.patch( + "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" + ): + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=api_override + ) + client = client_class( + client_options=options, + credentials=ga_credentials.AnonymousCredentials(), + ) assert client.api_endpoint == api_override # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", @@ -622,11 +940,19 @@ def test_products_service_client_client_api_endpoint(client_class): universe_exists = hasattr(options, "universe_domain") if universe_exists: options = client_options.ClientOptions(universe_domain=mock_universe) - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) else: - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) - assert client.api_endpoint == (mock_endpoint if universe_exists else default_endpoint) - assert client.universe_domain == (mock_universe if universe_exists else default_universe) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + assert client.api_endpoint == ( + mock_endpoint if universe_exists else default_endpoint + ) + assert client.universe_domain == ( + mock_universe if universe_exists else default_universe + ) # If ClientOptions does not have a universe domain attribute and GOOGLE_API_USE_MTLS_ENDPOINT="never", # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. @@ -634,27 +960,40 @@ def test_products_service_client_client_api_endpoint(client_class): if hasattr(options, "universe_domain"): delattr(options, "universe_domain") with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(client_options=options, credentials=ga_credentials.AnonymousCredentials()) + client = client_class( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) assert client.api_endpoint == default_endpoint -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio"), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), -]) -def test_products_service_client_client_options_scopes(client_class, transport_class, transport_name): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc"), + ( + ProductsServiceAsyncClient, + transports.ProductsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest"), + ], +) +def test_products_service_client_client_options_scopes( + client_class, transport_class, transport_name +): # Check the case scopes are provided. options = client_options.ClientOptions( scopes=["1", "2"], ) - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=["1", "2"], client_cert_source_for_mtls=None, quota_project_id=None, @@ -663,24 +1002,40 @@ def test_products_service_client_client_options_scopes(client_class, transport_c api_audience=None, ) -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", None), -]) -def test_products_service_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductsServiceClient, + transports.ProductsServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductsServiceAsyncClient, + transports.ProductsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + (ProductsServiceClient, transports.ProductsServiceRestTransport, "rest", None), + ], +) +def test_products_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) + options = client_options.ClientOptions(credentials_file="credentials.json") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -689,11 +1044,14 @@ def test_products_service_client_client_options_credentials_file(client_class, t api_audience=None, ) + def test_products_service_client_client_options_from_dict(): - with mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceGrpcTransport.__init__') as grpc_transport: + with mock.patch( + "google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceGrpcTransport.__init__" + ) as grpc_transport: grpc_transport.return_value = None client = ProductsServiceClient( - client_options={'api_endpoint': 'squid.clam.whelk'} + client_options={"api_endpoint": "squid.clam.whelk"} ) grpc_transport.assert_called_once_with( credentials=None, @@ -708,23 +1066,38 @@ def test_products_service_client_client_options_from_dict(): ) -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport, "grpc", grpc_helpers), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_products_service_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ProductsServiceClient, + transports.ProductsServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ProductsServiceAsyncClient, + transports.ProductsServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_products_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) + options = client_options.ClientOptions(credentials_file="credentials.json") - with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None, @@ -751,9 +1124,7 @@ def test_products_service_client_create_channel_credentials_file(client_class, t credentials=file_creds, credentials_file=None, quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), scopes=None, default_host="merchantapi.googleapis.com", ssl_credentials=None, @@ -764,11 +1135,14 @@ def test_products_service_client_create_channel_credentials_file(client_class, t ) -@pytest.mark.parametrize("request_type", [ - products.GetProductRequest, - dict, -]) -def test_get_product(request_type, transport: str = 'grpc'): +@pytest.mark.parametrize( + "request_type", + [ + products.GetProductRequest, + dict, + ], +) +def test_get_product(request_type, transport: str = "grpc"): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -779,17 +1153,15 @@ def test_get_product(request_type, transport: str = 'grpc'): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = products.Product( - name='name_value', + name="name_value", legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + data_source="data_source_value", version_number=1518, ) response = client.get_product(request) @@ -802,12 +1174,12 @@ def test_get_product(request_type, transport: str = 'grpc'): # Establish that the response is the type that we expect. assert isinstance(response, products.Product) - assert response.name == 'name_value' + assert response.name == "name_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.data_source == 'data_source_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" + assert response.data_source == "data_source_value" assert response.version_number == 1518 @@ -816,28 +1188,29 @@ def test_get_product_non_empty_request_with_auto_populated_field(): # automatically populated, according to AIP-4235, with non-empty requests. client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', + transport="grpc", ) # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. request = products.GetProductRequest( - name='name_value', + name="name_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + with mock.patch.object(type(client.transport.get_product), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.get_product(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == products.GetProductRequest( - name='name_value', + name="name_value", ) + def test_get_product_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -856,7 +1229,9 @@ def test_get_product_use_cached_wrapped_rpc(): # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client._transport._wrapped_methods[client._transport.get_product] = mock_rpc request = {} client.get_product(request) @@ -870,8 +1245,11 @@ def test_get_product_use_cached_wrapped_rpc(): assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_get_product_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_get_product_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -885,12 +1263,17 @@ async def test_get_product_async_use_cached_wrapped_rpc(transport: str = "grpc_a wrapper_fn.reset_mock() # Ensure method has been cached - assert client._client._transport.get_product in client._client._transport._wrapped_methods + assert ( + client._client._transport.get_product + in client._client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.get_product] = mock_rpc + client._client._transport._wrapped_methods[ + client._client._transport.get_product + ] = mock_rpc request = {} await client.get_product(request) @@ -904,8 +1287,11 @@ async def test_get_product_async_use_cached_wrapped_rpc(transport: str = "grpc_a assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=products.GetProductRequest): +async def test_get_product_async( + transport: str = "grpc_asyncio", request_type=products.GetProductRequest +): client = ProductsServiceAsyncClient( credentials=async_anonymous_credentials(), transport=transport, @@ -916,19 +1302,19 @@ async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=p request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.Product( - name='name_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + products.Product( + name="name_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + data_source="data_source_value", + version_number=1518, + ) + ) response = await client.get_product(request) # Establish that the underlying gRPC stub method was called. @@ -939,12 +1325,12 @@ async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=p # Establish that the response is the type that we expect. assert isinstance(response, products.Product) - assert response.name == 'name_value' + assert response.name == "name_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.data_source == 'data_source_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" + assert response.data_source == "data_source_value" assert response.version_number == 1518 @@ -952,6 +1338,7 @@ async def test_get_product_async(transport: str = 'grpc_asyncio', request_type=p async def test_get_product_async_from_dict(): await test_get_product_async(request_type=dict) + def test_get_product_field_headers(): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -961,12 +1348,10 @@ def test_get_product_field_headers(): # a field header. Set these to a non-empty value. request = products.GetProductRequest() - request.name = 'name_value' + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: call.return_value = products.Product() client.get_product(request) @@ -978,9 +1363,9 @@ def test_get_product_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -993,12 +1378,10 @@ async def test_get_product_field_headers_async(): # a field header. Set these to a non-empty value. request = products.GetProductRequest() - request.name = 'name_value' + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product()) await client.get_product(request) @@ -1010,9 +1393,9 @@ async def test_get_product_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_product_flattened(): @@ -1021,15 +1404,13 @@ def test_get_product_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = products.Product() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.get_product( - name='name_value', + name="name_value", ) # Establish that the underlying call was made with the expected @@ -1037,7 +1418,7 @@ def test_get_product_flattened(): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] arg = args[0].name - mock_val = 'name_value' + mock_val = "name_value" assert arg == mock_val @@ -1051,9 +1432,10 @@ def test_get_product_flattened_error(): with pytest.raises(ValueError): client.get_product( products.GetProductRequest(), - name='name_value', + name="name_value", ) + @pytest.mark.asyncio async def test_get_product_flattened_async(): client = ProductsServiceAsyncClient( @@ -1061,9 +1443,7 @@ async def test_get_product_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = products.Product() @@ -1071,7 +1451,7 @@ async def test_get_product_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.get_product( - name='name_value', + name="name_value", ) # Establish that the underlying call was made with the expected @@ -1079,9 +1459,10 @@ async def test_get_product_flattened_async(): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] arg = args[0].name - mock_val = 'name_value' + mock_val = "name_value" assert arg == mock_val + @pytest.mark.asyncio async def test_get_product_flattened_error_async(): client = ProductsServiceAsyncClient( @@ -1093,15 +1474,18 @@ async def test_get_product_flattened_error_async(): with pytest.raises(ValueError): await client.get_product( products.GetProductRequest(), - name='name_value', + name="name_value", ) -@pytest.mark.parametrize("request_type", [ - products.ListProductsRequest, - dict, -]) -def test_list_products(request_type, transport: str = 'grpc'): +@pytest.mark.parametrize( + "request_type", + [ + products.ListProductsRequest, + dict, + ], +) +def test_list_products(request_type, transport: str = "grpc"): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1112,12 +1496,10 @@ def test_list_products(request_type, transport: str = 'grpc'): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = products.ListProductsResponse( - next_page_token='next_page_token_value', + next_page_token="next_page_token_value", ) response = client.list_products(request) @@ -1129,7 +1511,7 @@ def test_list_products(request_type, transport: str = 'grpc'): # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' + assert response.next_page_token == "next_page_token_value" def test_list_products_non_empty_request_with_auto_populated_field(): @@ -1137,30 +1519,31 @@ def test_list_products_non_empty_request_with_auto_populated_field(): # automatically populated, according to AIP-4235, with non-empty requests. client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', + transport="grpc", ) # Populate all string fields in the request which are not UUID4 # since we want to check that UUID4 are populated automatically # if they meet the requirements of AIP 4235. request = products.ListProductsRequest( - parent='parent_value', - page_token='page_token_value', + parent="parent_value", + page_token="page_token_value", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + with mock.patch.object(type(client.transport.list_products), "__call__") as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client.list_products(request=request) call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == products.ListProductsRequest( - parent='parent_value', - page_token='page_token_value', + parent="parent_value", + page_token="page_token_value", ) + def test_list_products_use_cached_wrapped_rpc(): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call @@ -1179,7 +1562,9 @@ def test_list_products_use_cached_wrapped_rpc(): # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client._transport._wrapped_methods[client._transport.list_products] = mock_rpc request = {} client.list_products(request) @@ -1193,8 +1578,11 @@ def test_list_products_use_cached_wrapped_rpc(): assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_list_products_async_use_cached_wrapped_rpc(transport: str = "grpc_asyncio"): +async def test_list_products_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, # instead of constructing them on each call with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: @@ -1208,12 +1596,17 @@ async def test_list_products_async_use_cached_wrapped_rpc(transport: str = "grpc wrapper_fn.reset_mock() # Ensure method has been cached - assert client._client._transport.list_products in client._client._transport._wrapped_methods + assert ( + client._client._transport.list_products + in client._client._transport._wrapped_methods + ) # Replace cached wrapped function with mock mock_rpc = mock.AsyncMock() mock_rpc.return_value = mock.Mock() - client._client._transport._wrapped_methods[client._client._transport.list_products] = mock_rpc + client._client._transport._wrapped_methods[ + client._client._transport.list_products + ] = mock_rpc request = {} await client.list_products(request) @@ -1227,8 +1620,11 @@ async def test_list_products_async_use_cached_wrapped_rpc(transport: str = "grpc assert wrapper_fn.call_count == 0 assert mock_rpc.call_count == 2 + @pytest.mark.asyncio -async def test_list_products_async(transport: str = 'grpc_asyncio', request_type=products.ListProductsRequest): +async def test_list_products_async( + transport: str = "grpc_asyncio", request_type=products.ListProductsRequest +): client = ProductsServiceAsyncClient( credentials=async_anonymous_credentials(), transport=transport, @@ -1239,13 +1635,13 @@ async def test_list_products_async(transport: str = 'grpc_asyncio', request_type request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( - next_page_token='next_page_token_value', - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + products.ListProductsResponse( + next_page_token="next_page_token_value", + ) + ) response = await client.list_products(request) # Establish that the underlying gRPC stub method was called. @@ -1256,13 +1652,14 @@ async def test_list_products_async(transport: str = 'grpc_asyncio', request_type # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListProductsAsyncPager) - assert response.next_page_token == 'next_page_token_value' + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio async def test_list_products_async_from_dict(): await test_list_products_async(request_type=dict) + def test_list_products_field_headers(): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1272,12 +1669,10 @@ def test_list_products_field_headers(): # a field header. Set these to a non-empty value. request = products.ListProductsRequest() - request.parent = 'parent_value' + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: call.return_value = products.ListProductsResponse() client.list_products(request) @@ -1289,9 +1684,9 @@ def test_list_products_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1304,13 +1699,13 @@ async def test_list_products_field_headers_async(): # a field header. Set these to a non-empty value. request = products.ListProductsRequest() - request.parent = 'parent_value' + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) + with mock.patch.object(type(client.transport.list_products), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + products.ListProductsResponse() + ) await client.list_products(request) # Establish that the underlying gRPC stub method was called. @@ -1321,9 +1716,9 @@ async def test_list_products_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_products_flattened(): @@ -1332,15 +1727,13 @@ def test_list_products_flattened(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = products.ListProductsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.list_products( - parent='parent_value', + parent="parent_value", ) # Establish that the underlying call was made with the expected @@ -1348,7 +1741,7 @@ def test_list_products_flattened(): assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] arg = args[0].parent - mock_val = 'parent_value' + mock_val = "parent_value" assert arg == mock_val @@ -1362,9 +1755,10 @@ def test_list_products_flattened_error(): with pytest.raises(ValueError): client.list_products( products.ListProductsRequest(), - parent='parent_value', + parent="parent_value", ) + @pytest.mark.asyncio async def test_list_products_flattened_async(): client = ProductsServiceAsyncClient( @@ -1372,17 +1766,17 @@ async def test_list_products_flattened_async(): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = products.ListProductsResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + products.ListProductsResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.list_products( - parent='parent_value', + parent="parent_value", ) # Establish that the underlying call was made with the expected @@ -1390,9 +1784,10 @@ async def test_list_products_flattened_async(): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] arg = args[0].parent - mock_val = 'parent_value' + mock_val = "parent_value" assert arg == mock_val + @pytest.mark.asyncio async def test_list_products_flattened_error_async(): client = ProductsServiceAsyncClient( @@ -1404,7 +1799,7 @@ async def test_list_products_flattened_error_async(): with pytest.raises(ValueError): await client.list_products( products.ListProductsRequest(), - parent='parent_value', + parent="parent_value", ) @@ -1415,9 +1810,7 @@ def test_list_products_pager(transport_name: str = "grpc"): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( products.ListProductsResponse( @@ -1426,17 +1819,17 @@ def test_list_products_pager(transport_name: str = "grpc"): products.Product(), products.Product(), ], - next_page_token='abc', + next_page_token="abc", ), products.ListProductsResponse( products=[], - next_page_token='def', + next_page_token="def", ), products.ListProductsResponse( products=[ products.Product(), ], - next_page_token='ghi', + next_page_token="ghi", ), products.ListProductsResponse( products=[ @@ -1451,9 +1844,7 @@ def test_list_products_pager(transport_name: str = "grpc"): retry = retries.Retry() timeout = 5 expected_metadata = tuple(expected_metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) pager = client.list_products(request={}, retry=retry, timeout=timeout) @@ -1463,8 +1854,9 @@ def test_list_products_pager(transport_name: str = "grpc"): results = list(pager) assert len(results) == 6 - assert all(isinstance(i, products.Product) - for i in results) + assert all(isinstance(i, products.Product) for i in results) + + def test_list_products_pages(transport_name: str = "grpc"): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), @@ -1472,9 +1864,7 @@ def test_list_products_pages(transport_name: str = "grpc"): ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( products.ListProductsResponse( @@ -1483,17 +1873,17 @@ def test_list_products_pages(transport_name: str = "grpc"): products.Product(), products.Product(), ], - next_page_token='abc', + next_page_token="abc", ), products.ListProductsResponse( products=[], - next_page_token='def', + next_page_token="def", ), products.ListProductsResponse( products=[ products.Product(), ], - next_page_token='ghi', + next_page_token="ghi", ), products.ListProductsResponse( products=[ @@ -1504,9 +1894,10 @@ def test_list_products_pages(transport_name: str = "grpc"): RuntimeError, ) pages = list(client.list_products(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token + @pytest.mark.asyncio async def test_list_products_async_pager(): client = ProductsServiceAsyncClient( @@ -1515,8 +1906,8 @@ async def test_list_products_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: + type(client.transport.list_products), "__call__", new_callable=mock.AsyncMock + ) as call: # Set the response to a series of pages. call.side_effect = ( products.ListProductsResponse( @@ -1525,17 +1916,17 @@ async def test_list_products_async_pager(): products.Product(), products.Product(), ], - next_page_token='abc', + next_page_token="abc", ), products.ListProductsResponse( products=[], - next_page_token='def', + next_page_token="def", ), products.ListProductsResponse( products=[ products.Product(), ], - next_page_token='ghi', + next_page_token="ghi", ), products.ListProductsResponse( products=[ @@ -1545,15 +1936,16 @@ async def test_list_products_async_pager(): ), RuntimeError, ) - async_pager = await client.list_products(request={},) - assert async_pager.next_page_token == 'abc' + async_pager = await client.list_products( + request={}, + ) + assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: # pragma: no branch + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 - assert all(isinstance(i, products.Product) - for i in responses) + assert all(isinstance(i, products.Product) for i in responses) @pytest.mark.asyncio @@ -1564,8 +1956,8 @@ async def test_list_products_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_products), - '__call__', new_callable=mock.AsyncMock) as call: + type(client.transport.list_products), "__call__", new_callable=mock.AsyncMock + ) as call: # Set the response to a series of pages. call.side_effect = ( products.ListProductsResponse( @@ -1574,17 +1966,17 @@ async def test_list_products_async_pages(): products.Product(), products.Product(), ], - next_page_token='abc', + next_page_token="abc", ), products.ListProductsResponse( products=[], - next_page_token='def', + next_page_token="def", ), products.ListProductsResponse( products=[ products.Product(), ], - next_page_token='ghi', + next_page_token="ghi", ), products.ListProductsResponse( products=[ @@ -1597,11 +1989,11 @@ async def test_list_products_async_pages(): pages = [] # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 - async for page_ in ( # pragma: no branch + async for page_ in ( # pragma: no branch await client.list_products(request={}) ).pages: pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -1623,7 +2015,9 @@ def test_get_product_rest_use_cached_wrapped_rpc(): # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client._transport._wrapped_methods[client._transport.get_product] = mock_rpc request = {} @@ -1646,48 +2040,51 @@ def test_get_product_rest_required_fields(request_type=products.GetProductReques request_init["name"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) # verify fields with default values are dropped - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_product._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["name"] = 'name_value' + jsonified_request["name"] = "name_value" - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_product._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_product._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' + assert jsonified_request["name"] == "name_value" client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='rest', + transport="rest", ) request = request_type(**request_init) # Designate an appropriate value for the returned response. return_value = products.Product() # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: + with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values # for required fields will fail the real version if the http_options # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: + with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. pb_request = request_type.pb(request) transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, } transcode.return_value = transcode_result @@ -1698,24 +2095,24 @@ def test_get_product_rest_required_fields(request_type=products.GetProductReques return_value = products.Product.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_product(request) - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params def test_get_product_rest_unset_required_fields(): - transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + transport = transports.ProductsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) unset_fields = transport.get_product._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) + assert set(unset_fields) == (set(()) & set(("name",))) def test_get_product_rest_flattened(): @@ -1725,16 +2122,16 @@ def test_get_product_rest_flattened(): ) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = products.Product() # get arguments that satisfy an http rule for this method - sample_request = {'name': 'accounts/sample1/products/sample2'} + sample_request = {"name": "accounts/sample1/products/sample2"} # get truthy value for each flattened field mock_args = dict( - name='name_value', + name="name_value", ) mock_args.update(sample_request) @@ -1744,7 +2141,7 @@ def test_get_product_rest_flattened(): # Convert return value to protobuf type return_value = products.Product.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -1754,10 +2151,13 @@ def test_get_product_rest_flattened(): # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1/{name=accounts/*/products/*}" % client.transport._host, args[1]) + assert path_template.validate( + "%s/products/v1/{name=accounts/*/products/*}" % client.transport._host, + args[1], + ) -def test_get_product_rest_flattened_error(transport: str = 'rest'): +def test_get_product_rest_flattened_error(transport: str = "rest"): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1768,7 +2168,7 @@ def test_get_product_rest_flattened_error(transport: str = 'rest'): with pytest.raises(ValueError): client.get_product( products.GetProductRequest(), - name='name_value', + name="name_value", ) @@ -1790,7 +2190,9 @@ def test_list_products_rest_use_cached_wrapped_rpc(): # Replace cached wrapped function with mock mock_rpc = mock.Mock() - mock_rpc.return_value.name = "foo" # operation_request.operation in compute client(s) expect a string. + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) client._transport._wrapped_methods[client._transport.list_products] = mock_rpc request = {} @@ -1813,50 +2215,58 @@ def test_list_products_rest_required_fields(request_type=products.ListProductsRe request_init["parent"] = "" request = request_type(**request_init) pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - use_integers_for_enums=False - )) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) # verify fields with default values are dropped - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_products._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present - jsonified_request["parent"] = 'parent_value' + jsonified_request["parent"] = "parent_value" - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_products._get_unset_required_fields(jsonified_request) + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_products._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("page_size", "page_token", )) + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' + assert jsonified_request["parent"] == "parent_value" client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport='rest', + transport="rest", ) request = request_type(**request_init) # Designate an appropriate value for the returned response. return_value = products.ListProductsResponse() # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: + with mock.patch.object(Session, "request") as req: # We need to mock transcode() because providing default values # for required fields will fail the real version if the http_options # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: + with mock.patch.object(path_template, "transcode") as transcode: # A uri without fields and an empty body will force all the # request fields to show up in the query_params. pb_request = request_type.pb(request) transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, } transcode.return_value = transcode_result @@ -1867,24 +2277,32 @@ def test_list_products_rest_required_fields(request_type=products.ListProductsRe return_value = products.ListProductsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_products(request) - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] assert expected_params == actual_params def test_list_products_rest_unset_required_fields(): - transport = transports.ProductsServiceRestTransport(credentials=ga_credentials.AnonymousCredentials) + transport = transports.ProductsServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) unset_fields = transport.list_products._get_unset_required_fields({}) - assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) def test_list_products_rest_flattened(): @@ -1894,16 +2312,16 @@ def test_list_products_rest_flattened(): ) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = products.ListProductsResponse() # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'accounts/sample1'} + sample_request = {"parent": "accounts/sample1"} # get truthy value for each flattened field mock_args = dict( - parent='parent_value', + parent="parent_value", ) mock_args.update(sample_request) @@ -1913,7 +2331,7 @@ def test_list_products_rest_flattened(): # Convert return value to protobuf type return_value = products.ListProductsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') + response_value._content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} @@ -1923,10 +2341,13 @@ def test_list_products_rest_flattened(): # request object values. assert len(req.mock_calls) == 1 _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/products/v1/{parent=accounts/*}/products" % client.transport._host, args[1]) + assert path_template.validate( + "%s/products/v1/{parent=accounts/*}/products" % client.transport._host, + args[1], + ) -def test_list_products_rest_flattened_error(transport: str = 'rest'): +def test_list_products_rest_flattened_error(transport: str = "rest"): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1937,20 +2358,20 @@ def test_list_products_rest_flattened_error(transport: str = 'rest'): with pytest.raises(ValueError): client.list_products( products.ListProductsRequest(), - parent='parent_value', + parent="parent_value", ) -def test_list_products_rest_pager(transport: str = 'rest'): +def test_list_products_rest_pager(transport: str = "rest"): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: + with mock.patch.object(Session, "request") as req: # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: + # with mock.patch.object(path_template, 'transcode') as transcode: # Set the response as a series of pages response = ( products.ListProductsResponse( @@ -1959,17 +2380,17 @@ def test_list_products_rest_pager(transport: str = 'rest'): products.Product(), products.Product(), ], - next_page_token='abc', + next_page_token="abc", ), products.ListProductsResponse( products=[], - next_page_token='def', + next_page_token="def", ), products.ListProductsResponse( products=[ products.Product(), ], - next_page_token='ghi', + next_page_token="ghi", ), products.ListProductsResponse( products=[ @@ -1985,21 +2406,20 @@ def test_list_products_rest_pager(transport: str = 'rest'): response = tuple(products.ListProductsResponse.to_json(x) for x in response) return_values = tuple(Response() for i in response) for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') + return_val._content = response_val.encode("UTF-8") return_val.status_code = 200 req.side_effect = return_values - sample_request = {'parent': 'accounts/sample1'} + sample_request = {"parent": "accounts/sample1"} pager = client.list_products(request=sample_request) results = list(pager) assert len(results) == 6 - assert all(isinstance(i, products.Product) - for i in results) + assert all(isinstance(i, products.Product) for i in results) pages = list(client.list_products(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -2041,8 +2461,7 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = ProductsServiceClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) # It is an error to provide scopes and a transport instance. @@ -2064,6 +2483,7 @@ def test_transport_instance(): client = ProductsServiceClient(transport=transport) assert client.transport is transport + def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ProductsServiceGrpcTransport( @@ -2078,18 +2498,23 @@ def test_transport_get_channel(): channel = transport.grpc_channel assert channel -@pytest.mark.parametrize("transport_class", [ - transports.ProductsServiceGrpcTransport, - transports.ProductsServiceGrpcAsyncIOTransport, - transports.ProductsServiceRestTransport, -]) + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + transports.ProductsServiceRestTransport, + ], +) def test_transport_adc(transport_class): # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() + def test_transport_kind_grpc(): transport = ProductsServiceClient.get_transport_class("grpc")( credentials=ga_credentials.AnonymousCredentials() @@ -2099,8 +2524,7 @@ def test_transport_kind_grpc(): def test_initialize_client_w_grpc(): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" + credentials=ga_credentials.AnonymousCredentials(), transport="grpc" ) assert client is not None @@ -2114,9 +2538,7 @@ def test_get_product_empty_call_grpc(): ) # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: call.return_value = products.Product() client.get_product(request=None) @@ -2137,9 +2559,7 @@ def test_list_products_empty_call_grpc(): ) # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: call.return_value = products.ListProductsResponse() client.list_products(request=None) @@ -2160,8 +2580,7 @@ def test_transport_kind_grpc_asyncio(): def test_initialize_client_w_grpc_asyncio(): client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" + credentials=async_anonymous_credentials(), transport="grpc_asyncio" ) assert client is not None @@ -2176,19 +2595,19 @@ async def test_get_product_empty_call_grpc_asyncio(): ) # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.Product( - name='name_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + products.Product( + name="name_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + data_source="data_source_value", + version_number=1518, + ) + ) await client.get_product(request=None) # Establish that the underlying stub method was called. @@ -2209,13 +2628,13 @@ async def test_list_products_empty_call_grpc_asyncio(): ) # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(products.ListProductsResponse( - next_page_token='next_page_token_value', - )) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + products.ListProductsResponse( + next_page_token="next_page_token_value", + ) + ) await client.list_products(request=None) # Establish that the underlying stub method was called. @@ -2235,18 +2654,19 @@ def test_transport_kind_rest(): def test_get_product_rest_bad_request(request_type=products.GetProductRequest): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/products/sample2'} + request_init = {"name": "accounts/sample1/products/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): # Wrap the value into a proper Response obj response_value = mock.Mock() - json_return_value = '' + json_return_value = "" response_value.json = mock.Mock(return_value={}) response_value.status_code = 400 response_value.request = mock.Mock() @@ -2255,31 +2675,33 @@ def test_get_product_rest_bad_request(request_type=products.GetProductRequest): client.get_product(request) -@pytest.mark.parametrize("request_type", [ - products.GetProductRequest, - dict, -]) +@pytest.mark.parametrize( + "request_type", + [ + products.GetProductRequest, + dict, + ], +) def test_get_product_rest_call_success(request_type): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'name': 'accounts/sample1/products/sample2'} + request_init = {"name": "accounts/sample1/products/sample2"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = products.Product( - name='name_value', - legacy_local=True, - offer_id='offer_id_value', - content_language='content_language_value', - feed_label='feed_label_value', - data_source='data_source_value', - version_number=1518, + name="name_value", + legacy_local=True, + offer_id="offer_id_value", + content_language="content_language_value", + feed_label="feed_label_value", + data_source="data_source_value", + version_number=1518, ) # Wrap the value into a proper Response obj @@ -2289,19 +2711,19 @@ def test_get_product_rest_call_success(request_type): # Convert return value to protobuf type return_value = products.Product.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') + response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.get_product(request) # Establish that the response is the type that we expect. assert isinstance(response, products.Product) - assert response.name == 'name_value' + assert response.name == "name_value" assert response.legacy_local is True - assert response.offer_id == 'offer_id_value' - assert response.content_language == 'content_language_value' - assert response.feed_label == 'feed_label_value' - assert response.data_source == 'data_source_value' + assert response.offer_id == "offer_id_value" + assert response.content_language == "content_language_value" + assert response.feed_label == "feed_label_value" + assert response.data_source == "data_source_value" assert response.version_number == 1518 @@ -2309,15 +2731,23 @@ def test_get_product_rest_call_success(request_type): def test_get_product_rest_interceptors(null_interceptor): transport = transports.ProductsServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), - ) + interceptor=None + if null_interceptor + else transports.ProductsServiceRestInterceptor(), + ) client = ProductsServiceClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product") as post, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_get_product_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_get_product") as pre: + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.ProductsServiceRestInterceptor, "post_get_product" + ) as post, mock.patch.object( + transports.ProductsServiceRestInterceptor, "post_get_product_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.ProductsServiceRestInterceptor, "pre_get_product" + ) as pre: pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2336,7 +2766,7 @@ def test_get_product_rest_interceptors(null_interceptor): req.return_value.content = return_value request = products.GetProductRequest() - metadata =[ + metadata = [ ("key", "val"), ("cephalopod", "squid"), ] @@ -2344,7 +2774,13 @@ def test_get_product_rest_interceptors(null_interceptor): post.return_value = products.Product() post_with_metadata.return_value = products.Product(), metadata - client.get_product(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + client.get_product( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) pre.assert_called_once() post.assert_called_once() @@ -2353,18 +2789,19 @@ def test_get_product_rest_interceptors(null_interceptor): def test_list_products_rest_bad_request(request_type=products.ListProductsRequest): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} + request_init = {"parent": "accounts/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): # Wrap the value into a proper Response obj response_value = mock.Mock() - json_return_value = '' + json_return_value = "" response_value.json = mock.Mock(return_value={}) response_value.status_code = 400 response_value.request = mock.Mock() @@ -2373,25 +2810,27 @@ def test_list_products_rest_bad_request(request_type=products.ListProductsReques client.list_products(request) -@pytest.mark.parametrize("request_type", [ - products.ListProductsRequest, - dict, -]) +@pytest.mark.parametrize( + "request_type", + [ + products.ListProductsRequest, + dict, + ], +) def test_list_products_rest_call_success(request_type): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) # send a request that will satisfy transcoding - request_init = {'parent': 'accounts/sample1'} + request_init = {"parent": "accounts/sample1"} request = request_type(**request_init) # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: + with mock.patch.object(type(client.transport._session), "request") as req: # Designate an appropriate value for the returned response. return_value = products.ListProductsResponse( - next_page_token='next_page_token_value', + next_page_token="next_page_token_value", ) # Wrap the value into a proper Response obj @@ -2401,29 +2840,37 @@ def test_list_products_rest_call_success(request_type): # Convert return value to protobuf type return_value = products.ListProductsResponse.pb(return_value) json_return_value = json_format.MessageToJson(return_value) - response_value.content = json_return_value.encode('UTF-8') + response_value.content = json_return_value.encode("UTF-8") req.return_value = response_value req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} response = client.list_products(request) # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListProductsPager) - assert response.next_page_token == 'next_page_token_value' + assert response.next_page_token == "next_page_token_value" @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_products_rest_interceptors(null_interceptor): transport = transports.ProductsServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.ProductsServiceRestInterceptor(), - ) + interceptor=None + if null_interceptor + else transports.ProductsServiceRestInterceptor(), + ) client = ProductsServiceClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products") as post, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "post_list_products_with_metadata") as post_with_metadata, \ - mock.patch.object(transports.ProductsServiceRestInterceptor, "pre_list_products") as pre: + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.ProductsServiceRestInterceptor, "post_list_products" + ) as post, mock.patch.object( + transports.ProductsServiceRestInterceptor, "post_list_products_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.ProductsServiceRestInterceptor, "pre_list_products" + ) as pre: pre.assert_not_called() post.assert_not_called() post_with_metadata.assert_not_called() @@ -2438,11 +2885,13 @@ def test_list_products_rest_interceptors(null_interceptor): req.return_value = mock.Mock() req.return_value.status_code = 200 req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} - return_value = products.ListProductsResponse.to_json(products.ListProductsResponse()) + return_value = products.ListProductsResponse.to_json( + products.ListProductsResponse() + ) req.return_value.content = return_value request = products.ListProductsRequest() - metadata =[ + metadata = [ ("key", "val"), ("cephalopod", "squid"), ] @@ -2450,16 +2899,22 @@ def test_list_products_rest_interceptors(null_interceptor): post.return_value = products.ListProductsResponse() post_with_metadata.return_value = products.ListProductsResponse(), metadata - client.list_products(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + client.list_products( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) pre.assert_called_once() post.assert_called_once() post_with_metadata.assert_called_once() + def test_initialize_client_w_rest(): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) assert client is not None @@ -2473,9 +2928,7 @@ def test_get_product_empty_call_rest(): ) # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_product), - '__call__') as call: + with mock.patch.object(type(client.transport.get_product), "__call__") as call: client.get_product(request=None) # Establish that the underlying stub method was called. @@ -2495,9 +2948,7 @@ def test_list_products_empty_call_rest(): ) # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_products), - '__call__') as call: + with mock.patch.object(type(client.transport.list_products), "__call__") as call: client.list_products(request=None) # Establish that the underlying stub method was called. @@ -2518,18 +2969,21 @@ def test_transport_grpc_default(): transports.ProductsServiceGrpcTransport, ) + def test_products_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ProductsServiceTransport( credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" + credentials_file="credentials.json", ) def test_products_service_base_transport(): # Instantiate the base transport. - with mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport.__init__') as Transport: + with mock.patch( + "google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport.__init__" + ) as Transport: Transport.return_value = None transport = transports.ProductsServiceTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2538,8 +2992,8 @@ def test_products_service_base_transport(): # Every method on the transport should just blindly # raise NotImplementedError. methods = ( - 'get_product', - 'list_products', + "get_product", + "list_products", ) for method in methods: with pytest.raises(NotImplementedError): @@ -2550,7 +3004,7 @@ def test_products_service_base_transport(): # Catch all for all remaining methods and properties remainder = [ - 'kind', + "kind", ] for r in remainder: with pytest.raises(NotImplementedError): @@ -2559,25 +3013,30 @@ def test_products_service_base_transport(): def test_products_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages" + ) as Transport: Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", ) - load_creds.assert_called_once_with("credentials.json", + load_creds.assert_called_once_with( + "credentials.json", scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), quota_project_id="octopus", ) def test_products_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages') as Transport: + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.shopping.merchant_products_v1.services.products_service.transports.ProductsServiceTransport._prep_wrapped_messages" + ) as Transport: Transport.return_value = None adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.ProductsServiceTransport() @@ -2586,14 +3045,12 @@ def test_products_service_base_transport_with_adc(): def test_products_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: + with mock.patch.object(google.auth, "default", autospec=True) as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) ProductsServiceClient() adc.assert_called_once_with( scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), quota_project_id=None, ) @@ -2608,12 +3065,12 @@ def test_products_service_auth_adc(): def test_products_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: + with mock.patch.object(google.auth, "default", autospec=True) as adc: adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/content',), + default_scopes=("https://www.googleapis.com/auth/content",), quota_project_id="octopus", ) @@ -2627,48 +3084,45 @@ def test_products_service_transport_auth_adc(transport_class): ], ) def test_products_service_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] + host = "https://language.com" + api_audience_tests = [None, "https://language2.com"] + api_audience_expect = [host, "https://language2.com"] for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: + with mock.patch.object(google.auth, "default", autospec=True) as adc: gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + type(gdch_mock).with_gdch_audience = mock.PropertyMock( + return_value=gdch_mock + ) adc.return_value = (gdch_mock, None) transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) + gdch_mock.with_gdch_audience.assert_called_once_with(e) @pytest.mark.parametrize( "transport_class,grpc_helpers", [ (transports.ProductsServiceGrpcTransport, grpc_helpers), - (transports.ProductsServiceGrpcAsyncIOTransport, grpc_helpers_async) + (transports.ProductsServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) def test_products_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( "merchantapi.googleapis.com:443", credentials=creds, credentials_file=None, quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/content', -), + default_scopes=("https://www.googleapis.com/auth/content",), scopes=["1", "2"], default_host="merchantapi.googleapis.com", ssl_credentials=None, @@ -2679,10 +3133,14 @@ def test_products_service_transport_create_channel(transport_class, grpc_helpers ) -@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) -def test_products_service_grpc_transport_client_cert_source_for_mtls( - transport_class -): +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + ], +) +def test_products_service_grpc_transport_client_cert_source_for_mtls(transport_class): cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. @@ -2691,7 +3149,7 @@ def test_products_service_grpc_transport_client_cert_source_for_mtls( transport_class( host="squid.clam.whelk", credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds + ssl_channel_credentials=mock_ssl_channel_creds, ) mock_create_channel.assert_called_once_with( "squid.clam.whelk:443", @@ -2712,61 +3170,77 @@ def test_products_service_grpc_transport_client_cert_source_for_mtls( with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: transport_class( credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback + client_cert_source_for_mtls=client_cert_source_callback, ) expected_cert, expected_key = client_cert_source_callback() mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key + certificate_chain=expected_cert, private_key=expected_key ) + def test_products_service_http_transport_client_cert_source_for_mtls(): cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.ProductsServiceRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback + with mock.patch( + "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" + ) as mock_configure_mtls_channel: + transports.ProductsServiceRestTransport( + credentials=cred, client_cert_source_for_mtls=client_cert_source_callback ) mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + "rest", + ], +) def test_products_service_host_no_port(transport_name): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com'), - transport=transport_name, + client_options=client_options.ClientOptions( + api_endpoint="merchantapi.googleapis.com" + ), + transport=transport_name, ) assert client.transport._host == ( - 'merchantapi.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com' + "merchantapi.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com" ) -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + "rest", + ], +) def test_products_service_host_with_port(transport_name): client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='merchantapi.googleapis.com:8000'), + client_options=client_options.ClientOptions( + api_endpoint="merchantapi.googleapis.com:8000" + ), transport=transport_name, ) assert client.transport._host == ( - 'merchantapi.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://merchantapi.googleapis.com:8000' + "merchantapi.googleapis.com:8000" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://merchantapi.googleapis.com:8000" ) -@pytest.mark.parametrize("transport_name", [ - "rest", -]) + +@pytest.mark.parametrize( + "transport_name", + [ + "rest", + ], +) def test_products_service_client_transport_session_collision(transport_name): creds1 = ga_credentials.AnonymousCredentials() creds2 = ga_credentials.AnonymousCredentials() @@ -2784,8 +3258,10 @@ def test_products_service_client_transport_session_collision(transport_name): session1 = client1.transport.list_products._session session2 = client2.transport.list_products._session assert session1 != session2 + + def test_products_service_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductsServiceGrpcTransport( @@ -2798,7 +3274,7 @@ def test_products_service_grpc_transport_channel(): def test_products_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.ProductsServiceGrpcAsyncIOTransport( @@ -2812,12 +3288,22 @@ def test_products_service_grpc_asyncio_transport_channel(): # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are # removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + ], +) def test_products_service_transport_channel_mtls_with_client_cert_source( - transport_class + transport_class, ): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -2826,7 +3312,7 @@ def test_products_service_transport_channel_mtls_with_client_cert_source( cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: + with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) transport = transport_class( host="squid.clam.whelk", @@ -2856,17 +3342,23 @@ def test_products_service_transport_channel_mtls_with_client_cert_source( # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are # removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.ProductsServiceGrpcTransport, transports.ProductsServiceGrpcAsyncIOTransport]) -def test_products_service_transport_channel_mtls_with_adc( - transport_class -): +@pytest.mark.parametrize( + "transport_class", + [ + transports.ProductsServiceGrpcTransport, + transports.ProductsServiceGrpcAsyncIOTransport, + ], +) +def test_products_service_transport_channel_mtls_with_adc(transport_class): mock_ssl_cred = mock.Mock() with mock.patch.multiple( "google.auth.transport.grpc.SslCredentials", __init__=mock.Mock(return_value=None), ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel mock_cred = mock.Mock() @@ -2897,7 +3389,10 @@ def test_products_service_transport_channel_mtls_with_adc( def test_product_path(): account = "squid" product = "clam" - expected = "accounts/{account}/products/{product}".format(account=account, product=product, ) + expected = "accounts/{account}/products/{product}".format( + account=account, + product=product, + ) actual = ProductsServiceClient.product_path(account, product) assert expected == actual @@ -2913,9 +3408,12 @@ def test_parse_product_path(): actual = ProductsServiceClient.parse_product_path(path) assert expected == actual + def test_common_billing_account_path(): billing_account = "oyster" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) actual = ProductsServiceClient.common_billing_account_path(billing_account) assert expected == actual @@ -2930,9 +3428,12 @@ def test_parse_common_billing_account_path(): actual = ProductsServiceClient.parse_common_billing_account_path(path) assert expected == actual + def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder, ) + expected = "folders/{folder}".format( + folder=folder, + ) actual = ProductsServiceClient.common_folder_path(folder) assert expected == actual @@ -2947,9 +3448,12 @@ def test_parse_common_folder_path(): actual = ProductsServiceClient.parse_common_folder_path(path) assert expected == actual + def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization, ) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = ProductsServiceClient.common_organization_path(organization) assert expected == actual @@ -2964,9 +3468,12 @@ def test_parse_common_organization_path(): actual = ProductsServiceClient.parse_common_organization_path(path) assert expected == actual + def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project, ) + expected = "projects/{project}".format( + project=project, + ) actual = ProductsServiceClient.common_project_path(project) assert expected == actual @@ -2981,10 +3488,14 @@ def test_parse_common_project_path(): actual = ProductsServiceClient.parse_common_project_path(path) assert expected == actual + def test_common_location_path(): project = "squid" location = "clam" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) actual = ProductsServiceClient.common_location_path(project, location) assert expected == actual @@ -3004,14 +3515,18 @@ def test_parse_common_location_path(): def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: + with mock.patch.object( + transports.ProductsServiceTransport, "_prep_wrapped_messages" + ) as prep: client = ProductsServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) - with mock.patch.object(transports.ProductsServiceTransport, '_prep_wrapped_messages') as prep: + with mock.patch.object( + transports.ProductsServiceTransport, "_prep_wrapped_messages" + ) as prep: transport_class = ProductsServiceClient.get_transport_class() transport = transport_class( credentials=ga_credentials.AnonymousCredentials(), @@ -3022,10 +3537,11 @@ def test_client_with_default_client_info(): def test_transport_close_grpc(): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc" + credentials=ga_credentials.AnonymousCredentials(), transport="grpc" ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with mock.patch.object( + type(getattr(client.transport, "_grpc_channel")), "close" + ) as close: with client: close.assert_not_called() close.assert_called_once() @@ -3034,10 +3550,11 @@ def test_transport_close_grpc(): @pytest.mark.asyncio async def test_transport_close_grpc_asyncio(): client = ProductsServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio" + credentials=async_anonymous_credentials(), transport="grpc_asyncio" ) - with mock.patch.object(type(getattr(client.transport, "_grpc_channel")), "close") as close: + with mock.patch.object( + type(getattr(client.transport, "_grpc_channel")), "close" + ) as close: async with client: close.assert_not_called() close.assert_called_once() @@ -3045,10 +3562,11 @@ async def test_transport_close_grpc_asyncio(): def test_transport_close_rest(): client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest" + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - with mock.patch.object(type(getattr(client.transport, "_session")), "close") as close: + with mock.patch.object( + type(getattr(client.transport, "_session")), "close" + ) as close: with client: close.assert_not_called() close.assert_called_once() @@ -3056,13 +3574,12 @@ def test_transport_close_rest(): def test_client_ctx(): transports = [ - 'rest', - 'grpc', + "rest", + "grpc", ] for transport in transports: client = ProductsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3071,10 +3588,14 @@ def test_client_ctx(): pass close.assert_called() -@pytest.mark.parametrize("client_class,transport_class", [ - (ProductsServiceClient, transports.ProductsServiceGrpcTransport), - (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport), -]) + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ProductsServiceClient, transports.ProductsServiceGrpcTransport), + (ProductsServiceAsyncClient, transports.ProductsServiceGrpcAsyncIOTransport), + ], +) def test_api_key_credentials(client_class, transport_class): with mock.patch.object( google.auth._default, "get_api_key_credentials", create=True @@ -3089,7 +3610,9 @@ def test_api_key_credentials(client_class, transport_class): patched.assert_called_once_with( credentials=mock_cred, credentials_file=None, - host=client._DEFAULT_ENDPOINT_TEMPLATE.format(UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE), + host=client._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=client._DEFAULT_UNIVERSE + ), scopes=None, client_cert_source_for_mtls=None, quota_project_id=None,