Skip to content

Commit 82dc5fc

Browse files
authored
refactor(testing): deprecate httpnow (#2440)
* refactor(testing): deprecate httpnow Signed-off-by: Keming <kemingy94@gmail.com> * fix the httpnow alias assertion Signed-off-by: Keming <kemingy94@gmail.com> * fix the newsfragment Signed-off-by: Keming <kemingy94@gmail.com> --------- Signed-off-by: Keming <kemingy94@gmail.com>
1 parent 6ec5725 commit 82dc5fc

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

docs/_newsfragments/2389.misc.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :func:`falcon.testing.httpnow` function is deprecated and will be removed in
2+
Falcon 5.0. Use the :func:`falcon.util.http_now` function instead.

falcon/testing/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,7 @@ def test_get_message(client):
161161

162162
# NOTE(kgriffs): Alias for backwards-compatibility with Falcon 0.2
163163
# TODO(vytas): Remove in Falcon 5.0.
164-
httpnow = _util.http_now
164+
httpnow = _util.deprecated(
165+
'This method is deprecated and will be removed in Falcon 5.0. '
166+
'Use `falcon.util.http_now` instead.'
167+
)(_util.http_now)

tests/test_testing.py

+8
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,11 @@ def capture_method(req, resp):
224224
assert result.status_code == 200
225225
expected = '' if method == 'HEAD' else method
226226
assert result.text == expected
227+
228+
229+
def test_deprecated_httpnow():
230+
with pytest.warns(
231+
falcon.util.DeprecatedWarning, match='Use `falcon.util.http_now` instead.'
232+
):
233+
now = testing.httpnow()
234+
assert now

tests/test_utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import timezone
44
import functools
55
import http
6+
import inspect
67
import itertools
78
import json
89
import random
@@ -712,7 +713,11 @@ def test_decode_empty_result(self, app):
712713
assert response.json == falcon.HTTPNotFound().to_dict()
713714

714715
def test_httpnow_alias_for_backwards_compat(self):
715-
assert testing.httpnow is falcon.util.http_now
716+
# Ensure that both the alias and decorated alias work
717+
assert (
718+
testing.httpnow is falcon.util.http_now
719+
or inspect.unwrap(testing.httpnow) is falcon.util.http_now
720+
)
716721

717722
def test_default_headers(self, app):
718723
resource = testing.SimpleTestResource()

0 commit comments

Comments
 (0)