hankehly commented on code in PR #30981:
URL: https://github.com/apache/airflow/pull/30981#discussion_r1181365192
##########
tests/providers/google/cloud/hooks/test_pubsub.py:
##########
@@ -367,15 +362,31 @@ def test_create_subscription_nofailifexists(self,
mock_service):
@mock.patch(PUBSUB_STRING.format("PubSubHook.get_conn"))
def test_publish(self, mock_service):
+ """
+ Test that PubSubHook calls the publish method of the PubSub client
with the correct arguments.
+ In the case of string message data, the data should be encoded to
bytes before being passed to
+ the client.
+ """
publish_method = mock_service.return_value.publish
-
- self.pubsub_hook.publish(project_id=TEST_PROJECT, topic=TEST_TOPIC,
messages=TEST_MESSAGES)
+ hook_publish_messages = [
+ {"data": b"Hello, World!", "attributes": {"type": "greeting"}},
+ {"data": b"Knock, knock"},
+ {"attributes": {"foo": ""}},
+ {"data": "string data"},
+ ]
+ conn_publish_messages = [*hook_publish_messages[:3], {"data": b"string
data"}]
Review Comment:
This check needed to be updated to ensure that the `PubSubHook` converts
message data from string to bytes before passing it to the Google
`PublisherClient`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]