Exemple #1
0
    def test_list_autoscaling_policies(self):
        # Setup Expected Response
        next_page_token = ""
        policies_element = {}
        policies = [policies_element]
        expected_response = {
            "next_page_token": next_page_token,
            "policies": policies
        }
        expected_response = autoscaling_policies_pb2.ListAutoscalingPoliciesResponse(
            **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_v1.AutoscalingPolicyServiceClient()

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

        paged_list_response = client.list_autoscaling_policies(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.policies[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = autoscaling_policies_pb2.ListAutoscalingPoliciesRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemple #2
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_v1.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
Exemple #3
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_v1.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
Exemple #4
0
    def test_list_autoscaling_policies_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dataproc_v1.AutoscalingPolicyServiceClient()

        # Setup request
        parent = client.region_path("[PROJECT]", "[REGION]")

        paged_list_response = client.list_autoscaling_policies(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
Exemple #5
0
    def test_update_autoscaling_policy_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dataproc_v1.AutoscalingPolicyServiceClient()

        # Setup request
        policy = {}

        with pytest.raises(CustomException):
            client.update_autoscaling_policy(policy)
Exemple #6
0
    def test_delete_autoscaling_policy_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dataproc_v1.AutoscalingPolicyServiceClient()

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

        with pytest.raises(CustomException):
            client.delete_autoscaling_policy(name)
Exemple #7
0
    def test_delete_autoscaling_policy(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dataproc_v1.AutoscalingPolicyServiceClient()

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

        client.delete_autoscaling_policy(name)

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