def test_update_finding(self): # Setup Expected Response name = "name3373707" parent = "parent-995424086" resource_name = "resourceName979421212" category = "category50511102" external_uri = "externalUri-1385596168" expected_response = { "name": name, "parent": parent, "resource_name": resource_name, "category": category, "external_uri": external_uri, } expected_response = finding_pb2.Finding(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = securitycenter_v1.SecurityCenterClient() # Setup Request finding = {} response = client.update_finding(finding) assert expected_response == response assert len(channel.requests) == 1 expected_request = securitycenter_service_pb2.UpdateFindingRequest( finding=finding ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_set_finding_state(self): # Setup Expected Response name_2 = "name2-1052831874" parent = "parent-995424086" resource_name = "resourceName979421212" category = "category50511102" external_uri = "externalUri-1385596168" expected_response = { "name": name_2, "parent": parent, "resource_name": resource_name, "category": category, "external_uri": external_uri, } expected_response = finding_pb2.Finding(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = securitycenter_v1.SecurityCenterClient() # Setup Request name = client.finding_path("[ORGANIZATION]", "[SOURCE]", "[FINDING]") state = enums.Finding.State.STATE_UNSPECIFIED start_time = {} response = client.set_finding_state(name, state, start_time) assert expected_response == response assert len(channel.requests) == 1 expected_request = securitycenter_service_pb2.SetFindingStateRequest( name=name, state=state, start_time=start_time ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_finding(self): # Setup Expected Response name = "name3373707" parent_2 = "parent21175163357" resource_name = "resourceName979421212" category = "category50511102" external_uri = "externalUri-1385596168" expected_response = { "name": name, "parent": parent_2, "resource_name": resource_name, "category": category, "external_uri": external_uri, } expected_response = finding_pb2.Finding(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = securitycenter_v1.SecurityCenterClient() # Setup Request parent = client.source_path("[ORGANIZATION]", "[SOURCE]") finding_id = "findingId728776081" finding = {} response = client.create_finding(parent, finding_id, finding) assert expected_response == response assert len(channel.requests) == 1 expected_request = securitycenter_service_pb2.CreateFindingRequest( parent=parent, finding_id=finding_id, finding=finding ) actual_request = channel.requests[0][1] assert expected_request == actual_request