Commit 6d4ed257 by Clinton Blackburn Committed by GitHub

Merge pull request #270 from edx/clintonb/course-bug-fixes

Course/CourseRun bug fixes
parents ed5957f6 5a9f1142
...@@ -467,13 +467,9 @@ class CourseRunSearchSerializerTests(TestCase): ...@@ -467,13 +467,9 @@ class CourseRunSearchSerializerTests(TestCase):
def test_data(self): def test_data(self):
course_run = CourseRunFactory() course_run = CourseRunFactory()
serializer = self.serialize_course_run(course_run)
course_run_key = CourseKey.from_string(course_run.key) course_run_key = CourseKey.from_string(course_run.key)
# NOTE: This serializer expects SearchQuerySet results, so we run a search on the newly-created object
# to generate such a result.
result = SearchQuerySet().models(CourseRun).filter(key=course_run.key)[0]
serializer = CourseRunSearchSerializer(result)
expected = { expected = {
'transcript_languages': [self.serialize_language(l) for l in course_run.transcript_languages.all()], 'transcript_languages': [self.serialize_language(l) for l in course_run.transcript_languages.all()],
'short_description': course_run.short_description, 'short_description': course_run.short_description,
...@@ -498,6 +494,18 @@ class CourseRunSearchSerializerTests(TestCase): ...@@ -498,6 +494,18 @@ class CourseRunSearchSerializerTests(TestCase):
} }
self.assertDictEqual(serializer.data, expected) self.assertDictEqual(serializer.data, expected)
def serialize_course_run(self, course_run):
""" Serializes the given `CourseRun` as a search result. """
result = SearchQuerySet().models(CourseRun).filter(key=course_run.key)[0]
serializer = CourseRunSearchSerializer(result)
return serializer
def test_data_without_serializers(self):
""" Verify a null `LevelType` is properly serialized as None. """
course_run = CourseRunFactory(course__level_type=None)
serializer = self.serialize_course_run(course_run)
self.assertEqual(serializer.data['level_type'], None)
class ProgramSearchSerializerTests(TestCase): class ProgramSearchSerializerTests(TestCase):
def test_data(self): def test_data(self):
......
...@@ -12,12 +12,12 @@ def remove_duplicate_courses(apps, schema_editor): ...@@ -12,12 +12,12 @@ def remove_duplicate_courses(apps, schema_editor):
' course_metadata_course AS c' ' course_metadata_course AS c'
' JOIN (' ' JOIN ('
' SELECT' ' SELECT'
' LOWER(key) AS key,' ' LOWER(`key`) AS `key`,'
' COUNT(1)' ' COUNT(1)'
' FROM' ' FROM'
' course_metadata_course' ' course_metadata_course'
' GROUP BY' ' GROUP BY'
' LOWER(key)' ' LOWER(`key`)'
' HAVING' ' HAVING'
' COUNT(1) > 1' ' COUNT(1) > 1'
' ) AS dupes ON dupes.key = LOWER(c.key)') ' ) AS dupes ON dupes.key = LOWER(c.key)')
......
...@@ -52,7 +52,7 @@ class BaseCourseIndex(OrganizationsMixin, BaseIndex): ...@@ -52,7 +52,7 @@ class BaseCourseIndex(OrganizationsMixin, BaseIndex):
organizations = indexes.MultiValueField(faceted=True) organizations = indexes.MultiValueField(faceted=True)
authoring_organizations = indexes.MultiValueField(faceted=True) authoring_organizations = indexes.MultiValueField(faceted=True)
sponsoring_organizations = indexes.MultiValueField(faceted=True) sponsoring_organizations = indexes.MultiValueField(faceted=True)
level_type = indexes.CharField(model_attr='level_type__name', null=True, faceted=True) level_type = indexes.CharField(null=True, faceted=True)
partner = indexes.CharField(model_attr='partner__short_code', null=True, faceted=True) partner = indexes.CharField(model_attr='partner__short_code', null=True, faceted=True)
def prepare_subjects(self, obj): def prepare_subjects(self, obj):
...@@ -67,6 +67,9 @@ class BaseCourseIndex(OrganizationsMixin, BaseIndex): ...@@ -67,6 +67,9 @@ class BaseCourseIndex(OrganizationsMixin, BaseIndex):
def prepare_sponsoring_organizations(self, obj): def prepare_sponsoring_organizations(self, obj):
return self._prepare_organizations(obj.sponsoring_organizations.all()) return self._prepare_organizations(obj.sponsoring_organizations.all())
def prepare_level_type(self, obj):
return obj.level_type.name if obj.level_type else None
class CourseIndex(BaseCourseIndex, indexes.Indexable): class CourseIndex(BaseCourseIndex, indexes.Indexable):
model = Course model = Course
......
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