Esempio n. 1
0
    def test_create_autoscaling_policy(self):
        # Setup Expected Response
        id_ = "id3355"
        name = "name3373707"
        expected_response = {"id": id_, "name": name}
        expected_response = autoscaling_policies_pb2.AutoscalingPolicy(
            **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 = dataproc_v1beta2.AutoscalingPolicyServiceClient()

        # Setup Request
        parent = client.region_path("[PROJECT]", "[REGION]")
        policy = {}

        response = client.create_autoscaling_policy(parent, policy)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = autoscaling_policies_pb2.CreateAutoscalingPolicyRequest(
            parent=parent, policy=policy)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 2
0
    def test_get_autoscaling_policy(self):
        # Setup Expected Response
        id_ = "id3355"
        name_2 = "name2-1052831874"
        expected_response = {"id": id_, "name": name_2}
        expected_response = autoscaling_policies_pb2.AutoscalingPolicy(
            **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 = dataproc_v1beta2.AutoscalingPolicyServiceClient()

        # Setup Request
        name = client.autoscaling_policy_path("[PROJECT]", "[REGION]",
                                              "[AUTOSCALING_POLICY]")

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

        assert len(channel.requests) == 1
        expected_request = autoscaling_policies_pb2.GetAutoscalingPolicyRequest(
            name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request