Skip to content

Commit 07cde59

Browse files
committed
Add orm_deprecated function and related tests
1 parent 7cce8f9 commit 07cde59

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

flask_mongoengine/decorators.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
"""Collection of project wide decorators."""
12
import functools
23
import logging
4+
import warnings
35

46
try:
57
import wtforms # noqa
@@ -23,3 +25,25 @@ def wrapped(*args, **kwargs):
2325
return func(*args, **kwargs)
2426

2527
return wrapped
28+
29+
30+
def orm_deprecated(func):
31+
"""Warning about usage of deprecated functions, that will be removed in the future."""
32+
33+
@functools.wraps(func)
34+
def wrapped(*args, **kwargs):
35+
# TODO: Insert URL
36+
warnings.warn(
37+
(
38+
f"ORM module and function '{func.__name__}' are deprecated and will be "
39+
"removed in version 3.0.0. Please switch to form generation from full "
40+
"model nesting. Support and bugfixes are not available for stalled code. "
41+
"Please read: "
42+
),
43+
DeprecationWarning,
44+
stacklevel=2,
45+
)
46+
47+
return func(*args, **kwargs)
48+
49+
return wrapped

tests/test_decorators.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Tests for project wide decorators."""
2+
from flask_mongoengine.decorators import orm_deprecated
3+
4+
5+
def test__orm_deprecated(recwarn):
6+
@orm_deprecated
7+
def func(a, b):
8+
"""Function example."""
9+
return a + b
10+
11+
assert func(1, 1) == 2
12+
assert str(recwarn.list[0].message) == (
13+
"ORM module and function 'func' are deprecated and will be removed in version 3.0.0. "
14+
"Please switch to form generation from full model nesting. "
15+
"Support and bugfixes are not available for stalled code. "
16+
"Please read: "
17+
)

0 commit comments

Comments
 (0)