Commit 64e29046 by Renzo Lucioni Committed by GitHub

Merge pull request #256 from edx/renzo/fix-no-orgs

Allow ProgramSearchSerializer to deal with missing organization bodies
parents 98c38ede 013b7f46
...@@ -547,7 +547,7 @@ class ProgramSearchSerializer(HaystackSerializer): ...@@ -547,7 +547,7 @@ class ProgramSearchSerializer(HaystackSerializer):
def get_authoring_organizations(self, program): def get_authoring_organizations(self, program):
organizations = program.organization_bodies 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: class Meta:
field_aliases = COMMON_SEARCH_FIELD_ALIASES field_aliases = COMMON_SEARCH_FIELD_ALIASES
......
...@@ -548,3 +548,23 @@ class ProgramSearchSerializerTests(TestCase): ...@@ -548,3 +548,23 @@ class ProgramSearchSerializerTests(TestCase):
'status': program.status, 'status': program.status,
} }
self.assertDictEqual(serializer.data, expected) 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