Skip to content

Commit 84bd0c7

Browse files
committed
added test for serialising functions in migrations
1 parent 2593611 commit 84bd0c7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/apps/migrations/auto/test_serialisation.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from piccolo.columns.reference import LazyTableReference
66

77

8+
def example_function():
9+
pass
10+
11+
812
class TestSerialiseParams(TestCase):
913
def test_time(self):
1014
serialised = serialise_params(params={"default": TimeNow()})
@@ -58,3 +62,31 @@ def test_lazy_table_reference(self):
5862
serialised.extra_definitions[0].__str__(),
5963
'class Manager(Table, tablename="manager"): pass',
6064
)
65+
66+
def test_function(self):
67+
serialised = serialise_params(params={"default": example_function})
68+
self.assertTrue(
69+
serialised.params["default"].__repr__() == "example_function"
70+
)
71+
72+
self.assertTrue(len(serialised.extra_imports) == 1)
73+
self.assertEqual(
74+
serialised.extra_imports[0].__str__(),
75+
(
76+
"from tests.apps.migrations.auto.test_serialisation import "
77+
"example_function"
78+
),
79+
)
80+
81+
self.assertTrue(len(serialised.extra_definitions) == 0)
82+
83+
def test_lambda(self):
84+
"""
85+
Make sure lambda functions are rejected.
86+
"""
87+
with self.assertRaises(ValueError) as manager:
88+
serialise_params(params={"default": lambda x: x + 1})
89+
90+
self.assertEqual(
91+
manager.exception.__str__(), "Lambdas can't be serialised"
92+
)

0 commit comments

Comments
 (0)