Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_creates_global_publisher_when_published_called(
self, mock_publisher, config
):
mock_publisher.return_value = MagicMock(spec=Publisher)
publishing.init_global_publisher(config)
message = {"foo": "bar"}
publishing.publish(topic="order-cancelled", data=message, myattr="hello")
assert isinstance(publishing._publisher, Publisher)
publisher_id = id(publishing._publisher)
mock_publisher.return_value.publish.assert_called_with(
"order-cancelled", {"foo": "bar"}, myattr="hello"
)
mock_publisher.return_value = MagicMock(spec=Publisher)
publishing.publish(topic="order-cancelled", data=message, myattr="hello")
assert id(publishing._publisher) == publisher_id
def test_creates_global_publisher_when_published_called(
self, mock_publisher, config
):
mock_publisher.return_value = MagicMock(spec=Publisher)
publishing.init_global_publisher(config)
message = {"foo": "bar"}
publishing.publish(topic="order-cancelled", data=message, myattr="hello")
assert isinstance(publishing._publisher, Publisher)
publisher_id = id(publishing._publisher)
mock_publisher.return_value.publish.assert_called_with(
"order-cancelled", {"foo": "bar"}, myattr="hello"
)
mock_publisher.return_value = MagicMock(spec=Publisher)
publishing.publish(topic="order-cancelled", data=message, myattr="hello")
assert id(publishing._publisher) == publisher_id