Skip to content

Commit 4812c65

Browse files
committed
Add back api._twisted_publish with deprecation warning
Signed-off-by: Mattia Verga <mattia.verga@tiscali.it>
1 parent 4dbe620 commit 4812c65

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

fedora_messaging/api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import inspect
44
import logging
5+
import warnings
56

67
import crochet
78
from twisted.internet import defer, reactor, threads
@@ -262,6 +263,16 @@ def twisted_publish(message, exchange=None):
262263
raise
263264

264265

266+
def _twisted_publish(message, exchange):
267+
"""Deprecated method, use _twisted_publish_wrapper()."""
268+
warnings.warn(
269+
"_twisted_publish() is deprecated, use _twisted_publish_wrapper(); version 3.6.0",
270+
DeprecationWarning,
271+
stacklevel=2,
272+
)
273+
return _twisted_publish_wrapper(message, exchange)
274+
275+
265276
@crochet.run_in_reactor
266277
@defer.inlineCallbacks
267278
def _twisted_publish_wrapper(message, exchange):

news/PR375.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add back api._twisted_publish as deprecated method and emit proper warning when it is used

tests/unit/test_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ def test_publish_to_exchange(self):
222222

223223
mock_twisted_publish.assert_called_once_with(message, exchange)
224224

225+
@mock.patch("warnings.warn")
226+
def test_deprecated_twisted_publish(self, warn):
227+
"""Assert calling the deprecated method emits warning."""
228+
message = "test_message"
229+
exchange = "test_exchange"
230+
231+
with mock.patch("fedora_messaging.api._twisted_publish_wrapper") as mock_twisted_publish:
232+
api._twisted_publish(message, exchange)
233+
234+
warn.assert_called_once_with(
235+
"_twisted_publish() is deprecated, use _twisted_publish_wrapper(); version 3.6.0",
236+
DeprecationWarning,
237+
stacklevel=2,
238+
)
239+
mock_twisted_publish.assert_called_once_with(message, exchange)
240+
225241
@pytest_twisted.inlineCallbacks
226242
def test_publish_failed(self):
227243
"""Assert an exception is raised when message can't be published."""

0 commit comments

Comments
 (0)