Skip to content

Commit

Permalink
Add back api._twisted_publish with deprecation warning
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <[email protected]>
  • Loading branch information
mattiaverga committed Jun 22, 2024
1 parent 4dbe620 commit 51bcaf4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fedora_messaging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import inspect
import logging
import warnings

import crochet
from twisted.internet import defer, reactor, threads
Expand Down Expand Up @@ -262,6 +263,16 @@ def twisted_publish(message, exchange=None):
raise


def _twisted_publish(message, exchange):
"""Deprecated method, use _twisted_publish_wrapper()."""
warnings.warn(
"_twisted_publish() is deprecated, use _twisted_publish_wrapper(); version 3.6.0",
DeprecationWarning,
stacklevel=2,
)
return _twisted_publish_wrapper(message, exchange)


@crochet.run_in_reactor
@defer.inlineCallbacks
def _twisted_publish_wrapper(message, exchange):
Expand Down
1 change: 1 addition & 0 deletions news/PR375.api
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add back api._twisted_publish as deprecated method and emit proper warning when it is used
16 changes: 16 additions & 0 deletions tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ def test_publish_to_exchange(self):

mock_twisted_publish.assert_called_once_with(message, exchange)

@mock.patch("warnings.warn")
def test_deprecated_twisted_publish(self, warn):
"""Assert calling the deprecated method emits warning."""
message = "test_message"
exchange = "test_exchange"

with mock.patch("fedora_messaging.api._twisted_publish_wrapper") as mock_twisted_publish:
result = api._twisted_publish(message, exchange)

warn.assert_called_once_with(
"_twisted_publish() is deprecated, use _twisted_publish_wrapper(); version 3.6.0",
DeprecationWarning,
stacklevel=2,
)
mock_twisted_publish.assert_called_once_with(message, exchange)

@pytest_twisted.inlineCallbacks
def test_publish_failed(self):
"""Assert an exception is raised when message can't be published."""
Expand Down

0 comments on commit 51bcaf4

Please sign in to comment.