示例#1
0
    def test_update_source(self):
        # Setup Expected Response
        name = "name3373707"
        display_name = "displayName1615086568"
        description = "description-1724546052"
        expected_response = {
            "name": name,
            "display_name": display_name,
            "description": description,
        }
        expected_response = source_pb2.Source(**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
        source = {}

        response = client.update_source(source)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = securitycenter_service_pb2.UpdateSourceRequest(source=source)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
示例#2
0
    def test_get_source(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        display_name = "displayName1615086568"
        description = "description-1724546052"
        expected_response = {
            "name": name_2,
            "display_name": display_name,
            "description": description,
        }
        expected_response = source_pb2.Source(**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.source_path("[ORGANIZATION]", "[SOURCE]")

        response = client.get_source(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = securitycenter_service_pb2.GetSourceRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request