Commit 013b7f46 by Renzo Lucioni

Allow ProgramSearchSerializer to deal with missing organization bodies

parent 98c38ede
......@@ -547,7 +547,7 @@ class ProgramSearchSerializer(HaystackSerializer):
def get_authoring_organizations(self, program):
organizations = program.organization_bodies
return [json.loads(organization) for organization in organizations]
return [json.loads(organization) for organization in organizations] if organizations else []
class Meta:
field_aliases = COMMON_SEARCH_FIELD_ALIASES
......
......@@ -548,3 +548,23 @@ class ProgramSearchSerializerTests(TestCase):
'status': program.status,
}
self.assertDictEqual(serializer.data, expected)
def test_organization_bodies_missing(self):
program = ProgramFactory()
result = SearchQuerySet().models(Program).filter(uuid=program.uuid)[0]
result.organization_bodies = None
serializer = ProgramSearchSerializer(result)
expected = {
'uuid': str(program.uuid),
'title': program.title,
'subtitle': program.subtitle,
'type': program.type.name,
'marketing_url': program.marketing_url,
'authoring_organizations': [],
'content_type': 'program',
'card_image_url': program.card_image_url,
'status': program.status,
}
self.assertDictEqual(serializer.data, expected)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment