From c68af9d21ef0c3e2c0dabeb9dba4a0ce3b9e8537 Mon Sep 17 00:00:00 2001 From: jsa Date: Sun, 1 Nov 2015 12:39:23 -0500 Subject: [PATCH] Show xseries upsell even if the course is not yet in session ECOM-2780 --- common/djangoapps/student/tests/tests.py | 26 ++++++++++++++++++++++++ common/djangoapps/student/views.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/student/tests/tests.py b/common/djangoapps/student/tests/tests.py index cc03c370c3..9b03546e05 100644 --- a/common/djangoapps/student/tests/tests.py +++ b/common/djangoapps/student/tests/tests.py @@ -1033,6 +1033,32 @@ class DashboardTestXSeriesPrograms(ModuleStoreTestCase, ProgramsApiConfigMixin): else: self.assertIn('xseries-border-btn', response.content) + @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) + @ddt.data((-2, -1), (-1, 1), (1, 2)) + @ddt.unpack + def test_start_end_offsets(self, start_days_offset, end_days_offset): + """Test that the xseries upsell messaging displays whether the course + has not yet started, is in session, or has already ended. + """ + self.course_1.start = datetime.now(pytz.UTC) + timedelta(days=start_days_offset) + self.course_1.end = datetime.now(pytz.UTC) + timedelta(days=end_days_offset) + self.update_course(self.course_1, self.user.id) + CourseEnrollment.enroll(self.user, self.course_1.id, mode='verified') + + self.client.login(username="jack", password="test") + self.create_config(enabled=True, enable_student_dashboard=True) + + with patch( + 'student.views.get_course_programs_for_dashboard', + return_value=self._create_program_data([(self.course_1.id, 'active')]) + ) as mock_get_programs: + response = self.client.get(reverse('dashboard')) + # ensure that our course id was included in the API call regardless of start/end dates + __, course_ids = mock_get_programs.call_args[0] + self.assertEqual(list(course_ids), [self.course_1.id]) + # count total courses appearing on student dashboard + self._assert_responses(response, 1) + @ddt.data( ('unpublished', 'unpublished', 'unpublished', 0), ('active', 'unpublished', 'unpublished', 1), diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 97df4883e9..1e02fe1514 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -581,7 +581,7 @@ def dashboard(request): # program-related information on the dashboard view. course_programs = {} if is_student_dashboard_programs_enabled(): - course_programs = _get_course_programs(user, show_courseware_links_for) + course_programs = _get_course_programs(user, [enrollment.course_id for enrollment in course_enrollments]) # Construct a dictionary of course mode information # used to render the course list. We re-use the course modes dict