Skip to content

Commit 4c05132

Browse files
committed
Add test for nested serializer
1 parent 0ad048c commit 4c05132

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/endpoints/test_plugin_list.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77

88
class PluginListTestCase(BaseCMSRestTestCase):
9+
maxDiff = None
10+
911
def test_get(self):
1012
from cms.plugin_pool import plugin_pool
1113

@@ -22,8 +24,17 @@ def test_get(self):
2224
"json": {"type": "object"},
2325
"float": {"type": "number"},
2426
"title": {"enum": ["title", "subtitle", "header"], "type": "string"},
27+
"kvp": {
28+
"properties": {
29+
"prop1": {"type": "string"},
30+
"prop2": {"type": "string"},
31+
"prop3": {"type": "string"},
32+
},
33+
"type": "object",
34+
},
2535
},
2636
}
37+
2738
# GET
2839
response = self.client.get(reverse("plugin-list"))
2940
self.assertEqual(response.status_code, 200)

tests/test_app/serializers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class CustomSerializer(serializers.Serializer):
1111
)
1212
json = serializers.JSONField()
1313

14+
class KeyValuePairSerializer(serializers.Serializer):
15+
prop1 = serializers.CharField()
16+
prop2 = serializers.CharField()
17+
prop3 = serializers.CharField()
18+
19+
kvp = KeyValuePairSerializer()
20+
1421
def to_representation(self, instance):
1522
return {
1623
"id": instance.id,
@@ -25,4 +32,9 @@ def to_representation(self, instance):
2532
False,
2633
None,
2734
],
35+
"kvp": {
36+
"prop1": "value1",
37+
"prop2": "value2",
38+
"prop3": "value3",
39+
},
2840
}

0 commit comments

Comments
 (0)