예제 #1
0
    def test_delete_snapshot(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        snapshot = client.snapshot_path('[PROJECT]', '[SNAPSHOT]')

        client.delete_snapshot(snapshot)

        grpc_stub.DeleteSnapshot.assert_called_once()
        args, kwargs = grpc_stub.DeleteSnapshot.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = pubsub_pb2.DeleteSnapshotRequest(snapshot=snapshot)
        self.assertEqual(expected_request, actual_request)
예제 #2
0
    def test_delete_subscription(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')

        client.delete_subscription(subscription)

        grpc_stub.DeleteSubscription.assert_called_once()
        args, kwargs = grpc_stub.DeleteSubscription.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = pubsub_pb2.DeleteSubscriptionRequest(
            subscription=subscription)
        self.assertEqual(expected_request, actual_request)
예제 #3
0
    def test_test_iam_permissions(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock(spec=iam_policy_pb2.IAMPolicyStub)
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        resource = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        permissions = []

        # Mock response
        expected_response = iam_policy_pb2.TestIamPermissionsResponse()
        grpc_stub.TestIamPermissions.return_value = expected_response

        response = client.test_iam_permissions(resource, permissions)
        self.assertEqual(expected_response, response)

        grpc_stub.TestIamPermissions.assert_called_once()
        request = grpc_stub.TestIamPermissions.call_args[0]

        self.assertEqual(resource, request.resource)
        self.assertEqual(permissions, request.permissions)
예제 #4
0
    def test_get_iam_policy(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock(spec=iam_policy_pb2.IAMPolicyStub)
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        resource = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')

        # Mock response
        version = 351608024
        etag = b'21'
        expected_response = policy_pb2.Policy(version, etag)
        grpc_stub.GetIamPolicy.return_value = expected_response

        response = client.get_iam_policy(resource)
        self.assertEqual(expected_response, response)

        grpc_stub.GetIamPolicy.assert_called_once()
        request = grpc_stub.GetIamPolicy.call_args[0]

        self.assertEqual(resource, request.resource)
예제 #5
0
    def test_pull(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock(spec=pubsub_pb2.SubscriberStub)
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        max_messages = 496131527

        # Mock response
        expected_response = pubsub_pb2.PullResponse()
        grpc_stub.Pull.return_value = expected_response

        response = client.pull(subscription, max_messages)
        self.assertEqual(expected_response, response)

        grpc_stub.Pull.assert_called_once()
        request = grpc_stub.Pull.call_args[0]

        self.assertEqual(subscription, request.subscription)
        self.assertEqual(max_messages, request.max_messages)
예제 #6
0
    def test_modify_push_config(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        push_config = pubsub_pb2.PushConfig()

        client.modify_push_config(subscription, push_config)

        grpc_stub.ModifyPushConfig.assert_called_once()
        args, kwargs = grpc_stub.ModifyPushConfig.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = pubsub_pb2.ModifyPushConfigRequest(
            subscription=subscription, push_config=push_config)
        self.assertEqual(expected_request, actual_request)
예제 #7
0
    def test_update_subscription(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = subscriber_client.SubscriberClient()

        # Mock request
        subscription = pubsub_pb2.Subscription()
        update_mask = field_mask_pb2.FieldMask()

        # Mock response
        name = 'name3373707'
        topic = 'topic110546223'
        ack_deadline_seconds = 2135351438
        retain_acked_messages = False
        expected_response = pubsub_pb2.Subscription(
            name=name,
            topic=topic,
            ack_deadline_seconds=ack_deadline_seconds,
            retain_acked_messages=retain_acked_messages)
        grpc_stub.UpdateSubscription.return_value = expected_response

        response = client.update_subscription(subscription, update_mask)
        self.assertEqual(expected_response, response)

        grpc_stub.UpdateSubscription.assert_called_once()
        args, kwargs = grpc_stub.UpdateSubscription.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = pubsub_pb2.UpdateSubscriptionRequest(
            subscription=subscription, update_mask=update_mask)
        self.assertEqual(expected_request, actual_request)