From 99659ce3d44b73afb8a499ecfb9659e095d2fea1 Mon Sep 17 00:00:00 2001 From: arbisoft Date: Thu, 8 Jan 2015 14:52:31 +0500 Subject: [PATCH 01/10] ECOM-528 added donation support for verified courses --- .../djangoapps/student/tests/test_recent_enrollments.py | 8 ++++---- common/djangoapps/student/views.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index ccba26e903..6206ca4f86 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -112,10 +112,10 @@ class TestRecentEnrollments(ModuleStoreTestCase): recent_course_list = _get_recently_enrolled_courses(courses_list) self.assertEqual(len(recent_course_list), 5) - self.assertEqual(recent_course_list[1], courses[0]) - self.assertEqual(recent_course_list[2], courses[1]) - self.assertEqual(recent_course_list[3], courses[2]) - self.assertEqual(recent_course_list[4], courses[3]) + self.assertEqual(recent_course_list[1][0], courses[0]) + self.assertEqual(recent_course_list[2][0], courses[1]) + self.assertEqual(recent_course_list[3][0], courses[2]) + self.assertEqual(recent_course_list[4][0], courses[3]) def test_dashboard_rendering(self): """ diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index f5f75485c8..6d000c299d 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -712,9 +712,9 @@ def _create_recent_enrollment_message(course_enrollment_pairs, course_modes): { "course_id": course.id, "course_name": course.display_name, - "allow_donation": _allow_donation(course_modes, course.id) + "allow_donation": _allow_donation(course_modes, course.id, enrollment) } - for course in recently_enrolled_courses + for course, enrollment in recently_enrolled_courses ] return render_to_string( @@ -745,7 +745,7 @@ def _get_recently_enrolled_courses(course_enrollment_pairs): ] -def _allow_donation(course_modes, course_id): +def _allow_donation(course_modes, course_id, enrollment): """Determines if the dashboard will request donations for the given course. Check if donations are configured for the platform, and if the current course is accepting donations. @@ -761,7 +761,7 @@ def _allow_donation(course_modes, course_id): donations_enabled = DonationConfiguration.current().enabled is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) has_payment_option = CourseMode.has_payment_options(course_id) - return donations_enabled and not is_verified_mode and not has_payment_option + return donations_enabled and (not is_verified_mode or (is_verified_mode and enrollment.mode in ['audit', 'honor']) )and not has_payment_option def try_change_enrollment(request): From 7bdbf8f17cb171f28931d2bf66951b792933489f Mon Sep 17 00:00:00 2001 From: arbisoft Date: Fri, 9 Jan 2015 00:02:04 +0500 Subject: [PATCH 02/10] ECOM-528 added donation support for verified courses --- .../student/tests/test_recent_enrollments.py | 110 ++++++++++++++++-- common/djangoapps/student/views.py | 9 +- 2 files changed, 109 insertions(+), 10 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index 6206ca4f86..9e464a5ce6 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -43,7 +43,7 @@ class TestRecentEnrollments(ModuleStoreTestCase): # New Course course_location = locator.CourseLocator('Org1', 'Course1', 'Run1') - self.course, _ = self._create_course_and_enrollment(course_location) + self.course, self.enrollment = self._create_course_and_enrollment(course_location) def _create_course_and_enrollment(self, course_location): """ Creates a course and associated enrollment. """ @@ -127,15 +127,43 @@ class TestRecentEnrollments(ModuleStoreTestCase): self.assertContains(response, "Thank you for enrolling in") @ddt.data( - (['audit', 'honor', 'verified'], False), - (['professional'], False), - (['verified'], False), - (['audit'], True), - (['honor'], True), - ([], True) + # (['audit', 'honor'], 'honor', False), + (['professional'], 'honor', True), + (['verified'], 'honor', True), + (['professional', 'verified'], 'honor', True), + (['audit', 'honor', 'professional'], 'honor', True), + (['audit', 'honor', 'verified'], 'honor', True), + (['audit', 'honor', 'verified', 'professional'], 'honor', True), + # (['audit'], 'honor', False), + # (['honor'], 'honor', False), + # ([], 'honor', False), + # + # (['audit', 'honor'], 'audit', False), + # (['professional'], 'audit', True), + # (['verified'], 'audit', True), + # (['professional', 'verified'], 'audit', True), + # (['audit', 'honor', 'professional'], 'audit', True), + # (['audit', 'honor', 'verified'], 'audit', True), + # (['audit', 'honor', 'verified', 'professional'], 'audit', True), + # (['audit'], 'audit', True), + # (['honor'], 'audit', True), + # ([], 'audit', True), + + # (['audit', 'honor'], 'verified', False), + (['professional'], 'verified', False), + (['verified'], 'verified', False), + (['professional', 'verified'], 'verified', False), + (['audit', 'honor', 'professional'], 'verified', False), + (['audit', 'honor', 'verified'], 'verified', False), + (['audit', 'honor', 'verified', 'professional'], 'verified', False), + # (['audit'], 'verified', False), + # (['honor'], 'verified', False), + # ([], 'verified', False) ) @ddt.unpack - def test_donate_button(self, course_modes, show_donate): + def test_donate_button(self, course_modes, enrollment_mode, show_donate): + from nose.tools import set_trace; + set_trace() # Enable the enrollment success message self._configure_message_timeout(10000) @@ -146,6 +174,9 @@ class TestRecentEnrollments(ModuleStoreTestCase): for mode in course_modes: CourseModeFactory(mode_slug=mode, course_id=self.course.id) + self.enrollment.mode = enrollment_mode + self.enrollment.save() + # Check that the donate button is or is not displayed self.client.login(username=self.student.username, password=self.PASSWORD) response = self.client.get(reverse("dashboard")) @@ -155,6 +186,69 @@ class TestRecentEnrollments(ModuleStoreTestCase): else: self.assertNotContains(response, "donate-container") + # @ddt.data( + # (['audit', 'honor'], True), + # (['professional'], True), + # (['verified'], True), + # (['audit'], True), + # (['honor'], True), + # ([], True) + # ) + # @ddt.unpack + # def test_donate_button_enrollment_audit(self, course_modes, show_donate): + # from nose.tools import set_trace; set_trace() + # # Enable the enrollment success message + # self._configure_message_timeout(10000) + # + # # Enable donations + # DonationConfiguration(enabled=True).save() + # + # # Create the course mode(s) + # for mode in course_modes: + # CourseModeFactory(mode_slug=mode, course_id=self.course.id) + # self.enrollment.mode = 'audit' + # self.enrollment.save() + # # Check that the donate button is or is not displayed + # self.client.login(username=self.student.username, password=self.PASSWORD) + # response = self.client.get(reverse("dashboard")) + # + # if show_donate: + # self.assertContains(response, "donate-container") + # else: + # self.assertNotContains(response, "donate-container") + # + # @ddt.data( + # (['audit', 'honor'], True), + # (['professional'], True), + # (['verified'], True), + # (['audit'], True), + # (['honor'], True), + # ([], True) + # ) + # @ddt.unpack + # def test_donate_button_verified_courses(self, course_modes, show_donate): + # from nose.tools import set_trace; set_trace() + # # Enable the enrollment success message + # self._configure_message_timeout(10000) + # + # # Enable donations + # DonationConfiguration(enabled=True).save() + # + # # Create the course mode(s) + # for mode in course_modes: + # CourseModeFactory(mode_slug=mode, course_id=self.course.id) + # + # self.enrollment.mode = '' + # + # # Check that the donate button is or is not displayed + # self.client.login(username=self.student.username, password=self.PASSWORD) + # response = self.client.get(reverse("dashboard")) + # + # if show_donate: + # self.assertContains(response, "donate-container") + # else: + # self.assertNotContains(response, "donate-container") + def test_donate_button_honor_with_price(self): # Enable the enrollment success message and donations self._configure_message_timeout(10000) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 6d000c299d..f799710a9b 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -738,7 +738,7 @@ def _get_recently_enrolled_courses(course_enrollment_pairs): seconds = DashboardConfiguration.current().recent_enrollment_time_delta time_delta = (datetime.datetime.now(UTC) - datetime.timedelta(seconds=seconds)) return [ - course for course, enrollment in course_enrollment_pairs + (course, enrollment) for course, enrollment in course_enrollment_pairs # If the enrollment has no created date, we are explicitly excluding the course # from the list of recent enrollments. if enrollment.is_active and enrollment.created > time_delta @@ -758,10 +758,15 @@ def _allow_donation(course_modes, course_id, enrollment): True if the course is allowing donations. """ + # from nose.tools import set_trace; + # set_trace() donations_enabled = DonationConfiguration.current().enabled is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) has_payment_option = CourseMode.has_payment_options(course_id) - return donations_enabled and (not is_verified_mode or (is_verified_mode and enrollment.mode in ['audit', 'honor']) )and not has_payment_option + return_val = donations_enabled and (not is_verified_mode or (is_verified_mode and enrollment.mode in ['audit', 'honor'])) and not has_payment_option + return_val + #TODO Hard coded for the time being + return True def try_change_enrollment(request): From 7eb8195c2301c0bee46e96f9b6d459dc32f0608f Mon Sep 17 00:00:00 2001 From: arbisoft Date: Fri, 9 Jan 2015 12:31:33 +0500 Subject: [PATCH 03/10] ECOM-528 added donation support for verified courses --- common/djangoapps/student/views.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index f799710a9b..c8ddfa1e16 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -763,10 +763,17 @@ def _allow_donation(course_modes, course_id, enrollment): donations_enabled = DonationConfiguration.current().enabled is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) has_payment_option = CourseMode.has_payment_options(course_id) - return_val = donations_enabled and (not is_verified_mode or (is_verified_mode and enrollment.mode in ['audit', 'honor'])) and not has_payment_option - return_val - #TODO Hard coded for the time being - return True + return_val = False + if donations_enabled: + if not is_verified_mode: + if not has_payment_option: + return_val = True + else: + if enrollment.mode in ['audit', 'honor']: + return_val = True + # return_val = donations_enabled and ((not is_verified_mode and not has_payment_option) or (is_verified_mode and enrollment.mode in ['audit', 'honor'])) + # return_val = donations_enabled and not is_verified_mode and not has_payment_option + return return_val def try_change_enrollment(request): From 866ddc22e903572aed1f797c4d5c5b2be0afeff1 Mon Sep 17 00:00:00 2001 From: Awais Date: Fri, 9 Jan 2015 15:17:27 +0500 Subject: [PATCH 04/10] ECOM-528 refactor the code. --- common/djangoapps/student/tests/test_recent_enrollments.py | 2 -- common/djangoapps/student/views.py | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index 9e464a5ce6..265ba76101 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -162,8 +162,6 @@ class TestRecentEnrollments(ModuleStoreTestCase): ) @ddt.unpack def test_donate_button(self, course_modes, enrollment_mode, show_donate): - from nose.tools import set_trace; - set_trace() # Enable the enrollment success message self._configure_message_timeout(10000) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index c8ddfa1e16..e62c1397e2 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -758,16 +758,13 @@ def _allow_donation(course_modes, course_id, enrollment): True if the course is allowing donations. """ - # from nose.tools import set_trace; - # set_trace() donations_enabled = DonationConfiguration.current().enabled is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) has_payment_option = CourseMode.has_payment_options(course_id) return_val = False if donations_enabled: - if not is_verified_mode: - if not has_payment_option: - return_val = True + if not (is_verified_mode and has_payment_option): + return_val = True else: if enrollment.mode in ['audit', 'honor']: return_val = True From 507d7b1a1f6862779dd92195d425c13c60b9725e Mon Sep 17 00:00:00 2001 From: Awais Date: Fri, 9 Jan 2015 16:26:35 +0500 Subject: [PATCH 05/10] ECOM-528 refactor the code. --- common/djangoapps/student/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index e62c1397e2..b504540625 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -763,8 +763,9 @@ def _allow_donation(course_modes, course_id, enrollment): has_payment_option = CourseMode.has_payment_options(course_id) return_val = False if donations_enabled: - if not (is_verified_mode and has_payment_option): - return_val = True + if not is_verified_mode: + if not has_payment_option: + return_val = True else: if enrollment.mode in ['audit', 'honor']: return_val = True From fd76f3754cefceccb76acba1564036e764a5dd51 Mon Sep 17 00:00:00 2001 From: arbisoft Date: Fri, 9 Jan 2015 16:29:35 +0500 Subject: [PATCH 06/10] ECOM-528 added test cases --- .../student/tests/test_recent_enrollments.py | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index 9e464a5ce6..9e2f87f5dc 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -127,38 +127,38 @@ class TestRecentEnrollments(ModuleStoreTestCase): self.assertContains(response, "Thank you for enrolling in") @ddt.data( - # (['audit', 'honor'], 'honor', False), + (['audit', 'honor'], 'honor', True), (['professional'], 'honor', True), (['verified'], 'honor', True), (['professional', 'verified'], 'honor', True), (['audit', 'honor', 'professional'], 'honor', True), (['audit', 'honor', 'verified'], 'honor', True), (['audit', 'honor', 'verified', 'professional'], 'honor', True), - # (['audit'], 'honor', False), - # (['honor'], 'honor', False), - # ([], 'honor', False), - # - # (['audit', 'honor'], 'audit', False), - # (['professional'], 'audit', True), - # (['verified'], 'audit', True), - # (['professional', 'verified'], 'audit', True), - # (['audit', 'honor', 'professional'], 'audit', True), - # (['audit', 'honor', 'verified'], 'audit', True), - # (['audit', 'honor', 'verified', 'professional'], 'audit', True), - # (['audit'], 'audit', True), - # (['honor'], 'audit', True), - # ([], 'audit', True), + (['audit'], 'honor', True), + (['honor'], 'honor', True), + ([], 'honor', True), - # (['audit', 'honor'], 'verified', False), + (['audit', 'honor'], 'audit', True), + (['professional'], 'audit', True), + (['verified'], 'audit', True), + (['professional', 'verified'], 'audit', True), + (['audit', 'honor', 'professional'], 'audit', True), + (['audit', 'honor', 'verified'], 'audit', True), + (['audit', 'honor', 'verified', 'professional'], 'audit', True), + (['audit'], 'audit', True), + (['honor'], 'audit', True), + ([], 'audit', True), + + (['audit', 'honor'], 'verified', False), (['professional'], 'verified', False), (['verified'], 'verified', False), (['professional', 'verified'], 'verified', False), (['audit', 'honor', 'professional'], 'verified', False), (['audit', 'honor', 'verified'], 'verified', False), (['audit', 'honor', 'verified', 'professional'], 'verified', False), - # (['audit'], 'verified', False), - # (['honor'], 'verified', False), - # ([], 'verified', False) + (['audit'], 'verified', False), + (['honor'], 'verified', False), + ([], 'verified', False) ) @ddt.unpack def test_donate_button(self, course_modes, enrollment_mode, show_donate): From 36626a2b8ba111ff214b5292aabe315d47668c81 Mon Sep 17 00:00:00 2001 From: arbisoft Date: Fri, 9 Jan 2015 17:55:22 +0500 Subject: [PATCH 07/10] ECOM-528 added test cases --- .../student/tests/test_recent_enrollments.py | 156 +++++++----------- common/djangoapps/student/views.py | 4 - 2 files changed, 61 insertions(+), 99 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index 9e2f87f5dc..832268b56b 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -127,43 +127,72 @@ class TestRecentEnrollments(ModuleStoreTestCase): self.assertContains(response, "Thank you for enrolling in") @ddt.data( - (['audit', 'honor'], 'honor', True), - (['professional'], 'honor', True), - (['verified'], 'honor', True), - (['professional', 'verified'], 'honor', True), - (['audit', 'honor', 'professional'], 'honor', True), - (['audit', 'honor', 'verified'], 'honor', True), - (['audit', 'honor', 'verified', 'professional'], 'honor', True), - (['audit'], 'honor', True), - (['honor'], 'honor', True), + #Register as an honor in any course modes with no payment option + ([('audit', 0), ('honor', 0)], 'honor', True), + # ([('professional', 0)], 'honor', True), #This can not be the case as verified courses always has min_price + # ([('verified', 0)], 'honor', True), #This can not be the case as verified courses always has min_price + # ([('professional', 0), ('verified', 0)], 'honor', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 0), ('professional', 0)], 'honor', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 0), ('verified', 0)], 'honor', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 0), ('verified', 0), ('professional', 0)], 'honor', True), #This can not be the case as verified courses always has min_price + ([('audit', 0)], 'honor', True), + ([('honor', 0)], 'honor', True), + ([], 'honor', True), + #Register as an honor in any course modes which has payment option + ([('audit', 0), ('honor', 10)], 'honor', False), + ([('professional', 20)], 'honor', True), + ([('verified', 20)], 'honor', True), + ([('professional', 20), ('verified', 20)], 'honor', True), + ([('audit', 0), ('honor', 5), ('professional', 20)], 'honor', True), + ([('audit', 0), ('honor', 10), ('verified', 20)], 'honor', True), + ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'honor', True), + ([('audit', 10)], 'honor', False), + ([('honor', 10)], 'honor', False), ([], 'honor', True), - (['audit', 'honor'], 'audit', True), - (['professional'], 'audit', True), - (['verified'], 'audit', True), - (['professional', 'verified'], 'audit', True), - (['audit', 'honor', 'professional'], 'audit', True), - (['audit', 'honor', 'verified'], 'audit', True), - (['audit', 'honor', 'verified', 'professional'], 'audit', True), - (['audit'], 'audit', True), - (['honor'], 'audit', True), + + #Register as an audit in any course modes with no payment option + ([('audit', 0), ('honor', 0)], 'audit', True), + # ([('professional', 0)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('verified', 0)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('professional', 0), ('verified', 0)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 0), ('professional', 0)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 0), ('verified', 0)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 0), ('verified', 0), ('professional', 0)], 'audit', True), #This can not be the case as verified courses always has min_price + ([('audit', 0)], 'audit', True), + ([('honor', 0)], 'audit', True), + ([], 'audit', True), + #Register as an audit in any course modes which has payment option + ([('audit', 0), ('honor', 10)], 'audit', False), + # ([('professional', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('verified', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('professional', 20), ('verified', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 5), ('professional', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 10), ('verified', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + # ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + ([('audit', 10)], 'audit', False), + ([('honor', 10)], 'audit', False), ([], 'audit', True), - (['audit', 'honor'], 'verified', False), - (['professional'], 'verified', False), - (['verified'], 'verified', False), - (['professional', 'verified'], 'verified', False), - (['audit', 'honor', 'professional'], 'verified', False), - (['audit', 'honor', 'verified'], 'verified', False), - (['audit', 'honor', 'verified', 'professional'], 'verified', False), - (['audit'], 'verified', False), - (['honor'], 'verified', False), - ([], 'verified', False) + + + #Register as a verified in any course modes which has payment option + ([('audit', 0), ('honor', 10)], 'verified', False), + ([('professional', 20)], 'verified', False), + ([('verified', 20)], 'verified', False), + ([('professional', 20), ('verified', 20)], 'verified', False), + ([('audit', 0), ('honor', 5), ('professional', 20)], 'verified', False), + ([('audit', 0), ('honor', 10), ('verified', 20)], 'verified', False), + ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'verified', False), + ([('audit', 10)], 'verified', False), + ([('honor', 10)], 'verified', False), + # ([], 'audit', True), + ) @ddt.unpack def test_donate_button(self, course_modes, enrollment_mode, show_donate): - from nose.tools import set_trace; - set_trace() + # from nose.tools import set_trace; + # set_trace() # Enable the enrollment success message self._configure_message_timeout(10000) @@ -171,8 +200,8 @@ class TestRecentEnrollments(ModuleStoreTestCase): DonationConfiguration(enabled=True).save() # Create the course mode(s) - for mode in course_modes: - CourseModeFactory(mode_slug=mode, course_id=self.course.id) + for mode, min_price in course_modes: + CourseModeFactory(mode_slug=mode, course_id=self.course.id, min_price=min_price) self.enrollment.mode = enrollment_mode self.enrollment.save() @@ -186,69 +215,6 @@ class TestRecentEnrollments(ModuleStoreTestCase): else: self.assertNotContains(response, "donate-container") - # @ddt.data( - # (['audit', 'honor'], True), - # (['professional'], True), - # (['verified'], True), - # (['audit'], True), - # (['honor'], True), - # ([], True) - # ) - # @ddt.unpack - # def test_donate_button_enrollment_audit(self, course_modes, show_donate): - # from nose.tools import set_trace; set_trace() - # # Enable the enrollment success message - # self._configure_message_timeout(10000) - # - # # Enable donations - # DonationConfiguration(enabled=True).save() - # - # # Create the course mode(s) - # for mode in course_modes: - # CourseModeFactory(mode_slug=mode, course_id=self.course.id) - # self.enrollment.mode = 'audit' - # self.enrollment.save() - # # Check that the donate button is or is not displayed - # self.client.login(username=self.student.username, password=self.PASSWORD) - # response = self.client.get(reverse("dashboard")) - # - # if show_donate: - # self.assertContains(response, "donate-container") - # else: - # self.assertNotContains(response, "donate-container") - # - # @ddt.data( - # (['audit', 'honor'], True), - # (['professional'], True), - # (['verified'], True), - # (['audit'], True), - # (['honor'], True), - # ([], True) - # ) - # @ddt.unpack - # def test_donate_button_verified_courses(self, course_modes, show_donate): - # from nose.tools import set_trace; set_trace() - # # Enable the enrollment success message - # self._configure_message_timeout(10000) - # - # # Enable donations - # DonationConfiguration(enabled=True).save() - # - # # Create the course mode(s) - # for mode in course_modes: - # CourseModeFactory(mode_slug=mode, course_id=self.course.id) - # - # self.enrollment.mode = '' - # - # # Check that the donate button is or is not displayed - # self.client.login(username=self.student.username, password=self.PASSWORD) - # response = self.client.get(reverse("dashboard")) - # - # if show_donate: - # self.assertContains(response, "donate-container") - # else: - # self.assertNotContains(response, "donate-container") - def test_donate_button_honor_with_price(self): # Enable the enrollment success message and donations self._configure_message_timeout(10000) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index c8ddfa1e16..085a33770f 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -758,8 +758,6 @@ def _allow_donation(course_modes, course_id, enrollment): True if the course is allowing donations. """ - # from nose.tools import set_trace; - # set_trace() donations_enabled = DonationConfiguration.current().enabled is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) has_payment_option = CourseMode.has_payment_options(course_id) @@ -771,8 +769,6 @@ def _allow_donation(course_modes, course_id, enrollment): else: if enrollment.mode in ['audit', 'honor']: return_val = True - # return_val = donations_enabled and ((not is_verified_mode and not has_payment_option) or (is_verified_mode and enrollment.mode in ['audit', 'honor'])) - # return_val = donations_enabled and not is_verified_mode and not has_payment_option return return_val From 4dfabe9eb07e42d13724c66b92a2b5687b74e887 Mon Sep 17 00:00:00 2001 From: arbisoft Date: Fri, 9 Jan 2015 20:10:19 +0500 Subject: [PATCH 08/10] ECOM-528 removed the commented code in test cases --- .../student/tests/test_recent_enrollments.py | 31 ++----------------- common/djangoapps/student/views.py | 1 + 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index 832268b56b..f7511d12c5 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -129,53 +129,32 @@ class TestRecentEnrollments(ModuleStoreTestCase): @ddt.data( #Register as an honor in any course modes with no payment option ([('audit', 0), ('honor', 0)], 'honor', True), - # ([('professional', 0)], 'honor', True), #This can not be the case as verified courses always has min_price - # ([('verified', 0)], 'honor', True), #This can not be the case as verified courses always has min_price - # ([('professional', 0), ('verified', 0)], 'honor', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 0), ('professional', 0)], 'honor', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 0), ('verified', 0)], 'honor', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 0), ('verified', 0), ('professional', 0)], 'honor', True), #This can not be the case as verified courses always has min_price ([('audit', 0)], 'honor', True), ([('honor', 0)], 'honor', True), ([], 'honor', True), #Register as an honor in any course modes which has payment option ([('audit', 0), ('honor', 10)], 'honor', False), + ([('audit', 10), ('honor', 0)], 'honor', False), ([('professional', 20)], 'honor', True), ([('verified', 20)], 'honor', True), ([('professional', 20), ('verified', 20)], 'honor', True), ([('audit', 0), ('honor', 5), ('professional', 20)], 'honor', True), ([('audit', 0), ('honor', 10), ('verified', 20)], 'honor', True), - ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'honor', True), + ([('audit', 10), ('honor', 0), ('verified', 20), ('professional', 20)], 'honor', True), ([('audit', 10)], 'honor', False), ([('honor', 10)], 'honor', False), ([], 'honor', True), - - #Register as an audit in any course modes with no payment option ([('audit', 0), ('honor', 0)], 'audit', True), - # ([('professional', 0)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('verified', 0)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('professional', 0), ('verified', 0)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 0), ('professional', 0)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 0), ('verified', 0)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 0), ('verified', 0), ('professional', 0)], 'audit', True), #This can not be the case as verified courses always has min_price ([('audit', 0)], 'audit', True), ([('honor', 0)], 'audit', True), ([], 'audit', True), #Register as an audit in any course modes which has payment option ([('audit', 0), ('honor', 10)], 'audit', False), - # ([('professional', 20)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('verified', 20)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('professional', 20), ('verified', 20)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 5), ('professional', 20)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 10), ('verified', 20)], 'audit', True), #This can not be the case as verified courses always has min_price - # ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'audit', True), #This can not be the case as verified courses always has min_price + ([('audit', 10), ('honor', 0)], 'audit', False), ([('audit', 10)], 'audit', False), ([('honor', 10)], 'audit', False), ([], 'audit', True), - - - #Register as a verified in any course modes which has payment option ([('audit', 0), ('honor', 10)], 'verified', False), ([('professional', 20)], 'verified', False), @@ -186,13 +165,9 @@ class TestRecentEnrollments(ModuleStoreTestCase): ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'verified', False), ([('audit', 10)], 'verified', False), ([('honor', 10)], 'verified', False), - # ([], 'audit', True), - ) @ddt.unpack def test_donate_button(self, course_modes, enrollment_mode, show_donate): - # from nose.tools import set_trace; - # set_trace() # Enable the enrollment success message self._configure_message_timeout(10000) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 085a33770f..6b7597767e 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -753,6 +753,7 @@ def _allow_donation(course_modes, course_id, enrollment): Args: course_modes (dict): Mapping of course ID's to course mode dictionaries. course_id (str): The unique identifier for the course. + enrollment(CourseEnrollment): The enrollment object in which the user is enrolled Returns: True if the course is allowing donations. From 50961fe5ad645b9487863f5b05ef17ee55532ef7 Mon Sep 17 00:00:00 2001 From: arbisoft Date: Sat, 10 Jan 2015 05:08:24 +0500 Subject: [PATCH 09/10] ECOM-528 code refactoring --- common/djangoapps/student/views.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 6b7597767e..959ba55675 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -760,17 +760,8 @@ def _allow_donation(course_modes, course_id, enrollment): """ donations_enabled = DonationConfiguration.current().enabled - is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id]) - has_payment_option = CourseMode.has_payment_options(course_id) - return_val = False - if donations_enabled: - if not is_verified_mode: - if not has_payment_option: - return_val = True - else: - if enrollment.mode in ['audit', 'honor']: - return_val = True - return return_val + return donations_enabled and enrollment.mode in course_modes[course_id] and \ + course_modes[course_id][enrollment.mode].min_price == 0 def try_change_enrollment(request): From 62ea486570f748c61236a419f70f5e8c6718fadd Mon Sep 17 00:00:00 2001 From: arbisoft Date: Mon, 12 Jan 2015 15:55:06 +0500 Subject: [PATCH 10/10] ECOM-528 updated the test cases --- .../student/tests/test_recent_enrollments.py | 34 +++++-------------- common/djangoapps/student/views.py | 3 +- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/common/djangoapps/student/tests/test_recent_enrollments.py b/common/djangoapps/student/tests/test_recent_enrollments.py index f7511d12c5..618c378477 100644 --- a/common/djangoapps/student/tests/test_recent_enrollments.py +++ b/common/djangoapps/student/tests/test_recent_enrollments.py @@ -129,42 +129,24 @@ class TestRecentEnrollments(ModuleStoreTestCase): @ddt.data( #Register as an honor in any course modes with no payment option ([('audit', 0), ('honor', 0)], 'honor', True), - ([('audit', 0)], 'honor', True), ([('honor', 0)], 'honor', True), ([], 'honor', True), #Register as an honor in any course modes which has payment option - ([('audit', 0), ('honor', 10)], 'honor', False), - ([('audit', 10), ('honor', 0)], 'honor', False), - ([('professional', 20)], 'honor', True), - ([('verified', 20)], 'honor', True), - ([('professional', 20), ('verified', 20)], 'honor', True), - ([('audit', 0), ('honor', 5), ('professional', 20)], 'honor', True), - ([('audit', 0), ('honor', 10), ('verified', 20)], 'honor', True), - ([('audit', 10), ('honor', 0), ('verified', 20), ('professional', 20)], 'honor', True), - ([('audit', 10)], 'honor', False), - ([('honor', 10)], 'honor', False), + ([('honor', 10)], 'honor', False), # This is a paid course + ([('audit', 0), ('honor', 0), ('professional', 20)], 'honor', True), + ([('audit', 0), ('honor', 0), ('verified', 20)], 'honor', True), + ([('audit', 0), ('honor', 0), ('verified', 20), ('professional', 20)], 'honor', True), ([], 'honor', True), #Register as an audit in any course modes with no payment option ([('audit', 0), ('honor', 0)], 'audit', True), ([('audit', 0)], 'audit', True), - ([('honor', 0)], 'audit', True), - ([], 'audit', True), - #Register as an audit in any course modes which has payment option - ([('audit', 0), ('honor', 10)], 'audit', False), - ([('audit', 10), ('honor', 0)], 'audit', False), - ([('audit', 10)], 'audit', False), - ([('honor', 10)], 'audit', False), - ([], 'audit', True), + #Register as an audit in any course modes which has no payment option + ([('audit', 0), ('honor', 0), ('verified', 10)], 'audit', True), #Register as a verified in any course modes which has payment option - ([('audit', 0), ('honor', 10)], 'verified', False), - ([('professional', 20)], 'verified', False), + ([('professional', 20)], 'professional', False), ([('verified', 20)], 'verified', False), ([('professional', 20), ('verified', 20)], 'verified', False), - ([('audit', 0), ('honor', 5), ('professional', 20)], 'verified', False), - ([('audit', 0), ('honor', 10), ('verified', 20)], 'verified', False), - ([('audit', 0), ('honor', 10), ('verified', 20), ('professional', 20)], 'verified', False), - ([('audit', 10)], 'verified', False), - ([('honor', 10)], 'verified', False), + ([('audit', 0), ('honor', 0), ('verified', 20)], 'verified', False) ) @ddt.unpack def test_donate_button(self, course_modes, enrollment_mode, show_donate): diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 959ba55675..af017129f5 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -760,8 +760,7 @@ def _allow_donation(course_modes, course_id, enrollment): """ donations_enabled = DonationConfiguration.current().enabled - return donations_enabled and enrollment.mode in course_modes[course_id] and \ - course_modes[course_id][enrollment.mode].min_price == 0 + return donations_enabled and enrollment.mode in course_modes[course_id] and course_modes[course_id][enrollment.mode].min_price == 0 def try_change_enrollment(request):