Fix discussion_api to handle old threads

Some old threads do not have the pinned field set, which the thread
serializer should handle.
This commit is contained in:
Greg Price
2015-06-18 01:31:16 -04:00
parent 7c53400134
commit 6505713302
2 changed files with 15 additions and 0 deletions

View File

@@ -180,6 +180,10 @@ class ThreadSerializer(_ContentSerializer):
# type is an invalid class attribute name, so we must declare a
# different name above and modify it here
self.fields["type"] = self.fields.pop("type_")
# Compensate for the fact that some threads in the comments service do
# not have the pinned field set
if self.object and self.object.get("pinned") is None:
self.object["pinned"] = False
def get_group_name(self, obj):
"""Returns the name of the group identified by the thread's group_id."""

View File

@@ -212,6 +212,17 @@ class ThreadSerializerSerializationTest(SerializerTestMixin, ModuleStoreTestCase
})
self.assertEqual(self.serialize(thread), expected)
def test_pinned_missing(self):
"""
Make sure that older threads in the comments service without the pinned
field do not break serialization
"""
thread_data = self.make_cs_content({})
del thread_data["pinned"]
self.register_get_thread_response(thread_data)
serialized = self.serialize(Thread(id=thread_data["id"]))
self.assertEqual(serialized["pinned"], False)
def test_group(self):
cohort = CohortFactory.create(course_id=self.course.id)
serialized = self.serialize(self.make_cs_content({"group_id": cohort.id}))