Skip to content

Commit

Permalink
feat: add from_service_account_info factory and fix sphinx identifiers (
Browse files Browse the repository at this point in the history
#74)

feat: add 'from_service_account_info' factory to clients
fix: fix sphinx identifiers
PiperOrigin-RevId: 350246057

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Jan 5 16:44:11 2021 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 520682435235d9c503983a360a2090025aa47cd1
Source-Link: googleapis/googleapis@5206824
  • Loading branch information
yoshi-automation authored Jan 6, 2021
1 parent 2f4f05e commit 9011a4f
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 303 deletions.
5 changes: 3 additions & 2 deletions packages/google-cloud-containeranalysis/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ branch = True
[report]
fail_under = 100
show_missing = True
omit = google/cloud/devtools/containeranalysis/__init__.py
omit =
google/cloud/devtools/containeranalysis/__init__.py
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
Expand All @@ -14,4 +15,4 @@ exclude_lines =
# This is added at the module level as a safeguard for if someone
# generates the code and tries to run it without pip installing. This
# makes it virtually impossible to test properly.
except pkg_resources.DistributionNotFound
except pkg_resources.DistributionNotFound
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ContainerAnalysis
-----------------------------------

.. automodule:: google.cloud.devtools.containeranalysis_v1.services.container_analysis
:members:
:inherited-members:
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Services for Google Cloud Devtools Containeranalysis v1 API
===========================================================
.. toctree::
:maxdepth: 2

.. automodule:: google.cloud.devtools.containeranalysis_v1.services.container_analysis
:members:
:inherited-members:
container_analysis
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Types for Google Cloud Devtools Containeranalysis v1 API

.. automodule:: google.cloud.devtools.containeranalysis_v1.types
:members:
:undoc-members:
:show-inheritance:

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class VulnerabilityOccurrencesSummary(proto.Message):
resource and severity type.
Attributes:
counts (Sequence[~.containeranalysis.VulnerabilityOccurrencesSummary.FixableTotalByDigest]):
counts (Sequence[google.cloud.devtools.containeranalysis_v1.types.VulnerabilityOccurrencesSummary.FixableTotalByDigest]):
A listing by resource of the number of
fixable and total vulnerabilities.
"""
Expand All @@ -64,7 +64,7 @@ class FixableTotalByDigest(proto.Message):
Attributes:
resource_uri (str):
The affected resource.
severity (~.vulnerability.Severity):
severity (grafeas.v1.vulnerability_pb2.Severity):
The severity for this count. SEVERITY_UNSPECIFIED indicates
total across all severities.
fixable_count (int):
Expand Down
8 changes: 5 additions & 3 deletions packages/google-cloud-containeranalysis/synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/python-containeranalysis.git",
"sha": "c7bbfa1b67df35cae8adb45f8b34aae3a45c6e3d"
"sha": "56c8dafd3995079015f86119ae2d48bd50124ef3"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907",
"internalRef": "347055288"
"sha": "520682435235d9c503983a360a2090025aa47cd1",
"internalRef": "350246057"
}
},
{
Expand Down Expand Up @@ -42,6 +42,7 @@
}
],
"generatedFiles": [
".coveragerc",
".flake8",
".github/CONTRIBUTING.md",
".github/ISSUE_TEMPLATE/bug_report.md",
Expand Down Expand Up @@ -94,6 +95,7 @@
"docs/_static/custom.css",
"docs/_templates/layout.html",
"docs/conf.py",
"docs/containeranalysis_v1/container_analysis.rst",
"docs/containeranalysis_v1/services.rst",
"docs/containeranalysis_v1/types.rst",
"docs/multiprocessing.rst",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,21 @@ def test__get_default_mtls_endpoint():
)


def test_container_analysis_client_from_service_account_info():
creds = credentials.AnonymousCredentials()
with mock.patch.object(
service_account.Credentials, "from_service_account_info"
) as factory:
factory.return_value = creds
info = {"valid": True}
client = ContainerAnalysisClient.from_service_account_info(info)
assert client.transport._credentials == creds

assert client.transport._host == "containeranalysis.googleapis.com:443"


@pytest.mark.parametrize(
"client_class", [ContainerAnalysisClient, ContainerAnalysisAsyncClient]
"client_class", [ContainerAnalysisClient, ContainerAnalysisAsyncClient,]
)
def test_container_analysis_client_from_service_account_file(client_class):
creds = credentials.AnonymousCredentials()
Expand All @@ -114,7 +127,10 @@ def test_container_analysis_client_from_service_account_file(client_class):

def test_container_analysis_client_get_transport_class():
transport = ContainerAnalysisClient.get_transport_class()
assert transport == transports.ContainerAnalysisGrpcTransport
available_transports = [
transports.ContainerAnalysisGrpcTransport,
]
assert transport in available_transports

transport = ContainerAnalysisClient.get_transport_class("grpc")
assert transport == transports.ContainerAnalysisGrpcTransport
Expand Down Expand Up @@ -1526,7 +1542,7 @@ def test_container_analysis_host_with_port():


def test_container_analysis_grpc_transport_channel():
channel = grpc.insecure_channel("http://localhost/")
channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials())

# Check that channel is used if provided.
transport = transports.ContainerAnalysisGrpcTransport(
Expand All @@ -1538,7 +1554,7 @@ def test_container_analysis_grpc_transport_channel():


def test_container_analysis_grpc_asyncio_transport_channel():
channel = aio.insecure_channel("http://localhost/")
channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials())

# Check that channel is used if provided.
transport = transports.ContainerAnalysisGrpcAsyncIOTransport(
Expand All @@ -1563,7 +1579,7 @@ def test_container_analysis_transport_channel_mtls_with_client_cert_source(
"grpc.ssl_channel_credentials", autospec=True
) as grpc_ssl_channel_cred:
with mock.patch.object(
transport_class, "create_channel", autospec=True
transport_class, "create_channel"
) as grpc_create_channel:
mock_ssl_cred = mock.Mock()
grpc_ssl_channel_cred.return_value = mock_ssl_cred
Expand Down Expand Up @@ -1616,7 +1632,7 @@ def test_container_analysis_transport_channel_mtls_with_adc(transport_class):
ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred),
):
with mock.patch.object(
transport_class, "create_channel", autospec=True
transport_class, "create_channel"
) as grpc_create_channel:
mock_grpc_channel = mock.Mock()
grpc_create_channel.return_value = mock_grpc_channel
Expand Down

0 comments on commit 9011a4f

Please sign in to comment.