diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 70dcbbb..108063d 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:3f66ebf145a16bb07a2fcbdb79bcb5743a791e3dc46015b0de22cacdd2875f64 + digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 74028a9..568aca8 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -30,6 +30,7 @@ env_vars: { env_vars: { key: "V2_STAGING_BUCKET" + # Push google cloud library docs to the Cloud RAD bucket `docs-staging-v2` value: "docs-staging-v2" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 05569cd..4bd4972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +### [0.5.1](https://www.github.com/googleapis/python-data-qna/compare/v0.5.0...v0.5.1) (2021-11-01) + + +### Bug Fixes + +* **deps:** drop packaging dependency ([2cce50d](https://www.github.com/googleapis/python-data-qna/commit/2cce50dd31ed071a2a1ebaf14ae350238f60539e)) +* **deps:** require google-api-core >= 1.28.0 ([2cce50d](https://www.github.com/googleapis/python-data-qna/commit/2cce50dd31ed071a2a1ebaf14ae350238f60539e)) + + +### Documentation + +* list oneofs in docstring ([2cce50d](https://www.github.com/googleapis/python-data-qna/commit/2cce50dd31ed071a2a1ebaf14ae350238f60539e)) + ## [0.5.0](https://www.github.com/googleapis/python-data-qna/compare/v0.4.0...v0.5.0) (2021-10-21) diff --git a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py index 6a2e000..0da23ed 100644 --- a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py +++ b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.dataqna_v1alpha.types import auto_suggestion_service from .transports.base import AutoSuggestionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import AutoSuggestionServiceGrpcAsyncIOTransport @@ -234,9 +236,9 @@ def __init__( async def suggest_queries( self, - request: auto_suggestion_service.SuggestQueriesRequest = None, + request: Union[auto_suggestion_service.SuggestQueriesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> auto_suggestion_service.SuggestQueriesResponse: @@ -244,7 +246,7 @@ async def suggest_queries( AutoSuggestion tolerance should be less than 1 second. Args: - request (:class:`google.cloud.dataqna_v1alpha.types.SuggestQueriesRequest`): + request (Union[google.cloud.dataqna_v1alpha.types.SuggestQueriesRequest, dict]): The request object. Request for query suggestions. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. diff --git a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py index a6cb48d..98c7d97 100644 --- a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py +++ b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.dataqna_v1alpha.types import auto_suggestion_service from .transports.base import AutoSuggestionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import AutoSuggestionServiceGrpcTransport @@ -407,7 +409,7 @@ def suggest_queries( self, request: Union[auto_suggestion_service.SuggestQueriesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> auto_suggestion_service.SuggestQueriesResponse: diff --git a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py index 8e02396..6d3c6e8 100644 --- a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py +++ b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -35,15 +34,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class AutoSuggestionServiceTransport(abc.ABC): """Abstract transport class for AutoSuggestionService.""" @@ -93,7 +83,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -126,29 +116,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py index 21af0d4..f68df58 100644 --- a/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py +++ b/google/cloud/dataqna_v1alpha/services/auto_suggestion_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/cloud/dataqna_v1alpha/services/question_service/async_client.py b/google/cloud/dataqna_v1alpha/services/question_service/async_client.py index 0c6dac7..0125d0e 100644 --- a/google/cloud/dataqna_v1alpha/services/question_service/async_client.py +++ b/google/cloud/dataqna_v1alpha/services/question_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.dataqna_v1alpha.types import question from google.cloud.dataqna_v1alpha.types import question as gcd_question from google.cloud.dataqna_v1alpha.types import question_service @@ -190,17 +192,17 @@ def __init__( async def get_question( self, - request: question_service.GetQuestionRequest = None, + request: Union[question_service.GetQuestionRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> question.Question: r"""Gets a previously created question. Args: - request (:class:`google.cloud.dataqna_v1alpha.types.GetQuestionRequest`): + request (Union[google.cloud.dataqna_v1alpha.types.GetQuestionRequest, dict]): The request object. A request to get a previously created question. name (:class:`str`): @@ -264,18 +266,18 @@ async def get_question( async def create_question( self, - request: question_service.CreateQuestionRequest = None, + request: Union[question_service.CreateQuestionRequest, dict] = None, *, parent: str = None, question: gcd_question.Question = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_question.Question: r"""Creates a question. Args: - request (:class:`google.cloud.dataqna_v1alpha.types.CreateQuestionRequest`): + request (Union[google.cloud.dataqna_v1alpha.types.CreateQuestionRequest, dict]): The request object. Request to create a question resource. parent (:class:`str`): @@ -347,18 +349,18 @@ async def create_question( async def execute_question( self, - request: question_service.ExecuteQuestionRequest = None, + request: Union[question_service.ExecuteQuestionRequest, dict] = None, *, name: str = None, interpretation_index: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> question.Question: r"""Executes an interpretation. Args: - request (:class:`google.cloud.dataqna_v1alpha.types.ExecuteQuestionRequest`): + request (Union[google.cloud.dataqna_v1alpha.types.ExecuteQuestionRequest, dict]): The request object. Request to execute an interpretation. name (:class:`str`): @@ -431,17 +433,17 @@ async def execute_question( async def get_user_feedback( self, - request: question_service.GetUserFeedbackRequest = None, + request: Union[question_service.GetUserFeedbackRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> user_feedback.UserFeedback: r"""Gets previously created user feedback. Args: - request (:class:`google.cloud.dataqna_v1alpha.types.GetUserFeedbackRequest`): + request (Union[google.cloud.dataqna_v1alpha.types.GetUserFeedbackRequest, dict]): The request object. Request to get user feedback. name (:class:`str`): Required. The unique identifier for the user feedback. @@ -501,11 +503,11 @@ async def get_user_feedback( async def update_user_feedback( self, - request: question_service.UpdateUserFeedbackRequest = None, + request: Union[question_service.UpdateUserFeedbackRequest, dict] = None, *, user_feedback: gcd_user_feedback.UserFeedback = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_user_feedback.UserFeedback: @@ -513,7 +515,7 @@ async def update_user_feedback( there was none before (upsert). Args: - request (:class:`google.cloud.dataqna_v1alpha.types.UpdateUserFeedbackRequest`): + request (Union[google.cloud.dataqna_v1alpha.types.UpdateUserFeedbackRequest, dict]): The request object. Request to updates user feedback. user_feedback (:class:`google.cloud.dataqna_v1alpha.types.UserFeedback`): Required. The user feedback to diff --git a/google/cloud/dataqna_v1alpha/services/question_service/client.py b/google/cloud/dataqna_v1alpha/services/question_service/client.py index b5cd307..d32daf6 100644 --- a/google/cloud/dataqna_v1alpha/services/question_service/client.py +++ b/google/cloud/dataqna_v1alpha/services/question_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.dataqna_v1alpha.types import question from google.cloud.dataqna_v1alpha.types import question as gcd_question from google.cloud.dataqna_v1alpha.types import question_service @@ -391,7 +393,7 @@ def get_question( request: Union[question_service.GetQuestionRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> question.Question: @@ -466,7 +468,7 @@ def create_question( *, parent: str = None, question: gcd_question.Question = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_question.Question: @@ -549,7 +551,7 @@ def execute_question( *, name: str = None, interpretation_index: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> question.Question: @@ -632,7 +634,7 @@ def get_user_feedback( request: Union[question_service.GetUserFeedbackRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> user_feedback.UserFeedback: @@ -703,7 +705,7 @@ def update_user_feedback( *, user_feedback: gcd_user_feedback.UserFeedback = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gcd_user_feedback.UserFeedback: diff --git a/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py b/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py index 493845b..8a55b03 100644 --- a/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py +++ b/google/cloud/dataqna_v1alpha/services/question_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -39,15 +38,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class QuestionServiceTransport(abc.ABC): """Abstract transport class for QuestionService.""" @@ -97,7 +87,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -130,29 +120,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py b/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py index 57f171d..a8dbe35 100644 --- a/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py +++ b/google/cloud/dataqna_v1alpha/services/question_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/noxfile.py b/noxfile.py index 2bb4cf7..2a2001c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -101,7 +101,7 @@ def default(session): "py.test", "--quiet", f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google/cloud", + "--cov=google", "--cov=tests/unit", "--cov-append", "--cov-config=.coveragerc", diff --git a/setup.py b/setup.py index f936a31..8e54bb4 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "0.5.0" +version = "0.5.1" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -48,9 +48,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.10.0", - "packaging >= 14.3", ), python_requires=">=3.6", classifiers=[ diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 3ac91c6..da8c573 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,9 +5,5 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.10.0 -packaging==14.3 -# TODO: remove once google-auth>=1.25.0 is required transitively -# through google-api-core>=1.28.0 -google-auth==1.24.0 diff --git a/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py b/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py index 8782bb9..54d2775 100644 --- a/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py +++ b/tests/unit/gapic/dataqna_v1alpha/test_auto_suggestion_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,28 +38,11 @@ AutoSuggestionServiceClient, ) from google.cloud.dataqna_v1alpha.services.auto_suggestion_service import transports -from google.cloud.dataqna_v1alpha.services.auto_suggestion_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dataqna_v1alpha.types import auto_suggestion_service from google.oauth2 import service_account import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -222,7 +204,7 @@ def test_auto_suggestion_service_client_client_options( 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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -239,7 +221,7 @@ def test_auto_suggestion_service_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -256,7 +238,7 @@ def test_auto_suggestion_service_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -285,7 +267,7 @@ def test_auto_suggestion_service_client_client_options( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -354,7 +336,7 @@ def test_auto_suggestion_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -396,7 +378,7 @@ def test_auto_suggestion_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,7 +400,7 @@ def test_auto_suggestion_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -453,7 +435,7 @@ def test_auto_suggestion_service_client_client_options_scopes( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -488,7 +470,7 @@ def test_auto_suggestion_service_client_client_options_credentials_file( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -763,7 +745,6 @@ def test_auto_suggestion_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_auto_suggestion_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -784,26 +765,6 @@ def test_auto_suggestion_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_auto_suggestion_service_base_transport_with_credentials_file_old_google_auth(): - # 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.cloud.dataqna_v1alpha.services.auto_suggestion_service.transports.AutoSuggestionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.AutoSuggestionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_auto_suggestion_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( @@ -815,7 +776,6 @@ def test_auto_suggestion_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_auto_suggestion_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -828,18 +788,6 @@ def test_auto_suggestion_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_auto_suggestion_service_auth_adc_old_google_auth(): - # 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) - AutoSuggestionServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -847,7 +795,6 @@ def test_auto_suggestion_service_auth_adc_old_google_auth(): transports.AutoSuggestionServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_auto_suggestion_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -861,26 +808,6 @@ def test_auto_suggestion_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.AutoSuggestionServiceGrpcTransport, - transports.AutoSuggestionServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_auto_suggestion_service_transport_auth_adc_old_google_auth(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") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/dataqna_v1alpha/test_question_service.py b/tests/unit/gapic/dataqna_v1alpha/test_question_service.py index 7c8bd67..227d224 100644 --- a/tests/unit/gapic/dataqna_v1alpha/test_question_service.py +++ b/tests/unit/gapic/dataqna_v1alpha/test_question_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -37,9 +36,6 @@ ) from google.cloud.dataqna_v1alpha.services.question_service import QuestionServiceClient from google.cloud.dataqna_v1alpha.services.question_service import transports -from google.cloud.dataqna_v1alpha.services.question_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.dataqna_v1alpha.types import annotated_string from google.cloud.dataqna_v1alpha.types import question from google.cloud.dataqna_v1alpha.types import question as gcd_question @@ -54,20 +50,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -224,7 +206,7 @@ def test_question_service_client_client_options( 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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -241,7 +223,7 @@ def test_question_service_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -258,7 +240,7 @@ def test_question_service_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -287,7 +269,7 @@ def test_question_service_client_client_options( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -356,7 +338,7 @@ def test_question_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -398,7 +380,7 @@ def test_question_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -420,7 +402,7 @@ def test_question_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -451,7 +433,7 @@ def test_question_service_client_client_options_scopes( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -482,7 +464,7 @@ def test_question_service_client_client_options_credentials_file( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1785,7 +1767,6 @@ def test_question_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_question_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1806,26 +1787,6 @@ def test_question_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_question_service_base_transport_with_credentials_file_old_google_auth(): - # 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.cloud.dataqna_v1alpha.services.question_service.transports.QuestionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.QuestionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_question_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( @@ -1837,7 +1798,6 @@ def test_question_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_question_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1850,18 +1810,6 @@ def test_question_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_question_service_auth_adc_old_google_auth(): - # 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) - QuestionServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1869,7 +1817,6 @@ def test_question_service_auth_adc_old_google_auth(): transports.QuestionServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_question_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1883,26 +1830,6 @@ def test_question_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.QuestionServiceGrpcTransport, - transports.QuestionServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_question_service_transport_auth_adc_old_google_auth(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") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [