Пример #1
0
    def test_renew_lease(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        expected_response = {'name': name_2}
        expected_response = task_pb2.Task(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = tasks_v2beta2.CloudTasksClient(channel=channel)

        # Setup Request
        name = client.task_path('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]')
        schedule_time = {}
        lease_duration = {}

        response = client.renew_lease(name, schedule_time, lease_duration)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloudtasks_pb2.RenewLeaseRequest(
            name=name,
            schedule_time=schedule_time,
            lease_duration=lease_duration)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Пример #2
0
    def test_cancel_lease(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        expected_response = {"name": name_2}
        expected_response = task_pb2.Task(**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 = tasks_v2beta2.CloudTasksClient()

        # Setup Request
        name = client.task_path("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]")
        schedule_time = {}

        response = client.cancel_lease(name, schedule_time)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloudtasks_pb2.CancelLeaseRequest(
            name=name, schedule_time=schedule_time)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Пример #3
0
    def test_create_task(self):
        # Setup Expected Response
        name = "name3373707"
        expected_response = {"name": name}
        expected_response = task_pb2.Task(**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 = tasks_v2beta2.CloudTasksClient()

        # Setup Request
        parent = client.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]")
        task = {}

        response = client.create_task(parent, task)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloudtasks_pb2.CreateTaskRequest(parent=parent,
                                                            task=task)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_renew_lease(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        expected_response = {'name': name_2}
        expected_response = task_pb2.Task(**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 = tasks_v2beta2.CloudTasksClient()

        # Setup Request
        name = client.task_path('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]')
        schedule_time = {}
        lease_duration = {}

        response = client.renew_lease(name, schedule_time, lease_duration)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloudtasks_pb2.RenewLeaseRequest(
            name=name,
            schedule_time=schedule_time,
            lease_duration=lease_duration)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Пример #5
0
    def test_run_task(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        expected_response = {'name': name_2}
        expected_response = task_pb2.Task(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = tasks_v2beta2.CloudTasksClient(channel=channel)

        # Setup Request
        name = client.task_path('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]')

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

        assert len(channel.requests) == 1
        expected_request = cloudtasks_pb2.RunTaskRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Пример #6
0
    def test_create_task(self):
        # Setup Expected Response
        name = 'name3373707'
        expected_response = {'name': name}
        expected_response = task_pb2.Task(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = tasks_v2beta2.CloudTasksClient(channel=channel)

        # Setup Request
        parent = client.queue_path('[PROJECT]', '[LOCATION]', '[QUEUE]')
        task = {}

        response = client.create_task(parent, task)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = cloudtasks_pb2.CreateTaskRequest(
            parent=parent, task=task)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request