Commit 7da8b084 by Ahsan Ulhaq

MicroMasters logo showing on a non-MM course discovery card

ECOM-6372
parent cba37b58
...@@ -200,6 +200,46 @@ class CourseRunSearchViewSetTests(DefaultPartnerMixin, SerializationMixin, Login ...@@ -200,6 +200,46 @@ class CourseRunSearchViewSetTests(DefaultPartnerMixin, SerializationMixin, Login
""" Verify the unpublished programs do not show in the program_types representation. """ """ Verify the unpublished programs do not show in the program_types representation. """
self._test_exclude_program_types(ProgramStatus.Unpublished) self._test_exclude_program_types(ProgramStatus.Unpublished)
@ddt.data(
[{'title': 'Software Testing', 'excluded': True}],
[{'title': 'Software Testing', 'excluded': True}, {'title': 'Software Testing 2', 'excluded': True}],
[{'title': 'Software Testing', 'excluded': False}, {'title': 'Software Testing 2', 'excluded': False}],
[{'title': 'Software Testing', 'excluded': True}, {'title': 'Software Testing 2', 'excluded': True},
{'title': 'Software Testing 3', 'excluded': False}],
)
def test_excluded_course_run(self, course_runs):
course_list = []
course_run_list = []
excluded_course_run_list = []
non_excluded_course_run_list = []
for run in course_runs:
course_run = CourseRunFactory(course__partner=self.partner, course__title=run['title'],
status=CourseRunStatus.Published)
course_list.append(course_run.course)
course_run_list.append(course_run)
if run['excluded']:
excluded_course_run_list.append(course_run)
else:
non_excluded_course_run_list.append(course_run)
ProgramFactory(courses=course_list, status=ProgramStatus.Active, excluded_course_runs=excluded_course_run_list)
with self.assertNumQueries(6):
response = self.get_search_response('software', faceted=False)
self.assertEqual(response.status_code, 200)
response_data = response.json()
self.assertEqual(response_data['count'], len(course_run_list))
for result in response_data['results']:
for course_run in excluded_course_run_list:
if result.get('title') == course_run.title:
self.assertEqual(result.get('program_types'), [])
for course_run in non_excluded_course_run_list:
if result.get('title') == course_run.title:
self.assertEqual(result.get('program_types'), course_run.program_types)
def _test_exclude_program_types(self, program_status): def _test_exclude_program_types(self, program_status):
""" Verify that programs with the provided type do not show in the program_types representation. """ """ Verify that programs with the provided type do not show in the program_types representation. """
course_run = CourseRunFactory(course__partner=self.partner, course__title='Software Testing', course_run = CourseRunFactory(course__partner=self.partner, course__title='Software Testing',
......
...@@ -388,8 +388,11 @@ class CourseRun(TimeStampedModel): ...@@ -388,8 +388,11 @@ class CourseRun(TimeStampedModel):
so we don't identify that program type if not available so we don't identify that program type if not available
""" """
program_statuses_to_exclude = (ProgramStatus.Unpublished, ProgramStatus.Deleted) program_statuses_to_exclude = (ProgramStatus.Unpublished, ProgramStatus.Deleted)
all_programs = [program for program in self.programs.exclude(status__in=program_statuses_to_exclude)] associated_programs = []
return [program.type.name for program in all_programs] for program in self.programs.exclude(status__in=program_statuses_to_exclude):
if self not in program.excluded_course_runs.all():
associated_programs.append(program)
return [program.type.name for program in associated_programs]
@property @property
def marketing_url(self): def marketing_url(self):
......
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