diff --git a/docs/securitycenter_v1/types.rst b/docs/securitycenter_v1/types.rst index 14eaa881..f7497757 100644 --- a/docs/securitycenter_v1/types.rst +++ b/docs/securitycenter_v1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Securitycenter v1 API .. automodule:: google.cloud.securitycenter_v1.types :members: + :show-inheritance: diff --git a/docs/securitycenter_v1beta1/types.rst b/docs/securitycenter_v1beta1/types.rst index b0ca8b93..0bbeba06 100644 --- a/docs/securitycenter_v1beta1/types.rst +++ b/docs/securitycenter_v1beta1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Securitycenter v1beta1 API .. automodule:: google.cloud.securitycenter_v1beta1.types :members: + :show-inheritance: diff --git a/docs/securitycenter_v1p1beta1/types.rst b/docs/securitycenter_v1p1beta1/types.rst index 390f90e2..a68ac5c6 100644 --- a/docs/securitycenter_v1p1beta1/types.rst +++ b/docs/securitycenter_v1p1beta1/types.rst @@ -3,3 +3,4 @@ Types for Google Cloud Securitycenter v1p1beta1 API .. automodule:: google.cloud.securitycenter_v1p1beta1.types :members: + :show-inheritance: diff --git a/google/cloud/securitycenter_v1/proto/finding.proto b/google/cloud/securitycenter_v1/proto/finding.proto index cf0873cf..dcc62f8b 100644 --- a/google/cloud/securitycenter_v1/proto/finding.proto +++ b/google/cloud/securitycenter_v1/proto/finding.proto @@ -56,6 +56,65 @@ message Finding { INACTIVE = 2; } + // The severity of the finding. + enum Severity { + // This value is used for findings when a source doesn't write a severity + // value. + SEVERITY_UNSPECIFIED = 0; + + // Vulnerability: + // A critical vulnerability is easily discoverable by an external actor, + // exploitable, and results in the direct ability to execute arbitrary code, + // exfiltrate data, and otherwise gain additional access and privileges to + // cloud resources and workloads. Examples include publicly accessible + // unprotected user data, public SSH access with weak or no passwords, etc. + // + // Threat: + // Indicates a threat that is able to access, modify, or delete data or + // execute unauthorized code within existing resources. + CRITICAL = 1; + + // Vulnerability: + // A high risk vulnerability can be easily discovered and exploited in + // combination with other vulnerabilities in order to gain direct access and + // the ability to execute arbitrary code, exfiltrate data, and otherwise + // gain additional access and privileges to cloud resources and workloads. + // An example is a database with weak or no passwords that is only + // accessible internally. This database could easily be compromised by an + // actor that had access to the internal network. + // + // Threat: + // Indicates a threat that is able to create new computational resources in + // an environment but not able to access data or execute code in existing + // resources. + HIGH = 2; + + // Vulnerability: + // A medium risk vulnerability could be used by an actor to gain access to + // resources or privileges that enable them to eventually (through multiple + // steps or a complex exploit) gain access and the ability to execute + // arbitrary code or exfiltrate data. An example is a service account with + // access to more projects than it should have. If an actor gains access to + // the service account, they could potentially use that access to manipulate + // a project the service account was not intended to. + // + // Threat: + // Indicates a threat that is able to cause operational impact but may not + // access data or execute unauthorized code. + MEDIUM = 3; + + // Vulnerability: + // A low risk vulnerability hampers a security organization’s ability to + // detect vulnerabilities or active threats in their deployment, or prevents + // the root cause investigation of security issues. An example is monitoring + // and logs being disabled for resource configurations and access. + // + // Threat: + // Indicates a threat that has obtained minimal access to an environment but + // is not able to access data, execute code, or create resources. + LOW = 4; + } + // The relative resource name of this finding. See: // https://cloud.google.com/apis/design/resource_names#relative_resource_name // Example: @@ -110,4 +169,8 @@ message Finding { // The time at which the finding was created in Security Command Center. google.protobuf.Timestamp create_time = 10; + + // The severity of the finding. This field is managed by the source that + // writes the finding. + Severity severity = 12; } diff --git a/google/cloud/securitycenter_v1/proto/notification_config.proto b/google/cloud/securitycenter_v1/proto/notification_config.proto index 90bd83c3..1a9676d9 100644 --- a/google/cloud/securitycenter_v1/proto/notification_config.proto +++ b/google/cloud/securitycenter_v1/proto/notification_config.proto @@ -78,14 +78,14 @@ message NotificationConfig { // The description of the notification config (max of 1024 characters). string description = 2; - // The PubSub topic to send notifications to. Its format is + // The Pub/Sub topic to send notifications to. Its format is // "projects/[project_id]/topics/[topic]". - string pubsub_topic = 3 [ - (google.api.resource_reference) = { type: "pubsub.googleapis.com/Topic" } - ]; + string pubsub_topic = 3 [(google.api.resource_reference) = { + type: "pubsub.googleapis.com/Topic" + }]; // Output only. The service account that needs "pubsub.topics.publish" - // permission to publish to the PubSub topic. + // permission to publish to the Pub/Sub topic. string service_account = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; // The config for triggering notifications. diff --git a/google/cloud/securitycenter_v1/proto/securitycenter_service.proto b/google/cloud/securitycenter_v1/proto/securitycenter_service.proto index b660d467..07f2f99d 100644 --- a/google/cloud/securitycenter_v1/proto/securitycenter_service.proto +++ b/google/cloud/securitycenter_v1/proto/securitycenter_service.proto @@ -17,7 +17,6 @@ syntax = "proto3"; package google.cloud.securitycenter.v1; import public "google/cloud/securitycenter/v1/run_asset_discovery_response.proto"; - import "google/api/annotations.proto"; import "google/api/client.proto"; import "google/api/field_behavior.proto"; @@ -47,8 +46,7 @@ option ruby_package = "Google::Cloud::SecurityCenter::V1"; // V1 APIs for Security Center service. service SecurityCenter { option (google.api.default_host) = "securitycenter.googleapis.com"; - option (google.api.oauth_scopes) = - "https://www.googleapis.com/auth/cloud-platform"; + option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; // Creates a source. rpc CreateSource(CreateSourceRequest) returns (Source) { @@ -70,20 +68,17 @@ service SecurityCenter { } // Creates a notification config. - rpc CreateNotificationConfig(CreateNotificationConfigRequest) - returns (NotificationConfig) { + rpc CreateNotificationConfig(CreateNotificationConfigRequest) returns (NotificationConfig) { option (google.api.http) = { post: "/v1/{parent=organizations/*}/notificationConfigs" body: "notification_config" }; - option (google.api.method_signature) = - "parent,config_id,notification_config"; + option (google.api.method_signature) = "parent,config_id,notification_config"; option (google.api.method_signature) = "parent,notification_config"; } // Deletes a notification config. - rpc DeleteNotificationConfig(DeleteNotificationConfigRequest) - returns (google.protobuf.Empty) { + rpc DeleteNotificationConfig(DeleteNotificationConfigRequest) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v1/{name=organizations/*/notificationConfigs/*}" }; @@ -91,8 +86,7 @@ service SecurityCenter { } // Gets the access control policy on the specified Source. - rpc GetIamPolicy(google.iam.v1.GetIamPolicyRequest) - returns (google.iam.v1.Policy) { + rpc GetIamPolicy(google.iam.v1.GetIamPolicyRequest) returns (google.iam.v1.Policy) { option (google.api.http) = { post: "/v1/{resource=organizations/*/sources/*}:getIamPolicy" body: "*" @@ -101,8 +95,7 @@ service SecurityCenter { } // Gets a notification config. - rpc GetNotificationConfig(GetNotificationConfigRequest) - returns (NotificationConfig) { + rpc GetNotificationConfig(GetNotificationConfigRequest) returns (NotificationConfig) { option (google.api.http) = { get: "/v1/{name=organizations/*/notificationConfigs/*}" }; @@ -110,8 +103,7 @@ service SecurityCenter { } // Gets the settings for an organization. - rpc GetOrganizationSettings(GetOrganizationSettingsRequest) - returns (OrganizationSettings) { + rpc GetOrganizationSettings(GetOrganizationSettingsRequest) returns (OrganizationSettings) { option (google.api.http) = { get: "/v1/{name=organizations/*/organizationSettings}" }; @@ -166,8 +158,7 @@ service SecurityCenter { } // Lists notification configs. - rpc ListNotificationConfigs(ListNotificationConfigsRequest) - returns (ListNotificationConfigsResponse) { + rpc ListNotificationConfigs(ListNotificationConfigsRequest) returns (ListNotificationConfigsResponse) { option (google.api.http) = { get: "/v1/{parent=organizations/*}/notificationConfigs" }; @@ -188,8 +179,7 @@ service SecurityCenter { // This API can only be called with limited frequency for an organization. If // it is called too frequently the caller will receive a TOO_MANY_REQUESTS // error. - rpc RunAssetDiscovery(RunAssetDiscoveryRequest) - returns (google.longrunning.Operation) { + rpc RunAssetDiscovery(RunAssetDiscoveryRequest) returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/{parent=organizations/*}/assets:runDiscovery" body: "*" @@ -211,8 +201,7 @@ service SecurityCenter { } // Sets the access control policy on the specified Source. - rpc SetIamPolicy(google.iam.v1.SetIamPolicyRequest) - returns (google.iam.v1.Policy) { + rpc SetIamPolicy(google.iam.v1.SetIamPolicyRequest) returns (google.iam.v1.Policy) { option (google.api.http) = { post: "/v1/{resource=organizations/*/sources/*}:setIamPolicy" body: "*" @@ -221,8 +210,7 @@ service SecurityCenter { } // Returns the permissions that a caller has on the specified source. - rpc TestIamPermissions(google.iam.v1.TestIamPermissionsRequest) - returns (google.iam.v1.TestIamPermissionsResponse) { + rpc TestIamPermissions(google.iam.v1.TestIamPermissionsRequest) returns (google.iam.v1.TestIamPermissionsResponse) { option (google.api.http) = { post: "/v1/{resource=organizations/*/sources/*}:testIamPermissions" body: "*" @@ -242,8 +230,7 @@ service SecurityCenter { // Updates a notification config. The following update // fields are allowed: description, pubsub_topic, streaming_config.filter - rpc UpdateNotificationConfig(UpdateNotificationConfigRequest) - returns (NotificationConfig) { + rpc UpdateNotificationConfig(UpdateNotificationConfigRequest) returns (NotificationConfig) { option (google.api.http) = { patch: "/v1/{notification_config.name=organizations/*/notificationConfigs/*}" body: "notification_config" @@ -253,8 +240,7 @@ service SecurityCenter { } // Updates an organization's settings. - rpc UpdateOrganizationSettings(UpdateOrganizationSettingsRequest) - returns (OrganizationSettings) { + rpc UpdateOrganizationSettings(UpdateOrganizationSettingsRequest) returns (OrganizationSettings) { option (google.api.http) = { patch: "/v1/{organization_settings.name=organizations/*/organizationSettings}" body: "organization_settings" @@ -301,15 +287,15 @@ message CreateFindingRequest { // greater than 0 characters in length. string finding_id = 2 [(google.api.field_behavior) = REQUIRED]; - // Required. The Finding being created. The name and security_marks will be - // ignored as they are both output only fields on this resource. + // Required. The Finding being created. The name and security_marks will be ignored as + // they are both output only fields on this resource. Finding finding = 3 [(google.api.field_behavior) = REQUIRED]; } // Request message for creating a notification config. message CreateNotificationConfigRequest { - // Required. Resource name of the new notification config's parent. Its format - // is "organizations/[organization_id]". + // Required. Resource name of the new notification config's parent. Its format is + // "organizations/[organization_id]". string parent = 1 [ (google.api.field_behavior) = REQUIRED, (google.api.resource_reference) = { @@ -323,11 +309,9 @@ message CreateNotificationConfigRequest { // characters, underscores or hyphens only. string config_id = 2 [(google.api.field_behavior) = REQUIRED]; - // Required. The notification config being created. The name and the service - // account will be ignored as they are both output only fields on this - // resource. - NotificationConfig notification_config = 3 - [(google.api.field_behavior) = REQUIRED]; + // Required. The notification config being created. The name and the service account + // will be ignored as they are both output only fields on this resource. + NotificationConfig notification_config = 3 [(google.api.field_behavior) = REQUIRED]; } // Request message for creating a source. @@ -341,8 +325,8 @@ message CreateSourceRequest { } ]; - // Required. The Source being created, only the display_name and description - // will be used. All other fields will be ignored. + // Required. The Source being created, only the display_name and description will be + // used. All other fields will be ignored. Source source = 2 [(google.api.field_behavior) = REQUIRED]; } @@ -372,8 +356,8 @@ message GetNotificationConfigRequest { // Request message for getting organization settings. message GetOrganizationSettingsRequest { - // Required. Name of the organization to get organization settings for. Its - // format is "organizations/[organization_id]/organizationSettings". + // Required. Name of the organization to get organization settings for. Its format is + // "organizations/[organization_id]/organizationSettings". string name = 1 [ (google.api.field_behavior) = REQUIRED, (google.api.resource_reference) = { @@ -463,15 +447,15 @@ message GroupAssetsRequest { // For example, `resource_properties.size = 100` is a valid filter string. // // Use a partial match on the empty string to filter based on a property - // existing:`resource_properties.my_property : ""` + // existing: `resource_properties.my_property : ""` // // Use a negated partial match on the empty string to filter based on a // property not existing: `-resource_properties.my_property : ""` string filter = 2; - // Required. Expression that defines what assets fields to use for grouping. - // The string value should follow SQL syntax: comma separated list of fields. - // For example: + // Required. Expression that defines what assets fields to use for grouping. The string + // value should follow SQL syntax: comma separated list of fields. For + // example: // "security_center_properties.resource_project,security_center_properties.project". // // The following fields are supported when compare_duration is not set: @@ -598,6 +582,7 @@ message GroupFindingsRequest { // * category: `=`, `:` // * external_uri: `=`, `:` // * event_time: `=`, `>`, `<`, `>=`, `<=` + // * severity: `=`, `:` // // Usage: This should be milliseconds since epoch or an RFC3339 string. // Examples: @@ -616,9 +601,9 @@ message GroupFindingsRequest { // property not existing: `-source_properties.my_property : ""` string filter = 2; - // Required. Expression that defines what assets fields to use for grouping - // (including `state_change`). The string value should follow SQL syntax: - // comma separated list of fields. For example: "parent,resource_name". + // Required. Expression that defines what assets fields to use for grouping (including + // `state_change`). The string value should follow SQL syntax: comma separated + // list of fields. For example: "parent,resource_name". // // The following fields are supported: // @@ -626,6 +611,7 @@ message GroupFindingsRequest { // * category // * state // * parent + // * severity // // The following fields are supported when compare_duration is set: // @@ -901,10 +887,10 @@ message ListAssetsRequest { // read_time. google.protobuf.Duration compare_duration = 5; - // Optional. A field mask to specify the ListAssetsResult fields to be listed - // in the response. An empty field mask will list all fields. - google.protobuf.FieldMask field_mask = 7 - [(google.api.field_behavior) = OPTIONAL]; + // A field mask to specify the ListAssetsResult fields to be listed in the + // response. + // An empty field mask will list all fields. + google.protobuf.FieldMask field_mask = 7; // The value returned by the last `ListAssetsResponse`; indicates // that this is a continuation of a prior `ListAssets` call, and @@ -1000,13 +986,14 @@ message ListFindingsRequest { // // The following field and operator combinations are supported: // - // name: `=` - // parent: `=`, `:` - // resource_name: `=`, `:` - // state: `=`, `:` - // category: `=`, `:` - // external_uri: `=`, `:` - // event_time: `=`, `>`, `<`, `>=`, `<=` + // * name: `=` + // * parent: `=`, `:` + // * resource_name: `=`, `:` + // * state: `=`, `:` + // * category: `=`, `:` + // * external_uri: `=`, `:` + // * event_time: `=`, `>`, `<`, `>=`, `<=` + // * severity: `=`, `:` // // Usage: This should be milliseconds since epoch or an RFC3339 string. // Examples: @@ -1083,10 +1070,9 @@ message ListFindingsRequest { // read_time. google.protobuf.Duration compare_duration = 5; - // Optional. A field mask to specify the Finding fields to be listed in the - // response. An empty field mask will list all fields. - google.protobuf.FieldMask field_mask = 7 - [(google.api.field_behavior) = OPTIONAL]; + // A field mask to specify the Finding fields to be listed in the response. + // An empty field mask will list all fields. + google.protobuf.FieldMask field_mask = 7; // The value returned by the last `ListFindingsResponse`; indicates // that this is a continuation of a prior `ListFindings` call, and @@ -1157,7 +1143,7 @@ message ListFindingsResponse { StateChange state_change = 2; // Output only. Resource that is associated with this finding. - Resource resource = 3; + Resource resource = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; } // Findings matching the list request. @@ -1191,14 +1177,13 @@ message SetFindingStateRequest { Finding.State state = 2 [(google.api.field_behavior) = REQUIRED]; // Required. The time at which the updated state takes effect. - google.protobuf.Timestamp start_time = 3 - [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp start_time = 3 [(google.api.field_behavior) = REQUIRED]; } // Request message for running asset discovery for an organization. message RunAssetDiscoveryRequest { - // Required. Name of the organization to run asset discovery for. Its format - // is "organizations/[organization_id]". + // Required. Name of the organization to run asset discovery for. Its format is + // "organizations/[organization_id]". string parent = 1 [ (google.api.field_behavior) = REQUIRED, (google.api.resource_reference) = { @@ -1209,8 +1194,8 @@ message RunAssetDiscoveryRequest { // Request message for updating or creating a finding. message UpdateFindingRequest { - // Required. The finding resource to update or create if it does not already - // exist. parent, security_marks, and update_time will be ignored. + // Required. The finding resource to update or create if it does not already exist. + // parent, security_marks, and update_time will be ignored. // // In the case of creation, the finding id portion of the name must be // alphanumeric and less than or equal to 32 characters and greater than 0 @@ -1230,8 +1215,7 @@ message UpdateFindingRequest { // Request message for updating a notification config. message UpdateNotificationConfigRequest { // Required. The notification config to update. - NotificationConfig notification_config = 1 - [(google.api.field_behavior) = REQUIRED]; + NotificationConfig notification_config = 1 [(google.api.field_behavior) = REQUIRED]; // The FieldMask to use when updating the notification config. // @@ -1242,12 +1226,11 @@ message UpdateNotificationConfigRequest { // Request message for updating an organization's settings. message UpdateOrganizationSettingsRequest { // Required. The organization settings resource to update. - OrganizationSettings organization_settings = 1 - [(google.api.field_behavior) = REQUIRED]; + OrganizationSettings organization_settings = 1 [(google.api.field_behavior) = REQUIRED]; // The FieldMask to use when updating the settings resource. // - // If empty all mutable fields will be updated. + // If empty all mutable fields will be updated. google.protobuf.FieldMask update_mask = 2; } diff --git a/google/cloud/securitycenter_v1/services/security_center/async_client.py b/google/cloud/securitycenter_v1/services/security_center/async_client.py index 4e9b54d7..b0b01027 100644 --- a/google/cloud/securitycenter_v1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1/services/security_center/async_client.py @@ -66,6 +66,8 @@ class SecurityCenterAsyncClient: DEFAULT_ENDPOINT = SecurityCenterClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SecurityCenterClient.DEFAULT_MTLS_ENDPOINT + asset_path = staticmethod(SecurityCenterClient.asset_path) + parse_asset_path = staticmethod(SecurityCenterClient.parse_asset_path) finding_path = staticmethod(SecurityCenterClient.finding_path) parse_finding_path = staticmethod(SecurityCenterClient.parse_finding_path) notification_config_path = staticmethod( @@ -86,10 +88,50 @@ class SecurityCenterAsyncClient: ) source_path = staticmethod(SecurityCenterClient.source_path) parse_source_path = staticmethod(SecurityCenterClient.parse_source_path) + topic_path = staticmethod(SecurityCenterClient.topic_path) + parse_topic_path = staticmethod(SecurityCenterClient.parse_topic_path) + + common_billing_account_path = staticmethod( + SecurityCenterClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + SecurityCenterClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(SecurityCenterClient.common_folder_path) + parse_common_folder_path = staticmethod( + SecurityCenterClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + SecurityCenterClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + SecurityCenterClient.parse_common_organization_path + ) + + common_project_path = staticmethod(SecurityCenterClient.common_project_path) + parse_common_project_path = staticmethod( + SecurityCenterClient.parse_common_project_path + ) + + common_location_path = staticmethod(SecurityCenterClient.common_location_path) + parse_common_location_path = staticmethod( + SecurityCenterClient.parse_common_location_path + ) from_service_account_file = SecurityCenterClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> SecurityCenterTransport: + """Return the transport used by the client instance. + + Returns: + SecurityCenterTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(SecurityCenterClient).get_transport_class, type(SecurityCenterClient) ) @@ -191,7 +233,8 @@ async def create_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, source]): + has_flattened_params = any([parent, source]) + 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." @@ -291,7 +334,8 @@ async def create_finding( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, finding_id, finding]): + has_flattened_params = any([parent, finding_id, finding]) + 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." @@ -390,7 +434,8 @@ async def create_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, config_id, notification_config]): + has_flattened_params = any([parent, config_id, notification_config]) + 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." @@ -460,7 +505,8 @@ async def delete_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -596,7 +642,8 @@ async def get_iam_policy( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource]): + has_flattened_params = any([resource]) + 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." @@ -608,13 +655,7 @@ async def get_iam_policy( request = iam_policy.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -625,7 +666,7 @@ async def get_iam_policy( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -686,7 +727,8 @@ async def get_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -709,7 +751,7 @@ async def get_notification_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -767,7 +809,8 @@ async def get_organization_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -790,7 +833,7 @@ async def get_organization_settings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -851,7 +894,8 @@ async def get_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -874,7 +918,7 @@ async def get_source( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -937,7 +981,7 @@ async def group_assets( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1004,6 +1048,7 @@ async def group_findings( - state - parent + - severity The following fields are supported when compare_duration is set: @@ -1032,7 +1077,8 @@ async def group_findings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, group_by]): + has_flattened_params = any([parent, group_by]) + 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." @@ -1057,7 +1103,7 @@ async def group_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1123,7 +1169,7 @@ async def list_assets( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1194,7 +1240,7 @@ async def list_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1260,7 +1306,8 @@ async def list_notification_configs( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1283,7 +1330,7 @@ async def list_notification_configs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -1347,7 +1394,8 @@ async def list_sources( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1370,7 +1418,7 @@ async def list_sources( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -1441,7 +1489,8 @@ async def run_asset_discovery( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1544,7 +1593,8 @@ async def set_finding_state( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, state, start_time]): + has_flattened_params = any([name, state, start_time]) + 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." @@ -1685,7 +1735,8 @@ async def set_iam_policy( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource]): + has_flattened_params = any([resource]) + 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." @@ -1697,13 +1748,7 @@ async def set_iam_policy( request = iam_policy.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1772,7 +1817,8 @@ async def test_iam_permissions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource, permissions]): + has_flattened_params = any([resource, permissions]) + 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." @@ -1784,16 +1830,9 @@ async def test_iam_permissions( request = iam_policy.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource - - if permissions: - request.permissions.extend(permissions) + request = iam_policy.TestIamPermissionsRequest( + resource=resource, permissions=permissions, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1804,7 +1843,7 @@ async def test_iam_permissions( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -1873,7 +1912,8 @@ async def update_finding( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([finding]): + has_flattened_params = any([finding]) + 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." @@ -1960,7 +2000,8 @@ async def update_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([notification_config, update_mask]): + has_flattened_params = any([notification_config, update_mask]) + 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." @@ -2036,7 +2077,8 @@ async def update_organization_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([organization_settings]): + has_flattened_params = any([organization_settings]) + 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." @@ -2113,7 +2155,8 @@ async def update_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([source]): + has_flattened_params = any([source]) + 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." @@ -2192,7 +2235,8 @@ async def update_security_marks( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([security_marks]): + has_flattened_params = any([security_marks]) + 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." diff --git a/google/cloud/securitycenter_v1/services/security_center/client.py b/google/cloud/securitycenter_v1/services/security_center/client.py index b7d715fb..319ca077 100644 --- a/google/cloud/securitycenter_v1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1/services/security_center/client.py @@ -152,6 +152,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> SecurityCenterTransport: + """Return the transport used by the client instance. + + Returns: + SecurityCenterTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def asset_path(organization: str, asset: str,) -> str: + """Return a fully-qualified asset string.""" + return "organizations/{organization}/assets/{asset}".format( + organization=organization, asset=asset, + ) + + @staticmethod + def parse_asset_path(path: str) -> Dict[str, str]: + """Parse a asset path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/assets/(?P.+?)$", path + ) + return m.groupdict() if m else {} + @staticmethod def finding_path(organization: str, source: str, finding: str,) -> str: """Return a fully-qualified finding string.""" @@ -230,6 +254,76 @@ def parse_source_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def topic_path(project: str, topic: str,) -> str: + """Return a fully-qualified topic string.""" + return "projects/{project}/topics/{topic}".format(project=project, topic=topic,) + + @staticmethod + def parse_topic_path(path: str) -> Dict[str, str]: + """Parse a topic path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/topics/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return 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: + """Return 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: + """Return 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: + """Return 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: + """Return 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 {} + def __init__( self, *, @@ -265,10 +359,10 @@ def __init__( 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. - 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 + 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: @@ -830,13 +924,7 @@ def get_iam_policy( request = iam_policy.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1193,6 +1281,7 @@ def group_findings( - state - parent + - severity The following fields are supported when compare_duration is set: @@ -1863,13 +1952,7 @@ def set_iam_policy( request = iam_policy.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1947,16 +2030,9 @@ def test_iam_permissions( request = iam_policy.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource - - if permissions: - request.permissions.extend(permissions) + request = iam_policy.TestIamPermissionsRequest( + resource=resource, permissions=permissions, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/__init__.py b/google/cloud/securitycenter_v1/services/security_center/transports/__init__.py index 20423f2a..45814553 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/__init__.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = SecurityCenterGrpcTransport _transport_registry["grpc_asyncio"] = SecurityCenterGrpcAsyncIOTransport - __all__ = ( "SecurityCenterTransport", "SecurityCenterGrpcTransport", diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1/services/security_center/transports/base.py index 9bd2b417..896b834a 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/base.py @@ -148,7 +148,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -161,7 +161,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -174,7 +174,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -187,7 +187,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -200,7 +200,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -213,7 +213,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -226,7 +226,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -239,7 +239,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -252,7 +252,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -265,7 +265,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -287,7 +287,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py index d114c5e9..8d8c03c3 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc.py @@ -107,10 +107,10 @@ def __init__( for grpc 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're developing + 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: @@ -119,6 +119,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -126,6 +128,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -161,7 +164,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -178,9 +186,14 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] + self._operations_client = None # Run the base constructor. super().__init__( @@ -204,7 +217,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (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 @@ -239,12 +252,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.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 designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property @@ -255,13 +264,11 @@ def operations_client(self) -> operations_v1.OperationsClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsClient( - self.grpc_channel - ) + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def create_source( diff --git a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py index 4b036ee5..b44d5ce1 100644 --- a/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py @@ -164,6 +164,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -171,6 +173,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -206,7 +209,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -223,6 +231,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. @@ -236,6 +248,7 @@ def __init__( ) self._stubs = {} + self._operations_client = None @property def grpc_channel(self) -> aio.Channel: @@ -255,13 +268,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient( + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel ) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def create_source( diff --git a/google/cloud/securitycenter_v1/types/__init__.py b/google/cloud/securitycenter_v1/types/__init__.py index c65c45b8..1a1ebb24 100644 --- a/google/cloud/securitycenter_v1/types/__init__.py +++ b/google/cloud/securitycenter_v1/types/__init__.py @@ -54,7 +54,6 @@ UpdateSecurityMarksRequest, ) - __all__ = ( "SecurityMarks", "Asset", diff --git a/google/cloud/securitycenter_v1/types/finding.py b/google/cloud/securitycenter_v1/types/finding.py index aff349c6..5c5e3146 100644 --- a/google/cloud/securitycenter_v1/types/finding.py +++ b/google/cloud/securitycenter_v1/types/finding.py @@ -90,6 +90,9 @@ class Finding(proto.Message): create_time (~.timestamp.Timestamp): The time at which the finding was created in Security Command Center. + severity (~.finding.Finding.Severity): + The severity of the finding. This field is + managed by the source that writes the finding. """ class State(proto.Enum): @@ -98,6 +101,14 @@ class State(proto.Enum): ACTIVE = 1 INACTIVE = 2 + class Severity(proto.Enum): + r"""The severity of the finding.""" + SEVERITY_UNSPECIFIED = 0 + CRITICAL = 1 + HIGH = 2 + MEDIUM = 3 + LOW = 4 + name = proto.Field(proto.STRING, number=1) parent = proto.Field(proto.STRING, number=2) @@ -122,5 +133,7 @@ class State(proto.Enum): create_time = proto.Field(proto.MESSAGE, number=10, message=timestamp.Timestamp,) + severity = proto.Field(proto.ENUM, number=12, enum=Severity,) + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/securitycenter_v1/types/notification_config.py b/google/cloud/securitycenter_v1/types/notification_config.py index 87e4d654..13cd5c90 100644 --- a/google/cloud/securitycenter_v1/types/notification_config.py +++ b/google/cloud/securitycenter_v1/types/notification_config.py @@ -40,12 +40,12 @@ class NotificationConfig(proto.Message): The description of the notification config (max of 1024 characters). pubsub_topic (str): - The PubSub topic to send notifications to. Its format is + The Pub/Sub topic to send notifications to. Its format is "projects/[project_id]/topics/[topic]". service_account (str): Output only. The service account that needs "pubsub.topics.publish" permission to publish to - the PubSub topic. + the Pub/Sub topic. streaming_config (~.notification_config.NotificationConfig.StreamingConfig): The config for triggering streaming-based notifications. diff --git a/google/cloud/securitycenter_v1/types/securitycenter_service.py b/google/cloud/securitycenter_v1/types/securitycenter_service.py index 150917f4..486003a5 100644 --- a/google/cloud/securitycenter_v1/types/securitycenter_service.py +++ b/google/cloud/securitycenter_v1/types/securitycenter_service.py @@ -277,7 +277,7 @@ class GroupAssetsRequest(proto.Message): filter string. Use a partial match on the empty string to filter based on a - property existing:\ ``resource_properties.my_property : ""`` + property existing: ``resource_properties.my_property : ""`` Use a negated partial match on the empty string to filter based on a property not existing: @@ -454,6 +454,8 @@ class GroupFindingsRequest(proto.Message): - event_time: ``=``, ``>``, ``<``, ``>=``, ``<=`` + - severity: ``=``, ``:`` + Usage: This should be milliseconds since epoch or an RFC3339 string. Examples: ``event_time = "2019-06-10T16:07:18-07:00"`` @@ -485,6 +487,7 @@ class GroupFindingsRequest(proto.Message): - category - state - parent + - severity The following fields are supported when compare_duration is set: @@ -853,10 +856,9 @@ class ListAssetsRequest(proto.Message): state_change is "UNUSED", which will be the state_change set for all assets present at read_time. field_mask (~.gp_field_mask.FieldMask): - Optional. A field mask to specify the - ListAssetsResult fields to be listed in the - response. An empty field mask will list all - fields. + A field mask to specify the ListAssetsResult + fields to be listed in the response. + An empty field mask will list all fields. page_token (str): The value returned by the last ``ListAssetsResponse``; indicates that this is a continuation of a prior @@ -987,14 +989,26 @@ class ListFindingsRequest(proto.Message): The following field and operator combinations are supported: - name: ``=`` parent: ``=``, ``:`` resource_name: ``=``, ``:`` - state: ``=``, ``:`` category: ``=``, ``:`` external_uri: - ``=``, ``:`` event_time: ``=``, ``>``, ``<``, ``>=``, ``<=`` + - name: ``=`` + + - parent: ``=``, ``:`` + + - resource_name: ``=``, ``:`` + + - state: ``=``, ``:`` + + - category: ``=``, ``:`` + + - external_uri: ``=``, ``:`` + + - event_time: ``=``, ``>``, ``<``, ``>=``, ``<=`` - Usage: This should be milliseconds since epoch or an RFC3339 - string. Examples: - ``event_time = "2019-06-10T16:07:18-07:00"`` - ``event_time = 1560208038000`` + - severity: ``=``, ``:`` + + Usage: This should be milliseconds since epoch or an + RFC3339 string. Examples: + ``event_time = "2019-06-10T16:07:18-07:00"`` + ``event_time = 1560208038000`` security_marks.marks: ``=``, ``:`` source_properties: ``=``, ``:``, ``>``, ``<``, ``>=``, ``<=`` @@ -1064,9 +1078,9 @@ class ListFindingsRequest(proto.Message): state_change is "UNUSED", which will be the state_change set for all findings present at read_time. field_mask (~.gp_field_mask.FieldMask): - Optional. A field mask to specify the Finding - fields to be listed in the response. An empty - field mask will list all fields. + A field mask to specify the Finding fields to + be listed in the response. An empty field mask + will list all fields. page_token (str): The value returned by the last ``ListFindingsResponse``; indicates that this is a continuation of a prior diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py b/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py index b925674b..c9dccb0d 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/async_client.py @@ -62,6 +62,8 @@ class SecurityCenterAsyncClient: DEFAULT_ENDPOINT = SecurityCenterClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SecurityCenterClient.DEFAULT_MTLS_ENDPOINT + asset_path = staticmethod(SecurityCenterClient.asset_path) + parse_asset_path = staticmethod(SecurityCenterClient.parse_asset_path) finding_path = staticmethod(SecurityCenterClient.finding_path) parse_finding_path = staticmethod(SecurityCenterClient.parse_finding_path) organization_settings_path = staticmethod( @@ -77,9 +79,47 @@ class SecurityCenterAsyncClient: source_path = staticmethod(SecurityCenterClient.source_path) parse_source_path = staticmethod(SecurityCenterClient.parse_source_path) + common_billing_account_path = staticmethod( + SecurityCenterClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + SecurityCenterClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(SecurityCenterClient.common_folder_path) + parse_common_folder_path = staticmethod( + SecurityCenterClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + SecurityCenterClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + SecurityCenterClient.parse_common_organization_path + ) + + common_project_path = staticmethod(SecurityCenterClient.common_project_path) + parse_common_project_path = staticmethod( + SecurityCenterClient.parse_common_project_path + ) + + common_location_path = staticmethod(SecurityCenterClient.common_location_path) + parse_common_location_path = staticmethod( + SecurityCenterClient.parse_common_location_path + ) + from_service_account_file = SecurityCenterClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> SecurityCenterTransport: + """Return the transport used by the client instance. + + Returns: + SecurityCenterTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(SecurityCenterClient).get_transport_class, type(SecurityCenterClient) ) @@ -181,7 +221,8 @@ async def create_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, source]): + has_flattened_params = any([parent, source]) + 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." @@ -281,7 +322,8 @@ async def create_finding( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, finding_id, finding]): + has_flattened_params = any([parent, finding_id, finding]) + 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." @@ -422,7 +464,8 @@ async def get_iam_policy( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource]): + has_flattened_params = any([resource]) + 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." @@ -434,13 +477,7 @@ async def get_iam_policy( request = iam_policy.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -509,7 +546,8 @@ async def get_organization_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -593,7 +631,8 @@ async def get_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -769,7 +808,8 @@ async def group_findings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, group_by]): + has_flattened_params = any([parent, group_by]) + 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." @@ -996,7 +1036,8 @@ async def list_sources( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1102,7 +1143,8 @@ async def run_asset_discovery( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1205,7 +1247,8 @@ async def set_finding_state( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, state, start_time]): + has_flattened_params = any([name, state, start_time]) + 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." @@ -1346,7 +1389,8 @@ async def set_iam_policy( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource]): + has_flattened_params = any([resource]) + 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." @@ -1358,13 +1402,7 @@ async def set_iam_policy( request = iam_policy.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1471,8 @@ async def test_iam_permissions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource, permissions]): + has_flattened_params = any([resource, permissions]) + 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." @@ -1445,16 +1484,9 @@ async def test_iam_permissions( request = iam_policy.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource - - if permissions: - request.permissions.extend(permissions) + request = iam_policy.TestIamPermissionsRequest( + resource=resource, permissions=permissions, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1534,7 +1566,8 @@ async def update_finding( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([finding]): + has_flattened_params = any([finding]) + 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." @@ -1608,7 +1641,8 @@ async def update_organization_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([organization_settings]): + has_flattened_params = any([organization_settings]) + 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." @@ -1685,7 +1719,8 @@ async def update_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([source]): + has_flattened_params = any([source]) + 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." @@ -1764,7 +1799,8 @@ async def update_security_marks( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([security_marks]): + has_flattened_params = any([security_marks]) + 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." diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/client.py b/google/cloud/securitycenter_v1beta1/services/security_center/client.py index 7aa7cdce..a27f307b 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/client.py @@ -148,6 +148,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> SecurityCenterTransport: + """Return the transport used by the client instance. + + Returns: + SecurityCenterTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def asset_path(organization: str, asset: str,) -> str: + """Return a fully-qualified asset string.""" + return "organizations/{organization}/assets/{asset}".format( + organization=organization, asset=asset, + ) + + @staticmethod + def parse_asset_path(path: str) -> Dict[str, str]: + """Parse a asset path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/assets/(?P.+?)$", path + ) + return m.groupdict() if m else {} + @staticmethod def finding_path(organization: str, source: str, finding: str,) -> str: """Return a fully-qualified finding string.""" @@ -210,6 +234,65 @@ def parse_source_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return 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: + """Return 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: + """Return 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: + """Return 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: + """Return 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 {} + def __init__( self, *, @@ -245,10 +328,10 @@ def __init__( 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. - 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 + 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: @@ -634,13 +717,7 @@ def get_iam_policy( request = iam_policy.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1510,13 +1587,7 @@ def set_iam_policy( request = iam_policy.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1594,16 +1665,9 @@ def test_iam_permissions( request = iam_policy.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource - - if permissions: - request.permissions.extend(permissions) + request = iam_policy.TestIamPermissionsRequest( + resource=resource, permissions=permissions, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/__init__.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/__init__.py index 20423f2a..45814553 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/__init__.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = SecurityCenterGrpcTransport _transport_registry["grpc_asyncio"] = SecurityCenterGrpcAsyncIOTransport - __all__ = ( "SecurityCenterTransport", "SecurityCenterGrpcTransport", diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py index 5291388d..a7447d0b 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py @@ -104,10 +104,10 @@ def __init__( for grpc 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're developing + 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: @@ -116,6 +116,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -123,6 +125,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -158,7 +161,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -175,9 +183,14 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] + self._operations_client = None # Run the base constructor. super().__init__( @@ -201,7 +214,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (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 @@ -236,12 +249,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.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 designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property @@ -252,13 +261,11 @@ def operations_client(self) -> operations_v1.OperationsClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsClient( - self.grpc_channel - ) + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def create_source( diff --git a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py index 0ec96a14..2a2d3551 100644 --- a/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py @@ -161,6 +161,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -168,6 +170,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -203,7 +206,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -220,6 +228,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. @@ -233,6 +245,7 @@ def __init__( ) self._stubs = {} + self._operations_client = None @property def grpc_channel(self) -> aio.Channel: @@ -252,13 +265,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient( + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel ) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def create_source( diff --git a/google/cloud/securitycenter_v1beta1/types/__init__.py b/google/cloud/securitycenter_v1beta1/types/__init__.py index 50ef54be..11c4424f 100644 --- a/google/cloud/securitycenter_v1beta1/types/__init__.py +++ b/google/cloud/securitycenter_v1beta1/types/__init__.py @@ -45,7 +45,6 @@ UpdateSecurityMarksRequest, ) - __all__ = ( "SecurityMarks", "Asset", diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py index 78f388f0..a3a51ca4 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/async_client.py @@ -68,6 +68,8 @@ class SecurityCenterAsyncClient: DEFAULT_ENDPOINT = SecurityCenterClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SecurityCenterClient.DEFAULT_MTLS_ENDPOINT + asset_path = staticmethod(SecurityCenterClient.asset_path) + parse_asset_path = staticmethod(SecurityCenterClient.parse_asset_path) finding_path = staticmethod(SecurityCenterClient.finding_path) parse_finding_path = staticmethod(SecurityCenterClient.parse_finding_path) notification_config_path = staticmethod( @@ -88,10 +90,50 @@ class SecurityCenterAsyncClient: ) source_path = staticmethod(SecurityCenterClient.source_path) parse_source_path = staticmethod(SecurityCenterClient.parse_source_path) + topic_path = staticmethod(SecurityCenterClient.topic_path) + parse_topic_path = staticmethod(SecurityCenterClient.parse_topic_path) + + common_billing_account_path = staticmethod( + SecurityCenterClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + SecurityCenterClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(SecurityCenterClient.common_folder_path) + parse_common_folder_path = staticmethod( + SecurityCenterClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + SecurityCenterClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + SecurityCenterClient.parse_common_organization_path + ) + + common_project_path = staticmethod(SecurityCenterClient.common_project_path) + parse_common_project_path = staticmethod( + SecurityCenterClient.parse_common_project_path + ) + + common_location_path = staticmethod(SecurityCenterClient.common_location_path) + parse_common_location_path = staticmethod( + SecurityCenterClient.parse_common_location_path + ) from_service_account_file = SecurityCenterClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> SecurityCenterTransport: + """Return the transport used by the client instance. + + Returns: + SecurityCenterTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(SecurityCenterClient).get_transport_class, type(SecurityCenterClient) ) @@ -193,7 +235,8 @@ async def create_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, source]): + has_flattened_params = any([parent, source]) + 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." @@ -290,7 +333,8 @@ async def create_finding( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, finding_id, finding]): + has_flattened_params = any([parent, finding_id, finding]) + 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." @@ -389,7 +433,8 @@ async def create_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, config_id, notification_config]): + has_flattened_params = any([parent, config_id, notification_config]) + 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." @@ -459,7 +504,8 @@ async def delete_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -595,7 +641,8 @@ async def get_iam_policy( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource]): + has_flattened_params = any([resource]) + 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." @@ -607,13 +654,7 @@ async def get_iam_policy( request = iam_policy.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -624,7 +665,7 @@ async def get_iam_policy( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -686,7 +727,8 @@ async def get_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -709,7 +751,7 @@ async def get_notification_config( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -767,7 +809,8 @@ async def get_organization_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -790,7 +833,7 @@ async def get_organization_settings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -851,7 +894,8 @@ async def get_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + 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." @@ -874,7 +918,7 @@ async def get_source( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -937,7 +981,7 @@ async def group_assets( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1034,7 +1078,8 @@ async def group_findings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, group_by]): + has_flattened_params = any([parent, group_by]) + 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." @@ -1059,7 +1104,7 @@ async def group_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1122,7 +1167,8 @@ async def list_assets( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1145,7 +1191,7 @@ async def list_assets( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1217,7 +1263,8 @@ async def list_findings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1240,7 +1287,7 @@ async def list_findings( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -1306,7 +1353,8 @@ async def list_notification_configs( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1329,7 +1377,7 @@ async def list_notification_configs( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -1393,7 +1441,8 @@ async def list_sources( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1416,7 +1465,7 @@ async def list_sources( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -1487,7 +1536,8 @@ async def run_asset_discovery( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + 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." @@ -1590,7 +1640,8 @@ async def set_finding_state( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name, state, start_time]): + has_flattened_params = any([name, state, start_time]) + 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." @@ -1731,7 +1782,8 @@ async def set_iam_policy( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource]): + has_flattened_params = any([resource]) + 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." @@ -1743,13 +1795,7 @@ async def set_iam_policy( request = iam_policy.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1818,7 +1864,8 @@ async def test_iam_permissions( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([resource, permissions]): + has_flattened_params = any([resource, permissions]) + 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." @@ -1830,16 +1877,9 @@ async def test_iam_permissions( request = iam_policy.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource - - if permissions: - request.permissions.extend(permissions) + request = iam_policy.TestIamPermissionsRequest( + resource=resource, permissions=permissions, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1850,7 +1890,7 @@ async def test_iam_permissions( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -1933,7 +1973,8 @@ async def update_finding( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([finding, update_mask]): + has_flattened_params = any([finding, update_mask]) + 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." @@ -2023,7 +2064,8 @@ async def update_notification_config( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([notification_config, update_mask]): + has_flattened_params = any([notification_config, update_mask]) + 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." @@ -2099,7 +2141,8 @@ async def update_organization_settings( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([organization_settings]): + has_flattened_params = any([organization_settings]) + 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." @@ -2185,7 +2228,8 @@ async def update_source( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([source, update_mask]): + has_flattened_params = any([source, update_mask]) + 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." @@ -2278,7 +2322,8 @@ async def update_security_marks( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([security_marks, update_mask]): + has_flattened_params = any([security_marks, update_mask]) + 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." diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py index 814ad115..b2b042e8 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/client.py @@ -154,6 +154,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> SecurityCenterTransport: + """Return the transport used by the client instance. + + Returns: + SecurityCenterTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def asset_path(organization: str, asset: str,) -> str: + """Return a fully-qualified asset string.""" + return "organizations/{organization}/assets/{asset}".format( + organization=organization, asset=asset, + ) + + @staticmethod + def parse_asset_path(path: str) -> Dict[str, str]: + """Parse a asset path into its component segments.""" + m = re.match( + r"^organizations/(?P.+?)/assets/(?P.+?)$", path + ) + return m.groupdict() if m else {} + @staticmethod def finding_path(organization: str, source: str, finding: str,) -> str: """Return a fully-qualified finding string.""" @@ -232,6 +256,76 @@ def parse_source_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def topic_path(project: str, topic: str,) -> str: + """Return a fully-qualified topic string.""" + return "projects/{project}/topics/{topic}".format(project=project, topic=topic,) + + @staticmethod + def parse_topic_path(path: str) -> Dict[str, str]: + """Parse a topic path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/topics/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return 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: + """Return 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: + """Return 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: + """Return 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: + """Return 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 {} + def __init__( self, *, @@ -267,10 +361,10 @@ def __init__( 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. - 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 + 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: @@ -829,13 +923,7 @@ def get_iam_policy( request = iam_policy.GetIamPolicyRequest(**request) elif not request: - request = iam_policy.GetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.GetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1911,13 +1999,7 @@ def set_iam_policy( request = iam_policy.SetIamPolicyRequest(**request) elif not request: - request = iam_policy.SetIamPolicyRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource + request = iam_policy.SetIamPolicyRequest(resource=resource,) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1995,16 +2077,9 @@ def test_iam_permissions( request = iam_policy.TestIamPermissionsRequest(**request) elif not request: - request = iam_policy.TestIamPermissionsRequest() - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - - if resource is not None: - request.resource = resource - - if permissions: - request.permissions.extend(permissions) + request = iam_policy.TestIamPermissionsRequest( + resource=resource, permissions=permissions, + ) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/__init__.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/__init__.py index 20423f2a..45814553 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/__init__.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/__init__.py @@ -28,7 +28,6 @@ _transport_registry["grpc"] = SecurityCenterGrpcTransport _transport_registry["grpc_asyncio"] = SecurityCenterGrpcAsyncIOTransport - __all__ = ( "SecurityCenterTransport", "SecurityCenterGrpcTransport", diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py index fb0b14ba..59b77852 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py @@ -150,7 +150,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -163,7 +163,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -176,7 +176,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -189,7 +189,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -202,7 +202,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -215,7 +215,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -228,7 +228,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -241,7 +241,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=480.0, @@ -254,7 +254,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -267,7 +267,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, @@ -289,7 +289,7 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( - exceptions.ServiceUnavailable, exceptions.DeadlineExceeded, + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), default_timeout=60.0, diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py index b79627be..d402248c 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py @@ -109,10 +109,10 @@ def __init__( for grpc 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're developing + 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: @@ -121,6 +121,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -128,6 +130,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -163,7 +166,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -180,9 +188,14 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) self._stubs = {} # type: Dict[str, Callable] + self._operations_client = None # Run the base constructor. super().__init__( @@ -206,7 +219,7 @@ def create_channel( ) -> grpc.Channel: """Create and return a gRPC channel object. Args: - address (Optionsl[str]): The host for the channel to use. + address (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 @@ -241,12 +254,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.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 designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property @@ -257,13 +266,11 @@ def operations_client(self) -> operations_v1.OperationsClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsClient( - self.grpc_channel - ) + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def create_source( diff --git a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py index f7bcf44a..3269c916 100644 --- a/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py +++ b/google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py @@ -166,6 +166,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -173,6 +175,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -208,7 +211,12 @@ def __init__( ssl_credentials=ssl_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -225,6 +233,10 @@ def __init__( ssl_credentials=ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], ) # Run the base constructor. @@ -238,6 +250,7 @@ def __init__( ) self._stubs = {} + self._operations_client = None @property def grpc_channel(self) -> aio.Channel: @@ -257,13 +270,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: client. """ # Sanity check: Only create a new client if we do not already have one. - if "operations_client" not in self.__dict__: - self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient( + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel ) # Return the client from cache. - return self.__dict__["operations_client"] + return self._operations_client @property def create_source( diff --git a/google/cloud/securitycenter_v1p1beta1/types/__init__.py b/google/cloud/securitycenter_v1p1beta1/types/__init__.py index c65c45b8..1a1ebb24 100644 --- a/google/cloud/securitycenter_v1p1beta1/types/__init__.py +++ b/google/cloud/securitycenter_v1p1beta1/types/__init__.py @@ -54,7 +54,6 @@ UpdateSecurityMarksRequest, ) - __all__ = ( "SecurityMarks", "Asset", diff --git a/noxfile.py b/noxfile.py index 33b3b498..bf5b92d4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,7 +28,7 @@ DEFAULT_PYTHON_VERSION = "3.8" SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] @nox.session(python=DEFAULT_PYTHON_VERSION) diff --git a/scripts/fixup_securitycenter_v1_keywords.py b/scripts/fixup_securitycenter_v1_keywords.py index 70abd28b..6afbe367 100644 --- a/scripts/fixup_securitycenter_v1_keywords.py +++ b/scripts/fixup_securitycenter_v1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/scripts/fixup_securitycenter_v1beta1_keywords.py b/scripts/fixup_securitycenter_v1beta1_keywords.py index e7f3f9f4..c2bdd2db 100644 --- a/scripts/fixup_securitycenter_v1beta1_keywords.py +++ b/scripts/fixup_securitycenter_v1beta1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/scripts/fixup_securitycenter_v1p1beta1_keywords.py b/scripts/fixup_securitycenter_v1p1beta1_keywords.py index 70abd28b..6afbe367 100644 --- a/scripts/fixup_securitycenter_v1p1beta1_keywords.py +++ b/scripts/fixup_securitycenter_v1p1beta1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index 48c1dc41..77673e83 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-securitycenter.git", - "sha": "316d224077ecb786e19444965e0e6cdc0195efc3" + "sha": "553dfbb89f7e72ad280aaa5d59cc4a054aa1948e" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "bda7ce951def5ae6e5c4258d0e569188dd4ae02b", - "internalRef": "336180475" + "sha": "e9135d3cb8a99f77ee2ba3318ebc2c9b807581d0", + "internalRef": "347410691" } }, { diff --git a/tests/unit/gapic/securitycenter_v1/test_security_center.py b/tests/unit/gapic/securitycenter_v1/test_security_center.py index 2cca9372..0553ce66 100644 --- a/tests/unit/gapic/securitycenter_v1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1/test_security_center.py @@ -123,12 +123,12 @@ def test_security_center_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "securitycenter.googleapis.com:443" + assert client.transport._host == "securitycenter.googleapis.com:443" def test_security_center_client_get_transport_class(): @@ -478,7 +478,7 @@ def test_create_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source( name="name_value", @@ -495,6 +495,7 @@ def test_create_source( assert args[0] == securitycenter_service.CreateSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_source.Source) assert response.name == "name_value" @@ -509,19 +510,20 @@ def test_create_source_from_dict(): @pytest.mark.asyncio -async def test_create_source_async(transport: str = "grpc_asyncio"): +async def test_create_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_source.Source( @@ -537,7 +539,7 @@ async def test_create_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_source.Source) @@ -549,6 +551,11 @@ async def test_create_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_create_source_async_from_dict(): + await test_create_source_async(request_type=dict) + + def test_create_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -558,7 +565,7 @@ def test_create_source_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: call.return_value = gcs_source.Source() client.create_source(request) @@ -583,9 +590,7 @@ async def test_create_source_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) await client.create_source(request) @@ -604,7 +609,7 @@ def test_create_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -642,9 +647,7 @@ async def test_create_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -691,7 +694,7 @@ def test_create_finding( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding( name="name_value", @@ -700,6 +703,7 @@ def test_create_finding( state=gcs_finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", + severity=gcs_finding.Finding.Severity.CRITICAL, ) response = client.create_finding(request) @@ -711,6 +715,7 @@ def test_create_finding( assert args[0] == securitycenter_service.CreateFindingRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" @@ -725,25 +730,28 @@ def test_create_finding( assert response.external_uri == "external_uri_value" + assert response.severity == gcs_finding.Finding.Severity.CRITICAL + def test_create_finding_from_dict(): test_create_finding(request_type=dict) @pytest.mark.asyncio -async def test_create_finding_async(transport: str = "grpc_asyncio"): +async def test_create_finding_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateFindingRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateFindingRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_finding.Finding( @@ -753,6 +761,7 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): state=gcs_finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", + severity=gcs_finding.Finding.Severity.CRITICAL, ) ) @@ -762,7 +771,7 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_finding.Finding) @@ -779,6 +788,13 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): assert response.external_uri == "external_uri_value" + assert response.severity == gcs_finding.Finding.Severity.CRITICAL + + +@pytest.mark.asyncio +async def test_create_finding_async_from_dict(): + await test_create_finding_async(request_type=dict) + def test_create_finding_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -789,7 +805,7 @@ def test_create_finding_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: call.return_value = gcs_finding.Finding() client.create_finding(request) @@ -814,9 +830,7 @@ async def test_create_finding_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) await client.create_finding(request) @@ -835,7 +849,7 @@ def test_create_finding_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -878,9 +892,7 @@ async def test_create_finding_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -934,7 +946,7 @@ def test_create_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig( @@ -956,6 +968,7 @@ def test_create_notification_config( assert args[0] == securitycenter_service.CreateNotificationConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_notification_config.NotificationConfig) assert response.name == "name_value" @@ -972,18 +985,21 @@ def test_create_notification_config_from_dict(): @pytest.mark.asyncio -async def test_create_notification_config_async(transport: str = "grpc_asyncio"): +async def test_create_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1001,7 +1017,7 @@ async def test_create_notification_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateNotificationConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_notification_config.NotificationConfig) @@ -1015,6 +1031,11 @@ async def test_create_notification_config_async(transport: str = "grpc_asyncio") assert response.service_account == "service_account_value" +@pytest.mark.asyncio +async def test_create_notification_config_async_from_dict(): + await test_create_notification_config_async(request_type=dict) + + def test_create_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1025,7 +1046,7 @@ def test_create_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: call.return_value = gcs_notification_config.NotificationConfig() @@ -1052,7 +1073,7 @@ async def test_create_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_notification_config.NotificationConfig() @@ -1075,7 +1096,7 @@ def test_create_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -1128,7 +1149,7 @@ async def test_create_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -1193,7 +1214,7 @@ def test_delete_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1215,18 +1236,21 @@ def test_delete_notification_config_from_dict(): @pytest.mark.asyncio -async def test_delete_notification_config_async(transport: str = "grpc_asyncio"): +async def test_delete_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.DeleteNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.DeleteNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1237,12 +1261,17 @@ async def test_delete_notification_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_notification_config_async_from_dict(): + await test_delete_notification_config_async(request_type=dict) + + def test_delete_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1253,7 +1282,7 @@ def test_delete_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: call.return_value = None @@ -1280,7 +1309,7 @@ async def test_delete_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1301,7 +1330,7 @@ def test_delete_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1335,7 +1364,7 @@ async def test_delete_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1377,7 +1406,7 @@ def test_get_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -1390,6 +1419,7 @@ def test_get_iam_policy( assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -1402,19 +1432,19 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_get_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.GetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -1426,7 +1456,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -1436,6 +1466,11 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) + + def test_get_iam_policy_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1445,7 +1480,7 @@ def test_get_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.get_iam_policy(request) @@ -1470,9 +1505,7 @@ async def test_get_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.get_iam_policy(request) @@ -1487,10 +1520,10 @@ async def test_get_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_get_iam_policy_from_dict(): +def test_get_iam_policy_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1507,7 +1540,7 @@ def test_get_iam_policy_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1539,9 +1572,7 @@ async def test_get_iam_policy_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1584,7 +1615,7 @@ def test_get_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_config.NotificationConfig( @@ -1606,6 +1637,7 @@ def test_get_notification_config( assert args[0] == securitycenter_service.GetNotificationConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification_config.NotificationConfig) assert response.name == "name_value" @@ -1622,18 +1654,21 @@ def test_get_notification_config_from_dict(): @pytest.mark.asyncio -async def test_get_notification_config_async(transport: str = "grpc_asyncio"): +async def test_get_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1651,7 +1686,7 @@ async def test_get_notification_config_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetNotificationConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification_config.NotificationConfig) @@ -1665,6 +1700,11 @@ async def test_get_notification_config_async(transport: str = "grpc_asyncio"): assert response.service_account == "service_account_value" +@pytest.mark.asyncio +async def test_get_notification_config_async_from_dict(): + await test_get_notification_config_async(request_type=dict) + + def test_get_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1675,7 +1715,7 @@ def test_get_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: call.return_value = notification_config.NotificationConfig() @@ -1702,7 +1742,7 @@ async def test_get_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification_config.NotificationConfig() @@ -1725,7 +1765,7 @@ def test_get_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_config.NotificationConfig() @@ -1759,7 +1799,7 @@ async def test_get_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_config.NotificationConfig() @@ -1805,7 +1845,7 @@ def test_get_organization_settings( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings( @@ -1821,6 +1861,7 @@ def test_get_organization_settings( assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, organization_settings.OrganizationSettings) assert response.name == "name_value" @@ -1833,18 +1874,21 @@ def test_get_organization_settings_from_dict(): @pytest.mark.asyncio -async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): +async def test_get_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetOrganizationSettingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetOrganizationSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1859,7 +1903,7 @@ async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, organization_settings.OrganizationSettings) @@ -1869,6 +1913,11 @@ async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): assert response.enable_asset_discovery is True +@pytest.mark.asyncio +async def test_get_organization_settings_async_from_dict(): + await test_get_organization_settings_async(request_type=dict) + + def test_get_organization_settings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1879,7 +1928,7 @@ def test_get_organization_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: call.return_value = organization_settings.OrganizationSettings() @@ -1906,7 +1955,7 @@ async def test_get_organization_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( organization_settings.OrganizationSettings() @@ -1929,7 +1978,7 @@ def test_get_organization_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings() @@ -1963,7 +2012,7 @@ async def test_get_organization_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings() @@ -2007,7 +2056,7 @@ def test_get_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source( name="name_value", @@ -2024,6 +2073,7 @@ def test_get_source( assert args[0] == securitycenter_service.GetSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, source.Source) assert response.name == "name_value" @@ -2038,19 +2088,20 @@ def test_get_source_from_dict(): @pytest.mark.asyncio -async def test_get_source_async(transport: str = "grpc_asyncio"): +async def test_get_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( source.Source( @@ -2066,7 +2117,7 @@ async def test_get_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, source.Source) @@ -2078,6 +2129,11 @@ async def test_get_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_get_source_async_from_dict(): + await test_get_source_async(request_type=dict) + + def test_get_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2087,7 +2143,7 @@ def test_get_source_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: call.return_value = source.Source() client.get_source(request) @@ -2112,9 +2168,7 @@ async def test_get_source_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) await client.get_source(request) @@ -2133,7 +2187,7 @@ def test_get_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source() @@ -2165,9 +2219,7 @@ async def test_get_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source() @@ -2208,7 +2260,7 @@ def test_group_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupAssetsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2223,6 +2275,7 @@ def test_group_assets( assert args[0] == securitycenter_service.GroupAssetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupAssetsPager) assert response.next_page_token == "next_page_token_value" @@ -2235,19 +2288,20 @@ def test_group_assets_from_dict(): @pytest.mark.asyncio -async def test_group_assets_async(transport: str = "grpc_asyncio"): +async def test_group_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupAssetsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GroupAssetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupAssetsResponse( @@ -2261,7 +2315,7 @@ async def test_group_assets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GroupAssetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.GroupAssetsAsyncPager) @@ -2271,6 +2325,11 @@ async def test_group_assets_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_group_assets_async_from_dict(): + await test_group_assets_async(request_type=dict) + + def test_group_assets_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2280,7 +2339,7 @@ def test_group_assets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: call.return_value = securitycenter_service.GroupAssetsResponse() client.group_assets(request) @@ -2305,9 +2364,7 @@ async def test_group_assets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupAssetsResponse() ) @@ -2328,7 +2385,7 @@ def test_group_assets_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupAssetsResponse( @@ -2372,7 +2429,7 @@ def test_group_assets_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupAssetsResponse( @@ -2409,9 +2466,7 @@ async def test_group_assets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2454,9 +2509,7 @@ async def test_group_assets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2502,7 +2555,7 @@ def test_group_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2517,6 +2570,7 @@ def test_group_findings( assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupFindingsPager) assert response.next_page_token == "next_page_token_value" @@ -2529,19 +2583,20 @@ def test_group_findings_from_dict(): @pytest.mark.asyncio -async def test_group_findings_async(transport: str = "grpc_asyncio"): +async def test_group_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupFindingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GroupFindingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupFindingsResponse( @@ -2555,7 +2610,7 @@ async def test_group_findings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.GroupFindingsAsyncPager) @@ -2565,6 +2620,11 @@ async def test_group_findings_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_group_findings_async_from_dict(): + await test_group_findings_async(request_type=dict) + + def test_group_findings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2574,7 +2634,7 @@ def test_group_findings_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = securitycenter_service.GroupFindingsResponse() client.group_findings(request) @@ -2599,9 +2659,7 @@ async def test_group_findings_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupFindingsResponse() ) @@ -2622,7 +2680,7 @@ def test_group_findings_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse() @@ -2660,9 +2718,7 @@ async def test_group_findings_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse() @@ -2703,7 +2759,7 @@ def test_group_findings_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupFindingsResponse( @@ -2747,7 +2803,7 @@ def test_group_findings_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupFindingsResponse( @@ -2784,9 +2840,7 @@ async def test_group_findings_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2829,9 +2883,7 @@ async def test_group_findings_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2877,7 +2929,7 @@ def test_list_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2892,6 +2944,7 @@ def test_list_assets( assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAssetsPager) assert response.next_page_token == "next_page_token_value" @@ -2904,19 +2957,20 @@ def test_list_assets_from_dict(): @pytest.mark.asyncio -async def test_list_assets_async(transport: str = "grpc_asyncio"): +async def test_list_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListAssetsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListAssetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListAssetsResponse( @@ -2930,7 +2984,7 @@ async def test_list_assets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAssetsAsyncPager) @@ -2940,6 +2994,11 @@ async def test_list_assets_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_assets_async_from_dict(): + await test_list_assets_async(request_type=dict) + + def test_list_assets_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2949,7 +3008,7 @@ def test_list_assets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = securitycenter_service.ListAssetsResponse() client.list_assets(request) @@ -2974,9 +3033,7 @@ async def test_list_assets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListAssetsResponse() ) @@ -2997,7 +3054,7 @@ def test_list_assets_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListAssetsResponse( @@ -3046,7 +3103,7 @@ def test_list_assets_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListAssetsResponse( @@ -3085,9 +3142,7 @@ async def test_list_assets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3135,9 +3190,7 @@ async def test_list_assets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3185,7 +3238,7 @@ def test_list_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -3200,6 +3253,7 @@ def test_list_findings( assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFindingsPager) assert response.next_page_token == "next_page_token_value" @@ -3212,19 +3266,20 @@ def test_list_findings_from_dict(): @pytest.mark.asyncio -async def test_list_findings_async(transport: str = "grpc_asyncio"): +async def test_list_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListFindingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListFindingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListFindingsResponse( @@ -3238,7 +3293,7 @@ async def test_list_findings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFindingsAsyncPager) @@ -3248,6 +3303,11 @@ async def test_list_findings_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_findings_async_from_dict(): + await test_list_findings_async(request_type=dict) + + def test_list_findings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3257,7 +3317,7 @@ def test_list_findings_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = securitycenter_service.ListFindingsResponse() client.list_findings(request) @@ -3282,9 +3342,7 @@ async def test_list_findings_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListFindingsResponse() ) @@ -3305,7 +3363,7 @@ def test_list_findings_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListFindingsResponse( @@ -3356,7 +3414,7 @@ def test_list_findings_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListFindingsResponse( @@ -3395,9 +3453,7 @@ async def test_list_findings_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3447,9 +3503,7 @@ async def test_list_findings_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3499,7 +3553,7 @@ def test_list_notification_configs( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListNotificationConfigsResponse( @@ -3515,6 +3569,7 @@ def test_list_notification_configs( assert args[0] == securitycenter_service.ListNotificationConfigsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListNotificationConfigsPager) assert response.next_page_token == "next_page_token_value" @@ -3525,18 +3580,21 @@ def test_list_notification_configs_from_dict(): @pytest.mark.asyncio -async def test_list_notification_configs_async(transport: str = "grpc_asyncio"): +async def test_list_notification_configs_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListNotificationConfigsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListNotificationConfigsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3551,7 +3609,7 @@ async def test_list_notification_configs_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListNotificationConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListNotificationConfigsAsyncPager) @@ -3559,6 +3617,11 @@ async def test_list_notification_configs_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_notification_configs_async_from_dict(): + await test_list_notification_configs_async(request_type=dict) + + def test_list_notification_configs_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3569,7 +3632,7 @@ def test_list_notification_configs_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: call.return_value = securitycenter_service.ListNotificationConfigsResponse() @@ -3596,7 +3659,7 @@ async def test_list_notification_configs_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListNotificationConfigsResponse() @@ -3619,7 +3682,7 @@ def test_list_notification_configs_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListNotificationConfigsResponse() @@ -3654,7 +3717,7 @@ async def test_list_notification_configs_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListNotificationConfigsResponse() @@ -3692,7 +3755,7 @@ def test_list_notification_configs_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3740,7 +3803,7 @@ def test_list_notification_configs_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3778,7 +3841,7 @@ async def test_list_notification_configs_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), + type(client.transport.list_notification_configs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -3825,7 +3888,7 @@ async def test_list_notification_configs_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), + type(client.transport.list_notification_configs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -3873,7 +3936,7 @@ def test_list_sources( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse( next_page_token="next_page_token_value", @@ -3888,6 +3951,7 @@ def test_list_sources( assert args[0] == securitycenter_service.ListSourcesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSourcesPager) assert response.next_page_token == "next_page_token_value" @@ -3898,19 +3962,20 @@ def test_list_sources_from_dict(): @pytest.mark.asyncio -async def test_list_sources_async(transport: str = "grpc_asyncio"): +async def test_list_sources_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListSourcesRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListSourcesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListSourcesResponse( @@ -3924,7 +3989,7 @@ async def test_list_sources_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListSourcesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListSourcesAsyncPager) @@ -3932,6 +3997,11 @@ async def test_list_sources_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_sources_async_from_dict(): + await test_list_sources_async(request_type=dict) + + def test_list_sources_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3941,7 +4011,7 @@ def test_list_sources_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: call.return_value = securitycenter_service.ListSourcesResponse() client.list_sources(request) @@ -3966,9 +4036,7 @@ async def test_list_sources_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListSourcesResponse() ) @@ -3989,7 +4057,7 @@ def test_list_sources_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse() @@ -4021,9 +4089,7 @@ async def test_list_sources_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse() @@ -4058,7 +4124,7 @@ def test_list_sources_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListSourcesResponse( @@ -4094,7 +4160,7 @@ def test_list_sources_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListSourcesResponse( @@ -4123,9 +4189,7 @@ async def test_list_sources_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_sources), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4160,9 +4224,7 @@ async def test_list_sources_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_sources), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4202,7 +4264,7 @@ def test_run_asset_discovery( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -4224,18 +4286,21 @@ def test_run_asset_discovery_from_dict(): @pytest.mark.asyncio -async def test_run_asset_discovery_async(transport: str = "grpc_asyncio"): +async def test_run_asset_discovery_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.RunAssetDiscoveryRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.RunAssetDiscoveryRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4248,12 +4313,17 @@ async def test_run_asset_discovery_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.RunAssetDiscoveryRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_run_asset_discovery_async_from_dict(): + await test_run_asset_discovery_async(request_type=dict) + + def test_run_asset_discovery_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4264,7 +4334,7 @@ def test_run_asset_discovery_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -4291,7 +4361,7 @@ async def test_run_asset_discovery_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -4314,7 +4384,7 @@ def test_run_asset_discovery_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -4348,7 +4418,7 @@ async def test_run_asset_discovery_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -4393,7 +4463,7 @@ def test_set_finding_state( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding( @@ -4403,6 +4473,7 @@ def test_set_finding_state( state=finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", + severity=finding.Finding.Severity.CRITICAL, ) response = client.set_finding_state(request) @@ -4414,6 +4485,7 @@ def test_set_finding_state( assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. + assert isinstance(response, finding.Finding) assert response.name == "name_value" @@ -4428,24 +4500,29 @@ def test_set_finding_state( assert response.external_uri == "external_uri_value" + assert response.severity == finding.Finding.Severity.CRITICAL + def test_set_finding_state_from_dict(): test_set_finding_state(request_type=dict) @pytest.mark.asyncio -async def test_set_finding_state_async(transport: str = "grpc_asyncio"): +async def test_set_finding_state_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.SetFindingStateRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.SetFindingStateRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4456,6 +4533,7 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): state=finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", + severity=finding.Finding.Severity.CRITICAL, ) ) @@ -4465,7 +4543,7 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) @@ -4482,6 +4560,13 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): assert response.external_uri == "external_uri_value" + assert response.severity == finding.Finding.Severity.CRITICAL + + +@pytest.mark.asyncio +async def test_set_finding_state_async_from_dict(): + await test_set_finding_state_async(request_type=dict) + def test_set_finding_state_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4493,7 +4578,7 @@ def test_set_finding_state_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: call.return_value = finding.Finding() @@ -4520,7 +4605,7 @@ async def test_set_finding_state_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) @@ -4541,7 +4626,7 @@ def test_set_finding_state_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() @@ -4588,7 +4673,7 @@ async def test_set_finding_state_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() @@ -4643,7 +4728,7 @@ def test_set_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -4656,6 +4741,7 @@ def test_set_iam_policy( assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -4668,19 +4754,19 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_set_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.SetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -4692,7 +4778,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -4702,6 +4788,11 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) + + def test_set_iam_policy_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4711,7 +4802,7 @@ def test_set_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.set_iam_policy(request) @@ -4736,9 +4827,7 @@ async def test_set_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.set_iam_policy(request) @@ -4753,10 +4842,10 @@ async def test_set_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_set_iam_policy_from_dict(): +def test_set_iam_policy_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4773,7 +4862,7 @@ def test_set_iam_policy_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4805,9 +4894,7 @@ async def test_set_iam_policy_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4849,7 +4936,7 @@ def test_test_iam_permissions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse( @@ -4865,6 +4952,7 @@ def test_test_iam_permissions( assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -4875,18 +4963,20 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio -async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): +async def test_test_iam_permissions_async( + transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.TestIamPermissionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4899,7 +4989,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, iam_policy.TestIamPermissionsResponse) @@ -4907,6 +4997,11 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert response.permissions == ["permissions_value"] +@pytest.mark.asyncio +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) + + def test_test_iam_permissions_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4917,7 +5012,7 @@ def test_test_iam_permissions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = iam_policy.TestIamPermissionsResponse() @@ -4944,7 +5039,7 @@ async def test_test_iam_permissions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( iam_policy.TestIamPermissionsResponse() @@ -4962,11 +5057,11 @@ async def test_test_iam_permissions_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_test_iam_permissions_from_dict(): +def test_test_iam_permissions_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -4985,7 +5080,7 @@ def test_test_iam_permissions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -5025,7 +5120,7 @@ async def test_test_iam_permissions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -5075,7 +5170,7 @@ def test_update_finding( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding( name="name_value", @@ -5084,6 +5179,7 @@ def test_update_finding( state=gcs_finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", + severity=gcs_finding.Finding.Severity.CRITICAL, ) response = client.update_finding(request) @@ -5095,6 +5191,7 @@ def test_update_finding( assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" @@ -5109,25 +5206,28 @@ def test_update_finding( assert response.external_uri == "external_uri_value" + assert response.severity == gcs_finding.Finding.Severity.CRITICAL + def test_update_finding_from_dict(): test_update_finding(request_type=dict) @pytest.mark.asyncio -async def test_update_finding_async(transport: str = "grpc_asyncio"): +async def test_update_finding_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateFindingRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateFindingRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_finding.Finding( @@ -5137,6 +5237,7 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): state=gcs_finding.Finding.State.ACTIVE, category="category_value", external_uri="external_uri_value", + severity=gcs_finding.Finding.Severity.CRITICAL, ) ) @@ -5146,7 +5247,7 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_finding.Finding) @@ -5163,6 +5264,13 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): assert response.external_uri == "external_uri_value" + assert response.severity == gcs_finding.Finding.Severity.CRITICAL + + +@pytest.mark.asyncio +async def test_update_finding_async_from_dict(): + await test_update_finding_async(request_type=dict) + def test_update_finding_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5173,7 +5281,7 @@ def test_update_finding_field_headers(): request.finding.name = "finding.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: call.return_value = gcs_finding.Finding() client.update_finding(request) @@ -5200,9 +5308,7 @@ async def test_update_finding_field_headers_async(): request.finding.name = "finding.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) await client.update_finding(request) @@ -5223,7 +5329,7 @@ def test_update_finding_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -5256,9 +5362,7 @@ async def test_update_finding_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -5304,7 +5408,7 @@ def test_update_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig( @@ -5326,6 +5430,7 @@ def test_update_notification_config( assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_notification_config.NotificationConfig) assert response.name == "name_value" @@ -5342,18 +5447,21 @@ def test_update_notification_config_from_dict(): @pytest.mark.asyncio -async def test_update_notification_config_async(transport: str = "grpc_asyncio"): +async def test_update_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5371,7 +5479,7 @@ async def test_update_notification_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_notification_config.NotificationConfig) @@ -5385,6 +5493,11 @@ async def test_update_notification_config_async(transport: str = "grpc_asyncio") assert response.service_account == "service_account_value" +@pytest.mark.asyncio +async def test_update_notification_config_async_from_dict(): + await test_update_notification_config_async(request_type=dict) + + def test_update_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5395,7 +5508,7 @@ def test_update_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: call.return_value = gcs_notification_config.NotificationConfig() @@ -5425,7 +5538,7 @@ async def test_update_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_notification_config.NotificationConfig() @@ -5451,7 +5564,7 @@ def test_update_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -5500,7 +5613,7 @@ async def test_update_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -5561,7 +5674,7 @@ def test_update_organization_settings( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings( @@ -5577,6 +5690,7 @@ def test_update_organization_settings( assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_organization_settings.OrganizationSettings) assert response.name == "name_value" @@ -5589,18 +5703,21 @@ def test_update_organization_settings_from_dict(): @pytest.mark.asyncio -async def test_update_organization_settings_async(transport: str = "grpc_asyncio"): +async def test_update_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateOrganizationSettingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateOrganizationSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5615,7 +5732,7 @@ async def test_update_organization_settings_async(transport: str = "grpc_asyncio assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_organization_settings.OrganizationSettings) @@ -5625,6 +5742,11 @@ async def test_update_organization_settings_async(transport: str = "grpc_asyncio assert response.enable_asset_discovery is True +@pytest.mark.asyncio +async def test_update_organization_settings_async_from_dict(): + await test_update_organization_settings_async(request_type=dict) + + def test_update_organization_settings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5635,7 +5757,7 @@ def test_update_organization_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: call.return_value = gcs_organization_settings.OrganizationSettings() @@ -5665,7 +5787,7 @@ async def test_update_organization_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_organization_settings.OrganizationSettings() @@ -5691,7 +5813,7 @@ def test_update_organization_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings() @@ -5736,7 +5858,7 @@ async def test_update_organization_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings() @@ -5791,7 +5913,7 @@ def test_update_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source( name="name_value", @@ -5808,6 +5930,7 @@ def test_update_source( assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_source.Source) assert response.name == "name_value" @@ -5822,19 +5945,20 @@ def test_update_source_from_dict(): @pytest.mark.asyncio -async def test_update_source_async(transport: str = "grpc_asyncio"): +async def test_update_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_source.Source( @@ -5850,7 +5974,7 @@ async def test_update_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_source.Source) @@ -5862,6 +5986,11 @@ async def test_update_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_update_source_async_from_dict(): + await test_update_source_async(request_type=dict) + + def test_update_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5871,7 +6000,7 @@ def test_update_source_field_headers(): request.source.name = "source.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: call.return_value = gcs_source.Source() client.update_source(request) @@ -5896,9 +6025,7 @@ async def test_update_source_field_headers_async(): request.source.name = "source.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) await client.update_source(request) @@ -5917,7 +6044,7 @@ def test_update_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -5950,9 +6077,7 @@ async def test_update_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -5998,7 +6123,7 @@ def test_update_security_marks( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks(name="name_value",) @@ -6012,6 +6137,7 @@ def test_update_security_marks( assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_security_marks.SecurityMarks) assert response.name == "name_value" @@ -6022,18 +6148,21 @@ def test_update_security_marks_from_dict(): @pytest.mark.asyncio -async def test_update_security_marks_async(transport: str = "grpc_asyncio"): +async def test_update_security_marks_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSecurityMarksRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateSecurityMarksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6046,7 +6175,7 @@ async def test_update_security_marks_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_security_marks.SecurityMarks) @@ -6054,6 +6183,11 @@ async def test_update_security_marks_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_update_security_marks_async_from_dict(): + await test_update_security_marks_async(request_type=dict) + + def test_update_security_marks_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -6064,7 +6198,7 @@ def test_update_security_marks_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: call.return_value = gcs_security_marks.SecurityMarks() @@ -6094,7 +6228,7 @@ async def test_update_security_marks_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_security_marks.SecurityMarks() @@ -6120,7 +6254,7 @@ def test_update_security_marks_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks() @@ -6159,7 +6293,7 @@ async def test_update_security_marks_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks() @@ -6232,7 +6366,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = SecurityCenterClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -6268,7 +6402,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.SecurityCenterGrpcTransport,) + assert isinstance(client.transport, transports.SecurityCenterGrpcTransport,) def test_security_center_base_transport_error(): @@ -6389,7 +6523,7 @@ def test_security_center_host_no_port(): api_endpoint="securitycenter.googleapis.com" ), ) - assert client._transport._host == "securitycenter.googleapis.com:443" + assert client.transport._host == "securitycenter.googleapis.com:443" def test_security_center_host_with_port(): @@ -6399,7 +6533,7 @@ def test_security_center_host_with_port(): api_endpoint="securitycenter.googleapis.com:8000" ), ) - assert client._transport._host == "securitycenter.googleapis.com:8000" + assert client.transport._host == "securitycenter.googleapis.com:8000" def test_security_center_grpc_transport_channel(): @@ -6411,6 +6545,7 @@ def test_security_center_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_security_center_grpc_asyncio_transport_channel(): @@ -6422,6 +6557,7 @@ def test_security_center_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -6467,8 +6603,13 @@ def test_security_center_transport_channel_mtls_with_client_cert_source( scopes=("https://www.googleapis.com/auth/cloud-platform",), 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 @pytest.mark.parametrize( @@ -6507,6 +6648,10 @@ def test_security_center_transport_channel_mtls_with_adc(transport_class): scopes=("https://www.googleapis.com/auth/cloud-platform",), 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 @@ -6515,7 +6660,7 @@ def test_security_center_grpc_lro_client(): client = SecurityCenterClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -6528,7 +6673,7 @@ def test_security_center_grpc_lro_async_client(): client = SecurityCenterAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -6537,10 +6682,33 @@ def test_security_center_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_finding_path(): +def test_asset_path(): organization = "squid" - source = "clam" - finding = "whelk" + asset = "clam" + + expected = "organizations/{organization}/assets/{asset}".format( + organization=organization, asset=asset, + ) + actual = SecurityCenterClient.asset_path(organization, asset) + assert expected == actual + + +def test_parse_asset_path(): + expected = { + "organization": "whelk", + "asset": "octopus", + } + path = SecurityCenterClient.asset_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_asset_path(path) + assert expected == actual + + +def test_finding_path(): + organization = "oyster" + source = "nudibranch" + finding = "cuttlefish" expected = "organizations/{organization}/sources/{source}/findings/{finding}".format( organization=organization, source=source, finding=finding, @@ -6551,9 +6719,9 @@ def test_finding_path(): def test_parse_finding_path(): expected = { - "organization": "octopus", - "source": "oyster", - "finding": "nudibranch", + "organization": "mussel", + "source": "winkle", + "finding": "nautilus", } path = SecurityCenterClient.finding_path(**expected) @@ -6563,8 +6731,8 @@ def test_parse_finding_path(): def test_notification_config_path(): - organization = "squid" - notification_config = "clam" + organization = "scallop" + notification_config = "abalone" expected = "organizations/{organization}/notificationConfigs/{notification_config}".format( organization=organization, notification_config=notification_config, @@ -6577,8 +6745,8 @@ def test_notification_config_path(): def test_parse_notification_config_path(): expected = { - "organization": "whelk", - "notification_config": "octopus", + "organization": "squid", + "notification_config": "clam", } path = SecurityCenterClient.notification_config_path(**expected) @@ -6588,7 +6756,7 @@ def test_parse_notification_config_path(): def test_organization_settings_path(): - organization = "squid" + organization = "whelk" expected = "organizations/{organization}/organizationSettings".format( organization=organization, @@ -6599,7 +6767,7 @@ def test_organization_settings_path(): def test_parse_organization_settings_path(): expected = { - "organization": "clam", + "organization": "octopus", } path = SecurityCenterClient.organization_settings_path(**expected) @@ -6609,8 +6777,8 @@ def test_parse_organization_settings_path(): def test_security_marks_path(): - organization = "squid" - asset = "clam" + organization = "oyster" + asset = "nudibranch" expected = "organizations/{organization}/assets/{asset}/securityMarks".format( organization=organization, asset=asset, @@ -6621,8 +6789,8 @@ def test_security_marks_path(): def test_parse_security_marks_path(): expected = { - "organization": "whelk", - "asset": "octopus", + "organization": "cuttlefish", + "asset": "mussel", } path = SecurityCenterClient.security_marks_path(**expected) @@ -6632,8 +6800,8 @@ def test_parse_security_marks_path(): def test_source_path(): - organization = "squid" - source = "clam" + organization = "winkle" + source = "nautilus" expected = "organizations/{organization}/sources/{source}".format( organization=organization, source=source, @@ -6644,8 +6812,8 @@ def test_source_path(): def test_parse_source_path(): expected = { - "organization": "whelk", - "source": "octopus", + "organization": "scallop", + "source": "abalone", } path = SecurityCenterClient.source_path(**expected) @@ -6654,6 +6822,128 @@ def test_parse_source_path(): assert expected == actual +def test_topic_path(): + project = "squid" + topic = "clam" + + expected = "projects/{project}/topics/{topic}".format(project=project, topic=topic,) + actual = SecurityCenterClient.topic_path(project, topic) + assert expected == actual + + +def test_parse_topic_path(): + expected = { + "project": "whelk", + "topic": "octopus", + } + path = SecurityCenterClient.topic_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_topic_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "oyster" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = SecurityCenterClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nudibranch", + } + path = SecurityCenterClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "cuttlefish" + + expected = "folders/{folder}".format(folder=folder,) + actual = SecurityCenterClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "mussel", + } + path = SecurityCenterClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "winkle" + + expected = "organizations/{organization}".format(organization=organization,) + actual = SecurityCenterClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nautilus", + } + path = SecurityCenterClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "scallop" + + expected = "projects/{project}".format(project=project,) + actual = SecurityCenterClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "abalone", + } + path = SecurityCenterClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.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 = SecurityCenterClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "whelk", + "location": "octopus", + } + path = SecurityCenterClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() diff --git a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py index 0f9c8bc0..fc005bf6 100644 --- a/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1beta1/test_security_center.py @@ -122,12 +122,12 @@ def test_security_center_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "securitycenter.googleapis.com:443" + assert client.transport._host == "securitycenter.googleapis.com:443" def test_security_center_client_get_transport_class(): @@ -477,7 +477,7 @@ def test_create_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source( name="name_value", @@ -494,6 +494,7 @@ def test_create_source( assert args[0] == securitycenter_service.CreateSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_source.Source) assert response.name == "name_value" @@ -508,19 +509,20 @@ def test_create_source_from_dict(): @pytest.mark.asyncio -async def test_create_source_async(transport: str = "grpc_asyncio"): +async def test_create_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_source.Source( @@ -536,7 +538,7 @@ async def test_create_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_source.Source) @@ -548,6 +550,11 @@ async def test_create_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_create_source_async_from_dict(): + await test_create_source_async(request_type=dict) + + def test_create_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -557,7 +564,7 @@ def test_create_source_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: call.return_value = gcs_source.Source() client.create_source(request) @@ -582,9 +589,7 @@ async def test_create_source_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) await client.create_source(request) @@ -603,7 +608,7 @@ def test_create_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -641,9 +646,7 @@ async def test_create_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -690,7 +693,7 @@ def test_create_finding( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding( name="name_value", @@ -710,6 +713,7 @@ def test_create_finding( assert args[0] == securitycenter_service.CreateFindingRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" @@ -730,19 +734,20 @@ def test_create_finding_from_dict(): @pytest.mark.asyncio -async def test_create_finding_async(transport: str = "grpc_asyncio"): +async def test_create_finding_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateFindingRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateFindingRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_finding.Finding( @@ -761,7 +766,7 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_finding.Finding) @@ -779,6 +784,11 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): assert response.external_uri == "external_uri_value" +@pytest.mark.asyncio +async def test_create_finding_async_from_dict(): + await test_create_finding_async(request_type=dict) + + def test_create_finding_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -788,7 +798,7 @@ def test_create_finding_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: call.return_value = gcs_finding.Finding() client.create_finding(request) @@ -813,9 +823,7 @@ async def test_create_finding_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) await client.create_finding(request) @@ -834,7 +842,7 @@ def test_create_finding_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -877,9 +885,7 @@ async def test_create_finding_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -931,7 +937,7 @@ def test_get_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -944,6 +950,7 @@ def test_get_iam_policy( assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -956,19 +963,19 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_get_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.GetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -980,7 +987,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -990,6 +997,11 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) + + def test_get_iam_policy_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -999,7 +1011,7 @@ def test_get_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.get_iam_policy(request) @@ -1024,9 +1036,7 @@ async def test_get_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.get_iam_policy(request) @@ -1041,10 +1051,10 @@ async def test_get_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_get_iam_policy_from_dict(): +def test_get_iam_policy_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1061,7 +1071,7 @@ def test_get_iam_policy_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1093,9 +1103,7 @@ async def test_get_iam_policy_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1138,7 +1146,7 @@ def test_get_organization_settings( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings( @@ -1154,6 +1162,7 @@ def test_get_organization_settings( assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, organization_settings.OrganizationSettings) assert response.name == "name_value" @@ -1166,18 +1175,21 @@ def test_get_organization_settings_from_dict(): @pytest.mark.asyncio -async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): +async def test_get_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetOrganizationSettingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetOrganizationSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1192,7 +1204,7 @@ async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, organization_settings.OrganizationSettings) @@ -1202,6 +1214,11 @@ async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): assert response.enable_asset_discovery is True +@pytest.mark.asyncio +async def test_get_organization_settings_async_from_dict(): + await test_get_organization_settings_async(request_type=dict) + + def test_get_organization_settings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1212,7 +1229,7 @@ def test_get_organization_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: call.return_value = organization_settings.OrganizationSettings() @@ -1239,7 +1256,7 @@ async def test_get_organization_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( organization_settings.OrganizationSettings() @@ -1262,7 +1279,7 @@ def test_get_organization_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings() @@ -1296,7 +1313,7 @@ async def test_get_organization_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings() @@ -1340,7 +1357,7 @@ def test_get_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source( name="name_value", @@ -1357,6 +1374,7 @@ def test_get_source( assert args[0] == securitycenter_service.GetSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, source.Source) assert response.name == "name_value" @@ -1371,19 +1389,20 @@ def test_get_source_from_dict(): @pytest.mark.asyncio -async def test_get_source_async(transport: str = "grpc_asyncio"): +async def test_get_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( source.Source( @@ -1399,7 +1418,7 @@ async def test_get_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, source.Source) @@ -1411,6 +1430,11 @@ async def test_get_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_get_source_async_from_dict(): + await test_get_source_async(request_type=dict) + + def test_get_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1420,7 +1444,7 @@ def test_get_source_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: call.return_value = source.Source() client.get_source(request) @@ -1445,9 +1469,7 @@ async def test_get_source_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) await client.get_source(request) @@ -1466,7 +1488,7 @@ def test_get_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source() @@ -1498,9 +1520,7 @@ async def test_get_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source() @@ -1541,7 +1561,7 @@ def test_group_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupAssetsResponse( next_page_token="next_page_token_value", @@ -1556,6 +1576,7 @@ def test_group_assets( assert args[0] == securitycenter_service.GroupAssetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupAssetsPager) assert response.next_page_token == "next_page_token_value" @@ -1566,19 +1587,20 @@ def test_group_assets_from_dict(): @pytest.mark.asyncio -async def test_group_assets_async(transport: str = "grpc_asyncio"): +async def test_group_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupAssetsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GroupAssetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupAssetsResponse( @@ -1592,7 +1614,7 @@ async def test_group_assets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GroupAssetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.GroupAssetsAsyncPager) @@ -1600,6 +1622,11 @@ async def test_group_assets_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_group_assets_async_from_dict(): + await test_group_assets_async(request_type=dict) + + def test_group_assets_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1609,7 +1636,7 @@ def test_group_assets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: call.return_value = securitycenter_service.GroupAssetsResponse() client.group_assets(request) @@ -1634,9 +1661,7 @@ async def test_group_assets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupAssetsResponse() ) @@ -1657,7 +1682,7 @@ def test_group_assets_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupAssetsResponse( @@ -1701,7 +1726,7 @@ def test_group_assets_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupAssetsResponse( @@ -1738,9 +1763,7 @@ async def test_group_assets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1783,9 +1806,7 @@ async def test_group_assets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -1831,7 +1852,7 @@ def test_group_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse( next_page_token="next_page_token_value", @@ -1846,6 +1867,7 @@ def test_group_findings( assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupFindingsPager) assert response.next_page_token == "next_page_token_value" @@ -1856,19 +1878,20 @@ def test_group_findings_from_dict(): @pytest.mark.asyncio -async def test_group_findings_async(transport: str = "grpc_asyncio"): +async def test_group_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupFindingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GroupFindingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupFindingsResponse( @@ -1882,7 +1905,7 @@ async def test_group_findings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.GroupFindingsAsyncPager) @@ -1890,6 +1913,11 @@ async def test_group_findings_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_group_findings_async_from_dict(): + await test_group_findings_async(request_type=dict) + + def test_group_findings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1899,7 +1927,7 @@ def test_group_findings_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = securitycenter_service.GroupFindingsResponse() client.group_findings(request) @@ -1924,9 +1952,7 @@ async def test_group_findings_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupFindingsResponse() ) @@ -1947,7 +1973,7 @@ def test_group_findings_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse() @@ -1985,9 +2011,7 @@ async def test_group_findings_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse() @@ -2028,7 +2052,7 @@ def test_group_findings_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupFindingsResponse( @@ -2072,7 +2096,7 @@ def test_group_findings_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupFindingsResponse( @@ -2109,9 +2133,7 @@ async def test_group_findings_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2154,9 +2176,7 @@ async def test_group_findings_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2202,7 +2222,7 @@ def test_list_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2217,6 +2237,7 @@ def test_list_assets( assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAssetsPager) assert response.next_page_token == "next_page_token_value" @@ -2229,19 +2250,20 @@ def test_list_assets_from_dict(): @pytest.mark.asyncio -async def test_list_assets_async(transport: str = "grpc_asyncio"): +async def test_list_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListAssetsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListAssetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListAssetsResponse( @@ -2255,7 +2277,7 @@ async def test_list_assets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAssetsAsyncPager) @@ -2265,6 +2287,11 @@ async def test_list_assets_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_assets_async_from_dict(): + await test_list_assets_async(request_type=dict) + + def test_list_assets_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2274,7 +2301,7 @@ def test_list_assets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = securitycenter_service.ListAssetsResponse() client.list_assets(request) @@ -2299,9 +2326,7 @@ async def test_list_assets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListAssetsResponse() ) @@ -2322,7 +2347,7 @@ def test_list_assets_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListAssetsResponse( @@ -2371,7 +2396,7 @@ def test_list_assets_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListAssetsResponse( @@ -2410,9 +2435,7 @@ async def test_list_assets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2460,9 +2483,7 @@ async def test_list_assets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2510,7 +2531,7 @@ def test_list_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2525,6 +2546,7 @@ def test_list_findings( assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFindingsPager) assert response.next_page_token == "next_page_token_value" @@ -2537,19 +2559,20 @@ def test_list_findings_from_dict(): @pytest.mark.asyncio -async def test_list_findings_async(transport: str = "grpc_asyncio"): +async def test_list_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListFindingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListFindingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListFindingsResponse( @@ -2563,7 +2586,7 @@ async def test_list_findings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFindingsAsyncPager) @@ -2573,6 +2596,11 @@ async def test_list_findings_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_findings_async_from_dict(): + await test_list_findings_async(request_type=dict) + + def test_list_findings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2582,7 +2610,7 @@ def test_list_findings_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = securitycenter_service.ListFindingsResponse() client.list_findings(request) @@ -2607,9 +2635,7 @@ async def test_list_findings_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListFindingsResponse() ) @@ -2630,7 +2656,7 @@ def test_list_findings_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListFindingsResponse( @@ -2666,7 +2692,7 @@ def test_list_findings_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListFindingsResponse( @@ -2695,9 +2721,7 @@ async def test_list_findings_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2732,9 +2756,7 @@ async def test_list_findings_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2772,7 +2794,7 @@ def test_list_sources( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse( next_page_token="next_page_token_value", @@ -2787,6 +2809,7 @@ def test_list_sources( assert args[0] == securitycenter_service.ListSourcesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSourcesPager) assert response.next_page_token == "next_page_token_value" @@ -2797,19 +2820,20 @@ def test_list_sources_from_dict(): @pytest.mark.asyncio -async def test_list_sources_async(transport: str = "grpc_asyncio"): +async def test_list_sources_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListSourcesRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListSourcesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListSourcesResponse( @@ -2823,7 +2847,7 @@ async def test_list_sources_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListSourcesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListSourcesAsyncPager) @@ -2831,6 +2855,11 @@ async def test_list_sources_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_sources_async_from_dict(): + await test_list_sources_async(request_type=dict) + + def test_list_sources_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2840,7 +2869,7 @@ def test_list_sources_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: call.return_value = securitycenter_service.ListSourcesResponse() client.list_sources(request) @@ -2865,9 +2894,7 @@ async def test_list_sources_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListSourcesResponse() ) @@ -2888,7 +2915,7 @@ def test_list_sources_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse() @@ -2920,9 +2947,7 @@ async def test_list_sources_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse() @@ -2957,7 +2982,7 @@ def test_list_sources_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListSourcesResponse( @@ -2993,7 +3018,7 @@ def test_list_sources_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListSourcesResponse( @@ -3022,9 +3047,7 @@ async def test_list_sources_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_sources), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3059,9 +3082,7 @@ async def test_list_sources_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_sources), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3101,7 +3122,7 @@ def test_run_asset_discovery( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -3123,18 +3144,21 @@ def test_run_asset_discovery_from_dict(): @pytest.mark.asyncio -async def test_run_asset_discovery_async(transport: str = "grpc_asyncio"): +async def test_run_asset_discovery_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.RunAssetDiscoveryRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.RunAssetDiscoveryRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3147,12 +3171,17 @@ async def test_run_asset_discovery_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.RunAssetDiscoveryRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_run_asset_discovery_async_from_dict(): + await test_run_asset_discovery_async(request_type=dict) + + def test_run_asset_discovery_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3163,7 +3192,7 @@ def test_run_asset_discovery_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -3190,7 +3219,7 @@ async def test_run_asset_discovery_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -3213,7 +3242,7 @@ def test_run_asset_discovery_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3247,7 +3276,7 @@ async def test_run_asset_discovery_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -3292,7 +3321,7 @@ def test_set_finding_state( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding( @@ -3313,6 +3342,7 @@ def test_set_finding_state( assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. + assert isinstance(response, finding.Finding) assert response.name == "name_value" @@ -3333,18 +3363,21 @@ def test_set_finding_state_from_dict(): @pytest.mark.asyncio -async def test_set_finding_state_async(transport: str = "grpc_asyncio"): +async def test_set_finding_state_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.SetFindingStateRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.SetFindingStateRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3364,7 +3397,7 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) @@ -3382,6 +3415,11 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): assert response.external_uri == "external_uri_value" +@pytest.mark.asyncio +async def test_set_finding_state_async_from_dict(): + await test_set_finding_state_async(request_type=dict) + + def test_set_finding_state_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3392,7 +3430,7 @@ def test_set_finding_state_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: call.return_value = finding.Finding() @@ -3419,7 +3457,7 @@ async def test_set_finding_state_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) @@ -3440,7 +3478,7 @@ def test_set_finding_state_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() @@ -3487,7 +3525,7 @@ async def test_set_finding_state_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() @@ -3542,7 +3580,7 @@ def test_set_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -3555,6 +3593,7 @@ def test_set_iam_policy( assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -3567,19 +3606,19 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_set_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.SetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -3591,7 +3630,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -3601,6 +3640,11 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) + + def test_set_iam_policy_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3610,7 +3654,7 @@ def test_set_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.set_iam_policy(request) @@ -3635,9 +3679,7 @@ async def test_set_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.set_iam_policy(request) @@ -3652,10 +3694,10 @@ async def test_set_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_set_iam_policy_from_dict(): +def test_set_iam_policy_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -3672,7 +3714,7 @@ def test_set_iam_policy_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -3704,9 +3746,7 @@ async def test_set_iam_policy_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -3748,7 +3788,7 @@ def test_test_iam_permissions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse( @@ -3764,6 +3804,7 @@ def test_test_iam_permissions( assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -3774,18 +3815,20 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio -async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): +async def test_test_iam_permissions_async( + transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.TestIamPermissionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3798,7 +3841,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, iam_policy.TestIamPermissionsResponse) @@ -3806,6 +3849,11 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert response.permissions == ["permissions_value"] +@pytest.mark.asyncio +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) + + def test_test_iam_permissions_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3816,7 +3864,7 @@ def test_test_iam_permissions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = iam_policy.TestIamPermissionsResponse() @@ -3843,7 +3891,7 @@ async def test_test_iam_permissions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( iam_policy.TestIamPermissionsResponse() @@ -3861,11 +3909,11 @@ async def test_test_iam_permissions_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_test_iam_permissions_from_dict(): +def test_test_iam_permissions_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -3884,7 +3932,7 @@ def test_test_iam_permissions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -3924,7 +3972,7 @@ async def test_test_iam_permissions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -3974,7 +4022,7 @@ def test_update_finding( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding( name="name_value", @@ -3994,6 +4042,7 @@ def test_update_finding( assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" @@ -4014,19 +4063,20 @@ def test_update_finding_from_dict(): @pytest.mark.asyncio -async def test_update_finding_async(transport: str = "grpc_asyncio"): +async def test_update_finding_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateFindingRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateFindingRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_finding.Finding( @@ -4045,7 +4095,7 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_finding.Finding) @@ -4063,6 +4113,11 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): assert response.external_uri == "external_uri_value" +@pytest.mark.asyncio +async def test_update_finding_async_from_dict(): + await test_update_finding_async(request_type=dict) + + def test_update_finding_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4072,7 +4127,7 @@ def test_update_finding_field_headers(): request.finding.name = "finding.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: call.return_value = gcs_finding.Finding() client.update_finding(request) @@ -4099,9 +4154,7 @@ async def test_update_finding_field_headers_async(): request.finding.name = "finding.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) await client.update_finding(request) @@ -4122,7 +4175,7 @@ def test_update_finding_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -4155,9 +4208,7 @@ async def test_update_finding_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -4203,7 +4254,7 @@ def test_update_organization_settings( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings( @@ -4219,6 +4270,7 @@ def test_update_organization_settings( assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_organization_settings.OrganizationSettings) assert response.name == "name_value" @@ -4231,18 +4283,21 @@ def test_update_organization_settings_from_dict(): @pytest.mark.asyncio -async def test_update_organization_settings_async(transport: str = "grpc_asyncio"): +async def test_update_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateOrganizationSettingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateOrganizationSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4257,7 +4312,7 @@ async def test_update_organization_settings_async(transport: str = "grpc_asyncio assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_organization_settings.OrganizationSettings) @@ -4267,6 +4322,11 @@ async def test_update_organization_settings_async(transport: str = "grpc_asyncio assert response.enable_asset_discovery is True +@pytest.mark.asyncio +async def test_update_organization_settings_async_from_dict(): + await test_update_organization_settings_async(request_type=dict) + + def test_update_organization_settings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4277,7 +4337,7 @@ def test_update_organization_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: call.return_value = gcs_organization_settings.OrganizationSettings() @@ -4307,7 +4367,7 @@ async def test_update_organization_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_organization_settings.OrganizationSettings() @@ -4333,7 +4393,7 @@ def test_update_organization_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings() @@ -4378,7 +4438,7 @@ async def test_update_organization_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings() @@ -4433,7 +4493,7 @@ def test_update_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source( name="name_value", @@ -4450,6 +4510,7 @@ def test_update_source( assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_source.Source) assert response.name == "name_value" @@ -4464,19 +4525,20 @@ def test_update_source_from_dict(): @pytest.mark.asyncio -async def test_update_source_async(transport: str = "grpc_asyncio"): +async def test_update_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_source.Source( @@ -4492,7 +4554,7 @@ async def test_update_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_source.Source) @@ -4504,6 +4566,11 @@ async def test_update_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_update_source_async_from_dict(): + await test_update_source_async(request_type=dict) + + def test_update_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4513,7 +4580,7 @@ def test_update_source_field_headers(): request.source.name = "source.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: call.return_value = gcs_source.Source() client.update_source(request) @@ -4538,9 +4605,7 @@ async def test_update_source_field_headers_async(): request.source.name = "source.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) await client.update_source(request) @@ -4559,7 +4624,7 @@ def test_update_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -4592,9 +4657,7 @@ async def test_update_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -4640,7 +4703,7 @@ def test_update_security_marks( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks(name="name_value",) @@ -4654,6 +4717,7 @@ def test_update_security_marks( assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_security_marks.SecurityMarks) assert response.name == "name_value" @@ -4664,18 +4728,21 @@ def test_update_security_marks_from_dict(): @pytest.mark.asyncio -async def test_update_security_marks_async(transport: str = "grpc_asyncio"): +async def test_update_security_marks_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSecurityMarksRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateSecurityMarksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4688,7 +4755,7 @@ async def test_update_security_marks_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_security_marks.SecurityMarks) @@ -4696,6 +4763,11 @@ async def test_update_security_marks_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_update_security_marks_async_from_dict(): + await test_update_security_marks_async(request_type=dict) + + def test_update_security_marks_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4706,7 +4778,7 @@ def test_update_security_marks_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: call.return_value = gcs_security_marks.SecurityMarks() @@ -4736,7 +4808,7 @@ async def test_update_security_marks_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_security_marks.SecurityMarks() @@ -4762,7 +4834,7 @@ def test_update_security_marks_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks() @@ -4801,7 +4873,7 @@ async def test_update_security_marks_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks() @@ -4874,7 +4946,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = SecurityCenterClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -4910,7 +4982,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.SecurityCenterGrpcTransport,) + assert isinstance(client.transport, transports.SecurityCenterGrpcTransport,) def test_security_center_base_transport_error(): @@ -5026,7 +5098,7 @@ def test_security_center_host_no_port(): api_endpoint="securitycenter.googleapis.com" ), ) - assert client._transport._host == "securitycenter.googleapis.com:443" + assert client.transport._host == "securitycenter.googleapis.com:443" def test_security_center_host_with_port(): @@ -5036,7 +5108,7 @@ def test_security_center_host_with_port(): api_endpoint="securitycenter.googleapis.com:8000" ), ) - assert client._transport._host == "securitycenter.googleapis.com:8000" + assert client.transport._host == "securitycenter.googleapis.com:8000" def test_security_center_grpc_transport_channel(): @@ -5048,6 +5120,7 @@ def test_security_center_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_security_center_grpc_asyncio_transport_channel(): @@ -5059,6 +5132,7 @@ def test_security_center_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -5104,8 +5178,13 @@ def test_security_center_transport_channel_mtls_with_client_cert_source( scopes=("https://www.googleapis.com/auth/cloud-platform",), 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 @pytest.mark.parametrize( @@ -5144,6 +5223,10 @@ def test_security_center_transport_channel_mtls_with_adc(transport_class): scopes=("https://www.googleapis.com/auth/cloud-platform",), 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 @@ -5152,7 +5235,7 @@ def test_security_center_grpc_lro_client(): client = SecurityCenterClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -5165,7 +5248,7 @@ def test_security_center_grpc_lro_async_client(): client = SecurityCenterAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -5174,10 +5257,33 @@ def test_security_center_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_finding_path(): +def test_asset_path(): organization = "squid" - source = "clam" - finding = "whelk" + asset = "clam" + + expected = "organizations/{organization}/assets/{asset}".format( + organization=organization, asset=asset, + ) + actual = SecurityCenterClient.asset_path(organization, asset) + assert expected == actual + + +def test_parse_asset_path(): + expected = { + "organization": "whelk", + "asset": "octopus", + } + path = SecurityCenterClient.asset_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_asset_path(path) + assert expected == actual + + +def test_finding_path(): + organization = "oyster" + source = "nudibranch" + finding = "cuttlefish" expected = "organizations/{organization}/sources/{source}/findings/{finding}".format( organization=organization, source=source, finding=finding, @@ -5188,9 +5294,9 @@ def test_finding_path(): def test_parse_finding_path(): expected = { - "organization": "octopus", - "source": "oyster", - "finding": "nudibranch", + "organization": "mussel", + "source": "winkle", + "finding": "nautilus", } path = SecurityCenterClient.finding_path(**expected) @@ -5200,7 +5306,7 @@ def test_parse_finding_path(): def test_organization_settings_path(): - organization = "squid" + organization = "scallop" expected = "organizations/{organization}/organizationSettings".format( organization=organization, @@ -5211,7 +5317,7 @@ def test_organization_settings_path(): def test_parse_organization_settings_path(): expected = { - "organization": "clam", + "organization": "abalone", } path = SecurityCenterClient.organization_settings_path(**expected) @@ -5244,8 +5350,8 @@ def test_parse_security_marks_path(): def test_source_path(): - organization = "squid" - source = "clam" + organization = "oyster" + source = "nudibranch" expected = "organizations/{organization}/sources/{source}".format( organization=organization, source=source, @@ -5256,8 +5362,8 @@ def test_source_path(): def test_parse_source_path(): expected = { - "organization": "whelk", - "source": "octopus", + "organization": "cuttlefish", + "source": "mussel", } path = SecurityCenterClient.source_path(**expected) @@ -5266,6 +5372,107 @@ def test_parse_source_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "winkle" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = SecurityCenterClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = SecurityCenterClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "scallop" + + expected = "folders/{folder}".format(folder=folder,) + actual = SecurityCenterClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = SecurityCenterClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "squid" + + expected = "organizations/{organization}".format(organization=organization,) + actual = SecurityCenterClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = SecurityCenterClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "whelk" + + expected = "projects/{project}".format(project=project,) + actual = SecurityCenterClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = SecurityCenterClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.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 = SecurityCenterClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = SecurityCenterClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() diff --git a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py index 674123ab..ecc8ecb0 100644 --- a/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py +++ b/tests/unit/gapic/securitycenter_v1p1beta1/test_security_center.py @@ -127,12 +127,12 @@ def test_security_center_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "securitycenter.googleapis.com:443" + assert client.transport._host == "securitycenter.googleapis.com:443" def test_security_center_client_get_transport_class(): @@ -482,7 +482,7 @@ def test_create_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source( name="name_value", @@ -499,6 +499,7 @@ def test_create_source( assert args[0] == securitycenter_service.CreateSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_source.Source) assert response.name == "name_value" @@ -513,19 +514,20 @@ def test_create_source_from_dict(): @pytest.mark.asyncio -async def test_create_source_async(transport: str = "grpc_asyncio"): +async def test_create_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_source.Source( @@ -541,7 +543,7 @@ async def test_create_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_source.Source) @@ -553,6 +555,11 @@ async def test_create_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_create_source_async_from_dict(): + await test_create_source_async(request_type=dict) + + def test_create_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -562,7 +569,7 @@ def test_create_source_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: call.return_value = gcs_source.Source() client.create_source(request) @@ -587,9 +594,7 @@ async def test_create_source_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) await client.create_source(request) @@ -608,7 +613,7 @@ def test_create_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_source), "__call__") as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -646,9 +651,7 @@ async def test_create_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -695,7 +698,7 @@ def test_create_finding( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding( name="name_value", @@ -716,6 +719,7 @@ def test_create_finding( assert args[0] == securitycenter_service.CreateFindingRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" @@ -738,19 +742,20 @@ def test_create_finding_from_dict(): @pytest.mark.asyncio -async def test_create_finding_async(transport: str = "grpc_asyncio"): +async def test_create_finding_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateFindingRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateFindingRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_finding.Finding( @@ -770,7 +775,7 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_finding.Finding) @@ -790,6 +795,11 @@ async def test_create_finding_async(transport: str = "grpc_asyncio"): assert response.severity == gcs_finding.Finding.Severity.CRITICAL +@pytest.mark.asyncio +async def test_create_finding_async_from_dict(): + await test_create_finding_async(request_type=dict) + + def test_create_finding_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -799,7 +809,7 @@ def test_create_finding_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: call.return_value = gcs_finding.Finding() client.create_finding(request) @@ -824,9 +834,7 @@ async def test_create_finding_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) await client.create_finding(request) @@ -845,7 +853,7 @@ def test_create_finding_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_finding), "__call__") as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -888,9 +896,7 @@ async def test_create_finding_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -944,7 +950,7 @@ def test_create_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig( @@ -967,6 +973,7 @@ def test_create_notification_config( assert args[0] == securitycenter_service.CreateNotificationConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_notification_config.NotificationConfig) assert response.name == "name_value" @@ -988,18 +995,21 @@ def test_create_notification_config_from_dict(): @pytest.mark.asyncio -async def test_create_notification_config_async(transport: str = "grpc_asyncio"): +async def test_create_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.CreateNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.CreateNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1018,7 +1028,7 @@ async def test_create_notification_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.CreateNotificationConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_notification_config.NotificationConfig) @@ -1037,6 +1047,11 @@ async def test_create_notification_config_async(transport: str = "grpc_asyncio") assert response.service_account == "service_account_value" +@pytest.mark.asyncio +async def test_create_notification_config_async_from_dict(): + await test_create_notification_config_async(request_type=dict) + + def test_create_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1047,7 +1062,7 @@ def test_create_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: call.return_value = gcs_notification_config.NotificationConfig() @@ -1074,7 +1089,7 @@ async def test_create_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_notification_config.NotificationConfig() @@ -1097,7 +1112,7 @@ def test_create_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -1150,7 +1165,7 @@ async def test_create_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.create_notification_config), "__call__" + type(client.transport.create_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -1215,7 +1230,7 @@ def test_delete_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1237,18 +1252,21 @@ def test_delete_notification_config_from_dict(): @pytest.mark.asyncio -async def test_delete_notification_config_async(transport: str = "grpc_asyncio"): +async def test_delete_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.DeleteNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.DeleteNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1259,12 +1277,17 @@ async def test_delete_notification_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.DeleteNotificationConfigRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_notification_config_async_from_dict(): + await test_delete_notification_config_async(request_type=dict) + + def test_delete_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1275,7 +1298,7 @@ def test_delete_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: call.return_value = None @@ -1302,7 +1325,7 @@ async def test_delete_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1323,7 +1346,7 @@ def test_delete_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1357,7 +1380,7 @@ async def test_delete_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.delete_notification_config), "__call__" + type(client.transport.delete_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1399,7 +1422,7 @@ def test_get_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -1412,6 +1435,7 @@ def test_get_iam_policy( assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -1424,19 +1448,19 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_get_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.GetIamPolicyRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.GetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -1448,7 +1472,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.GetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -1458,6 +1482,11 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) + + def test_get_iam_policy_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1467,7 +1496,7 @@ def test_get_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.get_iam_policy(request) @@ -1492,9 +1521,7 @@ async def test_get_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.get_iam_policy(request) @@ -1509,10 +1536,10 @@ async def test_get_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_get_iam_policy_from_dict(): +def test_get_iam_policy_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1529,7 +1556,7 @@ def test_get_iam_policy_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1561,9 +1588,7 @@ async def test_get_iam_policy_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -1606,7 +1631,7 @@ def test_get_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_config.NotificationConfig( @@ -1629,6 +1654,7 @@ def test_get_notification_config( assert args[0] == securitycenter_service.GetNotificationConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, notification_config.NotificationConfig) assert response.name == "name_value" @@ -1649,18 +1675,21 @@ def test_get_notification_config_from_dict(): @pytest.mark.asyncio -async def test_get_notification_config_async(transport: str = "grpc_asyncio"): +async def test_get_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1679,7 +1708,7 @@ async def test_get_notification_config_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetNotificationConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, notification_config.NotificationConfig) @@ -1697,6 +1726,11 @@ async def test_get_notification_config_async(transport: str = "grpc_asyncio"): assert response.service_account == "service_account_value" +@pytest.mark.asyncio +async def test_get_notification_config_async_from_dict(): + await test_get_notification_config_async(request_type=dict) + + def test_get_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1707,7 +1741,7 @@ def test_get_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: call.return_value = notification_config.NotificationConfig() @@ -1734,7 +1768,7 @@ async def test_get_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( notification_config.NotificationConfig() @@ -1757,7 +1791,7 @@ def test_get_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_config.NotificationConfig() @@ -1791,7 +1825,7 @@ async def test_get_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_notification_config), "__call__" + type(client.transport.get_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = notification_config.NotificationConfig() @@ -1837,7 +1871,7 @@ def test_get_organization_settings( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings( @@ -1853,6 +1887,7 @@ def test_get_organization_settings( assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, organization_settings.OrganizationSettings) assert response.name == "name_value" @@ -1865,18 +1900,21 @@ def test_get_organization_settings_from_dict(): @pytest.mark.asyncio -async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): +async def test_get_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetOrganizationSettingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetOrganizationSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1891,7 +1929,7 @@ async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetOrganizationSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, organization_settings.OrganizationSettings) @@ -1901,6 +1939,11 @@ async def test_get_organization_settings_async(transport: str = "grpc_asyncio"): assert response.enable_asset_discovery is True +@pytest.mark.asyncio +async def test_get_organization_settings_async_from_dict(): + await test_get_organization_settings_async(request_type=dict) + + def test_get_organization_settings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -1911,7 +1954,7 @@ def test_get_organization_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: call.return_value = organization_settings.OrganizationSettings() @@ -1938,7 +1981,7 @@ async def test_get_organization_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( organization_settings.OrganizationSettings() @@ -1961,7 +2004,7 @@ def test_get_organization_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings() @@ -1995,7 +2038,7 @@ async def test_get_organization_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.get_organization_settings), "__call__" + type(client.transport.get_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = organization_settings.OrganizationSettings() @@ -2039,7 +2082,7 @@ def test_get_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source( name="name_value", @@ -2056,6 +2099,7 @@ def test_get_source( assert args[0] == securitycenter_service.GetSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, source.Source) assert response.name == "name_value" @@ -2070,19 +2114,20 @@ def test_get_source_from_dict(): @pytest.mark.asyncio -async def test_get_source_async(transport: str = "grpc_asyncio"): +async def test_get_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GetSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GetSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( source.Source( @@ -2098,7 +2143,7 @@ async def test_get_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GetSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, source.Source) @@ -2110,6 +2155,11 @@ async def test_get_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_get_source_async_from_dict(): + await test_get_source_async(request_type=dict) + + def test_get_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2119,7 +2169,7 @@ def test_get_source_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: call.return_value = source.Source() client.get_source(request) @@ -2144,9 +2194,7 @@ async def test_get_source_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(source.Source()) await client.get_source(request) @@ -2165,7 +2213,7 @@ def test_get_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_source), "__call__") as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source() @@ -2197,9 +2245,7 @@ async def test_get_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = source.Source() @@ -2240,7 +2286,7 @@ def test_group_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupAssetsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2255,6 +2301,7 @@ def test_group_assets( assert args[0] == securitycenter_service.GroupAssetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupAssetsPager) assert response.next_page_token == "next_page_token_value" @@ -2267,19 +2314,20 @@ def test_group_assets_from_dict(): @pytest.mark.asyncio -async def test_group_assets_async(transport: str = "grpc_asyncio"): +async def test_group_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupAssetsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GroupAssetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupAssetsResponse( @@ -2293,7 +2341,7 @@ async def test_group_assets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GroupAssetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.GroupAssetsAsyncPager) @@ -2303,6 +2351,11 @@ async def test_group_assets_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_group_assets_async_from_dict(): + await test_group_assets_async(request_type=dict) + + def test_group_assets_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2312,7 +2365,7 @@ def test_group_assets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: call.return_value = securitycenter_service.GroupAssetsResponse() client.group_assets(request) @@ -2337,9 +2390,7 @@ async def test_group_assets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupAssetsResponse() ) @@ -2360,7 +2411,7 @@ def test_group_assets_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupAssetsResponse( @@ -2404,7 +2455,7 @@ def test_group_assets_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_assets), "__call__") as call: + with mock.patch.object(type(client.transport.group_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupAssetsResponse( @@ -2441,9 +2492,7 @@ async def test_group_assets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2486,9 +2535,7 @@ async def test_group_assets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2534,7 +2581,7 @@ def test_group_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2549,6 +2596,7 @@ def test_group_findings( assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.GroupFindingsPager) assert response.next_page_token == "next_page_token_value" @@ -2561,19 +2609,20 @@ def test_group_findings_from_dict(): @pytest.mark.asyncio -async def test_group_findings_async(transport: str = "grpc_asyncio"): +async def test_group_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.GroupFindingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.GroupFindingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupFindingsResponse( @@ -2587,7 +2636,7 @@ async def test_group_findings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.GroupFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.GroupFindingsAsyncPager) @@ -2597,6 +2646,11 @@ async def test_group_findings_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_group_findings_async_from_dict(): + await test_group_findings_async(request_type=dict) + + def test_group_findings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2606,7 +2660,7 @@ def test_group_findings_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = securitycenter_service.GroupFindingsResponse() client.group_findings(request) @@ -2631,9 +2685,7 @@ async def test_group_findings_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.GroupFindingsResponse() ) @@ -2654,7 +2706,7 @@ def test_group_findings_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse() @@ -2692,9 +2744,7 @@ async def test_group_findings_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.group_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.GroupFindingsResponse() @@ -2735,7 +2785,7 @@ def test_group_findings_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupFindingsResponse( @@ -2779,7 +2829,7 @@ def test_group_findings_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.group_findings), "__call__") as call: + with mock.patch.object(type(client.transport.group_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.GroupFindingsResponse( @@ -2816,9 +2866,7 @@ async def test_group_findings_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2861,9 +2909,7 @@ async def test_group_findings_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.group_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.group_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2909,7 +2955,7 @@ def test_list_assets( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListAssetsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -2924,6 +2970,7 @@ def test_list_assets( assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListAssetsPager) assert response.next_page_token == "next_page_token_value" @@ -2936,19 +2983,20 @@ def test_list_assets_from_dict(): @pytest.mark.asyncio -async def test_list_assets_async(transport: str = "grpc_asyncio"): +async def test_list_assets_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListAssetsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListAssetsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListAssetsResponse( @@ -2962,7 +3010,7 @@ async def test_list_assets_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListAssetsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListAssetsAsyncPager) @@ -2972,6 +3020,11 @@ async def test_list_assets_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_assets_async_from_dict(): + await test_list_assets_async(request_type=dict) + + def test_list_assets_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -2981,7 +3034,7 @@ def test_list_assets_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = securitycenter_service.ListAssetsResponse() client.list_assets(request) @@ -3006,9 +3059,7 @@ async def test_list_assets_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListAssetsResponse() ) @@ -3029,7 +3080,7 @@ def test_list_assets_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListAssetsResponse() @@ -3061,9 +3112,7 @@ async def test_list_assets_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_assets), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListAssetsResponse() @@ -3098,7 +3147,7 @@ def test_list_assets_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListAssetsResponse( @@ -3147,7 +3196,7 @@ def test_list_assets_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_assets), "__call__") as call: + with mock.patch.object(type(client.transport.list_assets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListAssetsResponse( @@ -3186,9 +3235,7 @@ async def test_list_assets_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3236,9 +3283,7 @@ async def test_list_assets_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_assets), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_assets), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3286,7 +3331,7 @@ def test_list_findings( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListFindingsResponse( next_page_token="next_page_token_value", total_size=1086, @@ -3301,6 +3346,7 @@ def test_list_findings( assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFindingsPager) assert response.next_page_token == "next_page_token_value" @@ -3313,19 +3359,20 @@ def test_list_findings_from_dict(): @pytest.mark.asyncio -async def test_list_findings_async(transport: str = "grpc_asyncio"): +async def test_list_findings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListFindingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListFindingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListFindingsResponse( @@ -3339,7 +3386,7 @@ async def test_list_findings_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListFindingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFindingsAsyncPager) @@ -3349,6 +3396,11 @@ async def test_list_findings_async(transport: str = "grpc_asyncio"): assert response.total_size == 1086 +@pytest.mark.asyncio +async def test_list_findings_async_from_dict(): + await test_list_findings_async(request_type=dict) + + def test_list_findings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3358,7 +3410,7 @@ def test_list_findings_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = securitycenter_service.ListFindingsResponse() client.list_findings(request) @@ -3383,9 +3435,7 @@ async def test_list_findings_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListFindingsResponse() ) @@ -3406,7 +3456,7 @@ def test_list_findings_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListFindingsResponse() @@ -3438,9 +3488,7 @@ async def test_list_findings_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_findings), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListFindingsResponse() @@ -3475,7 +3523,7 @@ def test_list_findings_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListFindingsResponse( @@ -3526,7 +3574,7 @@ def test_list_findings_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_findings), "__call__") as call: + with mock.patch.object(type(client.transport.list_findings), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListFindingsResponse( @@ -3565,9 +3613,7 @@ async def test_list_findings_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3617,9 +3663,7 @@ async def test_list_findings_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_findings), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_findings), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3669,7 +3713,7 @@ def test_list_notification_configs( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListNotificationConfigsResponse( @@ -3685,6 +3729,7 @@ def test_list_notification_configs( assert args[0] == securitycenter_service.ListNotificationConfigsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListNotificationConfigsPager) assert response.next_page_token == "next_page_token_value" @@ -3695,18 +3740,21 @@ def test_list_notification_configs_from_dict(): @pytest.mark.asyncio -async def test_list_notification_configs_async(transport: str = "grpc_asyncio"): +async def test_list_notification_configs_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListNotificationConfigsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListNotificationConfigsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -3721,7 +3769,7 @@ async def test_list_notification_configs_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListNotificationConfigsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListNotificationConfigsAsyncPager) @@ -3729,6 +3777,11 @@ async def test_list_notification_configs_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_notification_configs_async_from_dict(): + await test_list_notification_configs_async(request_type=dict) + + def test_list_notification_configs_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -3739,7 +3792,7 @@ def test_list_notification_configs_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: call.return_value = securitycenter_service.ListNotificationConfigsResponse() @@ -3766,7 +3819,7 @@ async def test_list_notification_configs_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListNotificationConfigsResponse() @@ -3789,7 +3842,7 @@ def test_list_notification_configs_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListNotificationConfigsResponse() @@ -3824,7 +3877,7 @@ async def test_list_notification_configs_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListNotificationConfigsResponse() @@ -3862,7 +3915,7 @@ def test_list_notification_configs_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3910,7 +3963,7 @@ def test_list_notification_configs_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_notification_configs), "__call__" + type(client.transport.list_notification_configs), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -3948,7 +4001,7 @@ async def test_list_notification_configs_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), + type(client.transport.list_notification_configs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -3995,7 +4048,7 @@ async def test_list_notification_configs_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_notification_configs), + type(client.transport.list_notification_configs), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -4043,7 +4096,7 @@ def test_list_sources( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse( next_page_token="next_page_token_value", @@ -4058,6 +4111,7 @@ def test_list_sources( assert args[0] == securitycenter_service.ListSourcesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSourcesPager) assert response.next_page_token == "next_page_token_value" @@ -4068,19 +4122,20 @@ def test_list_sources_from_dict(): @pytest.mark.asyncio -async def test_list_sources_async(transport: str = "grpc_asyncio"): +async def test_list_sources_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.ListSourcesRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.ListSourcesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListSourcesResponse( @@ -4094,7 +4149,7 @@ async def test_list_sources_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.ListSourcesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListSourcesAsyncPager) @@ -4102,6 +4157,11 @@ async def test_list_sources_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_sources_async_from_dict(): + await test_list_sources_async(request_type=dict) + + def test_list_sources_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4111,7 +4171,7 @@ def test_list_sources_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: call.return_value = securitycenter_service.ListSourcesResponse() client.list_sources(request) @@ -4136,9 +4196,7 @@ async def test_list_sources_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( securitycenter_service.ListSourcesResponse() ) @@ -4159,7 +4217,7 @@ def test_list_sources_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse() @@ -4191,9 +4249,7 @@ async def test_list_sources_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_sources), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = securitycenter_service.ListSourcesResponse() @@ -4228,7 +4284,7 @@ def test_list_sources_pager(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListSourcesResponse( @@ -4264,7 +4320,7 @@ def test_list_sources_pages(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_sources), "__call__") as call: + with mock.patch.object(type(client.transport.list_sources), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( securitycenter_service.ListSourcesResponse( @@ -4293,9 +4349,7 @@ async def test_list_sources_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_sources), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4330,9 +4384,7 @@ async def test_list_sources_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_sources), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_sources), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -4372,7 +4424,7 @@ def test_run_asset_discovery( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -4394,18 +4446,21 @@ def test_run_asset_discovery_from_dict(): @pytest.mark.asyncio -async def test_run_asset_discovery_async(transport: str = "grpc_asyncio"): +async def test_run_asset_discovery_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.RunAssetDiscoveryRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.RunAssetDiscoveryRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4418,12 +4473,17 @@ async def test_run_asset_discovery_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.RunAssetDiscoveryRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_run_asset_discovery_async_from_dict(): + await test_run_asset_discovery_async(request_type=dict) + + def test_run_asset_discovery_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4434,7 +4494,7 @@ def test_run_asset_discovery_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = operations_pb2.Operation(name="operations/op") @@ -4461,7 +4521,7 @@ async def test_run_asset_discovery_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") @@ -4484,7 +4544,7 @@ def test_run_asset_discovery_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -4518,7 +4578,7 @@ async def test_run_asset_discovery_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.run_asset_discovery), "__call__" + type(client.transport.run_asset_discovery), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -4563,7 +4623,7 @@ def test_set_finding_state( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding( @@ -4585,6 +4645,7 @@ def test_set_finding_state( assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. + assert isinstance(response, finding.Finding) assert response.name == "name_value" @@ -4607,18 +4668,21 @@ def test_set_finding_state_from_dict(): @pytest.mark.asyncio -async def test_set_finding_state_async(transport: str = "grpc_asyncio"): +async def test_set_finding_state_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.SetFindingStateRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.SetFindingStateRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -4639,7 +4703,7 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.SetFindingStateRequest() # Establish that the response is the type that we expect. assert isinstance(response, finding.Finding) @@ -4659,6 +4723,11 @@ async def test_set_finding_state_async(transport: str = "grpc_asyncio"): assert response.severity == finding.Finding.Severity.CRITICAL +@pytest.mark.asyncio +async def test_set_finding_state_async_from_dict(): + await test_set_finding_state_async(request_type=dict) + + def test_set_finding_state_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4669,7 +4738,7 @@ def test_set_finding_state_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: call.return_value = finding.Finding() @@ -4696,7 +4765,7 @@ async def test_set_finding_state_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(finding.Finding()) @@ -4717,7 +4786,7 @@ def test_set_finding_state_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() @@ -4764,7 +4833,7 @@ async def test_set_finding_state_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.set_finding_state), "__call__" + type(client.transport.set_finding_state), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = finding.Finding() @@ -4819,7 +4888,7 @@ def test_set_iam_policy( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy(version=774, etag=b"etag_blob",) @@ -4832,6 +4901,7 @@ def test_set_iam_policy( assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. + assert isinstance(response, policy.Policy) assert response.version == 774 @@ -4844,19 +4914,19 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio -async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): +async def test_set_iam_policy_async( + transport: str = "grpc_asyncio", request_type=iam_policy.SetIamPolicyRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.SetIamPolicyRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( policy.Policy(version=774, etag=b"etag_blob",) @@ -4868,7 +4938,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.SetIamPolicyRequest() # Establish that the response is the type that we expect. assert isinstance(response, policy.Policy) @@ -4878,6 +4948,11 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): assert response.etag == b"etag_blob" +@pytest.mark.asyncio +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) + + def test_set_iam_policy_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -4887,7 +4962,7 @@ def test_set_iam_policy_field_headers(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = policy.Policy() client.set_iam_policy(request) @@ -4912,9 +4987,7 @@ async def test_set_iam_policy_field_headers_async(): request.resource = "resource/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy.Policy()) await client.set_iam_policy(request) @@ -4929,10 +5002,10 @@ async def test_set_iam_policy_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_set_iam_policy_from_dict(): +def test_set_iam_policy_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4949,7 +5022,7 @@ def test_set_iam_policy_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.set_iam_policy), "__call__") as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -4981,9 +5054,7 @@ async def test_set_iam_policy_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.set_iam_policy), "__call__" - ) as call: + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = policy.Policy() @@ -5025,7 +5096,7 @@ def test_test_iam_permissions( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse( @@ -5041,6 +5112,7 @@ def test_test_iam_permissions( assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy.TestIamPermissionsResponse) assert response.permissions == ["permissions_value"] @@ -5051,18 +5123,20 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio -async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): +async def test_test_iam_permissions_async( + transport: str = "grpc_asyncio", request_type=iam_policy.TestIamPermissionsRequest +): client = SecurityCenterAsyncClient( credentials=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 = iam_policy.TestIamPermissionsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5075,7 +5149,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == iam_policy.TestIamPermissionsRequest() # Establish that the response is the type that we expect. assert isinstance(response, iam_policy.TestIamPermissionsResponse) @@ -5083,6 +5157,11 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): assert response.permissions == ["permissions_value"] +@pytest.mark.asyncio +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) + + def test_test_iam_permissions_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5093,7 +5172,7 @@ def test_test_iam_permissions_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = iam_policy.TestIamPermissionsResponse() @@ -5120,7 +5199,7 @@ async def test_test_iam_permissions_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( iam_policy.TestIamPermissionsResponse() @@ -5138,11 +5217,11 @@ async def test_test_iam_permissions_field_headers_async(): assert ("x-goog-request-params", "resource=resource/value",) in kw["metadata"] -def test_test_iam_permissions_from_dict(): +def test_test_iam_permissions_from_dict_foreign(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -5161,7 +5240,7 @@ def test_test_iam_permissions_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -5201,7 +5280,7 @@ async def test_test_iam_permissions_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.test_iam_permissions), "__call__" + type(client.transport.test_iam_permissions), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iam_policy.TestIamPermissionsResponse() @@ -5251,7 +5330,7 @@ def test_update_finding( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding( name="name_value", @@ -5272,6 +5351,7 @@ def test_update_finding( assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_finding.Finding) assert response.name == "name_value" @@ -5294,19 +5374,20 @@ def test_update_finding_from_dict(): @pytest.mark.asyncio -async def test_update_finding_async(transport: str = "grpc_asyncio"): +async def test_update_finding_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateFindingRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateFindingRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_finding.Finding( @@ -5326,7 +5407,7 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateFindingRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_finding.Finding) @@ -5346,6 +5427,11 @@ async def test_update_finding_async(transport: str = "grpc_asyncio"): assert response.severity == gcs_finding.Finding.Severity.CRITICAL +@pytest.mark.asyncio +async def test_update_finding_async_from_dict(): + await test_update_finding_async(request_type=dict) + + def test_update_finding_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5355,7 +5441,7 @@ def test_update_finding_field_headers(): request.finding.name = "finding.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: call.return_value = gcs_finding.Finding() client.update_finding(request) @@ -5382,9 +5468,7 @@ async def test_update_finding_field_headers_async(): request.finding.name = "finding.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_finding.Finding()) await client.update_finding(request) @@ -5405,7 +5489,7 @@ def test_update_finding_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_finding), "__call__") as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -5444,9 +5528,7 @@ async def test_update_finding_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_finding), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_finding), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_finding.Finding() @@ -5496,7 +5578,7 @@ def test_update_notification_config( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig( @@ -5519,6 +5601,7 @@ def test_update_notification_config( assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_notification_config.NotificationConfig) assert response.name == "name_value" @@ -5540,18 +5623,21 @@ def test_update_notification_config_from_dict(): @pytest.mark.asyncio -async def test_update_notification_config_async(transport: str = "grpc_asyncio"): +async def test_update_notification_config_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateNotificationConfigRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateNotificationConfigRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5570,7 +5656,7 @@ async def test_update_notification_config_async(transport: str = "grpc_asyncio") assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateNotificationConfigRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_notification_config.NotificationConfig) @@ -5589,6 +5675,11 @@ async def test_update_notification_config_async(transport: str = "grpc_asyncio") assert response.service_account == "service_account_value" +@pytest.mark.asyncio +async def test_update_notification_config_async_from_dict(): + await test_update_notification_config_async(request_type=dict) + + def test_update_notification_config_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5599,7 +5690,7 @@ def test_update_notification_config_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: call.return_value = gcs_notification_config.NotificationConfig() @@ -5629,7 +5720,7 @@ async def test_update_notification_config_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_notification_config.NotificationConfig() @@ -5655,7 +5746,7 @@ def test_update_notification_config_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -5704,7 +5795,7 @@ async def test_update_notification_config_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_notification_config), "__call__" + type(client.transport.update_notification_config), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_notification_config.NotificationConfig() @@ -5765,7 +5856,7 @@ def test_update_organization_settings( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings( @@ -5781,6 +5872,7 @@ def test_update_organization_settings( assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_organization_settings.OrganizationSettings) assert response.name == "name_value" @@ -5793,18 +5885,21 @@ def test_update_organization_settings_from_dict(): @pytest.mark.asyncio -async def test_update_organization_settings_async(transport: str = "grpc_asyncio"): +async def test_update_organization_settings_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateOrganizationSettingsRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateOrganizationSettingsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5819,7 +5914,7 @@ async def test_update_organization_settings_async(transport: str = "grpc_asyncio assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateOrganizationSettingsRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_organization_settings.OrganizationSettings) @@ -5829,6 +5924,11 @@ async def test_update_organization_settings_async(transport: str = "grpc_asyncio assert response.enable_asset_discovery is True +@pytest.mark.asyncio +async def test_update_organization_settings_async_from_dict(): + await test_update_organization_settings_async(request_type=dict) + + def test_update_organization_settings_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -5839,7 +5939,7 @@ def test_update_organization_settings_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: call.return_value = gcs_organization_settings.OrganizationSettings() @@ -5869,7 +5969,7 @@ async def test_update_organization_settings_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_organization_settings.OrganizationSettings() @@ -5895,7 +5995,7 @@ def test_update_organization_settings_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings() @@ -5940,7 +6040,7 @@ async def test_update_organization_settings_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_organization_settings), "__call__" + type(client.transport.update_organization_settings), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_organization_settings.OrganizationSettings() @@ -5995,7 +6095,7 @@ def test_update_source( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source( name="name_value", @@ -6012,6 +6112,7 @@ def test_update_source( assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_source.Source) assert response.name == "name_value" @@ -6026,19 +6127,20 @@ def test_update_source_from_dict(): @pytest.mark.asyncio -async def test_update_source_async(transport: str = "grpc_asyncio"): +async def test_update_source_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSourceRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateSourceRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_source.Source( @@ -6054,7 +6156,7 @@ async def test_update_source_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateSourceRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_source.Source) @@ -6066,6 +6168,11 @@ async def test_update_source_async(transport: str = "grpc_asyncio"): assert response.description == "description_value" +@pytest.mark.asyncio +async def test_update_source_async_from_dict(): + await test_update_source_async(request_type=dict) + + def test_update_source_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -6075,7 +6182,7 @@ def test_update_source_field_headers(): request.source.name = "source.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: call.return_value = gcs_source.Source() client.update_source(request) @@ -6100,9 +6207,7 @@ async def test_update_source_field_headers_async(): request.source.name = "source.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gcs_source.Source()) await client.update_source(request) @@ -6121,7 +6226,7 @@ def test_update_source_flattened(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_source), "__call__") as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -6160,9 +6265,7 @@ async def test_update_source_flattened_async(): client = SecurityCenterAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_source), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_source), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gcs_source.Source() @@ -6212,7 +6315,7 @@ def test_update_security_marks( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks(name="name_value",) @@ -6226,6 +6329,7 @@ def test_update_security_marks( assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gcs_security_marks.SecurityMarks) assert response.name == "name_value" @@ -6236,18 +6340,21 @@ def test_update_security_marks_from_dict(): @pytest.mark.asyncio -async def test_update_security_marks_async(transport: str = "grpc_asyncio"): +async def test_update_security_marks_async( + transport: str = "grpc_asyncio", + request_type=securitycenter_service.UpdateSecurityMarksRequest, +): client = SecurityCenterAsyncClient( credentials=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 = securitycenter_service.UpdateSecurityMarksRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -6260,7 +6367,7 @@ async def test_update_security_marks_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == securitycenter_service.UpdateSecurityMarksRequest() # Establish that the response is the type that we expect. assert isinstance(response, gcs_security_marks.SecurityMarks) @@ -6268,6 +6375,11 @@ async def test_update_security_marks_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_update_security_marks_async_from_dict(): + await test_update_security_marks_async(request_type=dict) + + def test_update_security_marks_field_headers(): client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) @@ -6278,7 +6390,7 @@ def test_update_security_marks_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: call.return_value = gcs_security_marks.SecurityMarks() @@ -6308,7 +6420,7 @@ async def test_update_security_marks_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gcs_security_marks.SecurityMarks() @@ -6334,7 +6446,7 @@ def test_update_security_marks_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks() @@ -6377,7 +6489,7 @@ async def test_update_security_marks_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.update_security_marks), "__call__" + type(client.transport.update_security_marks), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gcs_security_marks.SecurityMarks() @@ -6454,7 +6566,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = SecurityCenterClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -6490,7 +6602,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SecurityCenterClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.SecurityCenterGrpcTransport,) + assert isinstance(client.transport, transports.SecurityCenterGrpcTransport,) def test_security_center_base_transport_error(): @@ -6611,7 +6723,7 @@ def test_security_center_host_no_port(): api_endpoint="securitycenter.googleapis.com" ), ) - assert client._transport._host == "securitycenter.googleapis.com:443" + assert client.transport._host == "securitycenter.googleapis.com:443" def test_security_center_host_with_port(): @@ -6621,7 +6733,7 @@ def test_security_center_host_with_port(): api_endpoint="securitycenter.googleapis.com:8000" ), ) - assert client._transport._host == "securitycenter.googleapis.com:8000" + assert client.transport._host == "securitycenter.googleapis.com:8000" def test_security_center_grpc_transport_channel(): @@ -6633,6 +6745,7 @@ def test_security_center_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_security_center_grpc_asyncio_transport_channel(): @@ -6644,6 +6757,7 @@ def test_security_center_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -6689,8 +6803,13 @@ def test_security_center_transport_channel_mtls_with_client_cert_source( scopes=("https://www.googleapis.com/auth/cloud-platform",), 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 @pytest.mark.parametrize( @@ -6729,6 +6848,10 @@ def test_security_center_transport_channel_mtls_with_adc(transport_class): scopes=("https://www.googleapis.com/auth/cloud-platform",), 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 @@ -6737,7 +6860,7 @@ def test_security_center_grpc_lro_client(): client = SecurityCenterClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -6750,7 +6873,7 @@ def test_security_center_grpc_lro_async_client(): client = SecurityCenterAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -6759,10 +6882,33 @@ def test_security_center_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_finding_path(): +def test_asset_path(): organization = "squid" - source = "clam" - finding = "whelk" + asset = "clam" + + expected = "organizations/{organization}/assets/{asset}".format( + organization=organization, asset=asset, + ) + actual = SecurityCenterClient.asset_path(organization, asset) + assert expected == actual + + +def test_parse_asset_path(): + expected = { + "organization": "whelk", + "asset": "octopus", + } + path = SecurityCenterClient.asset_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_asset_path(path) + assert expected == actual + + +def test_finding_path(): + organization = "oyster" + source = "nudibranch" + finding = "cuttlefish" expected = "organizations/{organization}/sources/{source}/findings/{finding}".format( organization=organization, source=source, finding=finding, @@ -6773,9 +6919,9 @@ def test_finding_path(): def test_parse_finding_path(): expected = { - "organization": "octopus", - "source": "oyster", - "finding": "nudibranch", + "organization": "mussel", + "source": "winkle", + "finding": "nautilus", } path = SecurityCenterClient.finding_path(**expected) @@ -6785,8 +6931,8 @@ def test_parse_finding_path(): def test_notification_config_path(): - organization = "squid" - notification_config = "clam" + organization = "scallop" + notification_config = "abalone" expected = "organizations/{organization}/notificationConfigs/{notification_config}".format( organization=organization, notification_config=notification_config, @@ -6799,8 +6945,8 @@ def test_notification_config_path(): def test_parse_notification_config_path(): expected = { - "organization": "whelk", - "notification_config": "octopus", + "organization": "squid", + "notification_config": "clam", } path = SecurityCenterClient.notification_config_path(**expected) @@ -6810,7 +6956,7 @@ def test_parse_notification_config_path(): def test_organization_settings_path(): - organization = "squid" + organization = "whelk" expected = "organizations/{organization}/organizationSettings".format( organization=organization, @@ -6821,7 +6967,7 @@ def test_organization_settings_path(): def test_parse_organization_settings_path(): expected = { - "organization": "clam", + "organization": "octopus", } path = SecurityCenterClient.organization_settings_path(**expected) @@ -6831,8 +6977,8 @@ def test_parse_organization_settings_path(): def test_security_marks_path(): - organization = "squid" - asset = "clam" + organization = "oyster" + asset = "nudibranch" expected = "organizations/{organization}/assets/{asset}/securityMarks".format( organization=organization, asset=asset, @@ -6843,8 +6989,8 @@ def test_security_marks_path(): def test_parse_security_marks_path(): expected = { - "organization": "whelk", - "asset": "octopus", + "organization": "cuttlefish", + "asset": "mussel", } path = SecurityCenterClient.security_marks_path(**expected) @@ -6854,8 +7000,8 @@ def test_parse_security_marks_path(): def test_source_path(): - organization = "squid" - source = "clam" + organization = "winkle" + source = "nautilus" expected = "organizations/{organization}/sources/{source}".format( organization=organization, source=source, @@ -6866,8 +7012,8 @@ def test_source_path(): def test_parse_source_path(): expected = { - "organization": "whelk", - "source": "octopus", + "organization": "scallop", + "source": "abalone", } path = SecurityCenterClient.source_path(**expected) @@ -6876,6 +7022,128 @@ def test_parse_source_path(): assert expected == actual +def test_topic_path(): + project = "squid" + topic = "clam" + + expected = "projects/{project}/topics/{topic}".format(project=project, topic=topic,) + actual = SecurityCenterClient.topic_path(project, topic) + assert expected == actual + + +def test_parse_topic_path(): + expected = { + "project": "whelk", + "topic": "octopus", + } + path = SecurityCenterClient.topic_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_topic_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "oyster" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = SecurityCenterClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nudibranch", + } + path = SecurityCenterClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "cuttlefish" + + expected = "folders/{folder}".format(folder=folder,) + actual = SecurityCenterClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "mussel", + } + path = SecurityCenterClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "winkle" + + expected = "organizations/{organization}".format(organization=organization,) + actual = SecurityCenterClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nautilus", + } + path = SecurityCenterClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "scallop" + + expected = "projects/{project}".format(project=project,) + actual = SecurityCenterClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "abalone", + } + path = SecurityCenterClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.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 = SecurityCenterClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "whelk", + "location": "octopus", + } + path = SecurityCenterClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = SecurityCenterClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo()