From 6f859eb8700c4fd3ebf6467c32f4e9b3de552928 Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Mon, 2 Dec 2024 18:01:58 +1100 Subject: [PATCH 1/3] refactor: rollback hiding course price when zero feature --- enterprise/admin/forms.py | 1 - .../0173_remove_hide_price_when_zero.py | 21 ++++++++++++++ enterprise/models.py | 5 ---- enterprise/utils.py | 25 ----------------- enterprise/views.py | 4 --- tests/test_enterprise/test_utils.py | 28 ------------------- 6 files changed, 21 insertions(+), 63 deletions(-) create mode 100644 enterprise/migrations/0173_remove_hide_price_when_zero.py diff --git a/enterprise/admin/forms.py b/enterprise/admin/forms.py index 7262a766d9..695aa6c181 100644 --- a/enterprise/admin/forms.py +++ b/enterprise/admin/forms.py @@ -400,7 +400,6 @@ class Meta: "enable_audit_data_reporting", "replace_sensitive_sso_username", "hide_course_original_price", - "hide_course_price_when_zero", "allow_enrollment_in_invite_only_courses", "enable_portal_code_management_screen", "enable_portal_subscription_management_screen", diff --git a/enterprise/migrations/0173_remove_hide_price_when_zero.py b/enterprise/migrations/0173_remove_hide_price_when_zero.py new file mode 100644 index 0000000000..50a97fc546 --- /dev/null +++ b/enterprise/migrations/0173_remove_hide_price_when_zero.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.21 on 2024-12-02 06:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('enterprise', '0172_adds_allow_enrollment_in_invite_only_courses_flag'), + ] + + operations = [ + migrations.RemoveField( + model_name='enterprisecustomer', + name='hide_course_price_when_zero', + ), + migrations.RemoveField( + model_name='historicalenterprisecustomer', + name='hide_course_price_when_zero', + ), + ] diff --git a/enterprise/models.py b/enterprise/models.py index a9475d8f9b..b8a1465d57 100644 --- a/enterprise/models.py +++ b/enterprise/models.py @@ -411,11 +411,6 @@ class Meta: help_text=_("The email address where learner's reply to enterprise emails will be delivered.") ) - hide_course_price_when_zero = models.BooleanField( - default=False, - help_text=_("Specify whether course cost should be hidden in the landing page when the final price is zero.") - ) - allow_enrollment_in_invite_only_courses = models.BooleanField( default=False, help_text=_( diff --git a/enterprise/utils.py b/enterprise/utils.py index 50445a49fb..0bd4f692af 100644 --- a/enterprise/utils.py +++ b/enterprise/utils.py @@ -2312,31 +2312,6 @@ def logo_path(instance, filename): return fullname -def hide_price_when_zero(enterprise_customer, course_modes): - """ - Adds a "hide_price" flag to the course modes if price is zero and "Hide course price when zero" flag is set. - - Arguments: - enterprise_customer: The EnterpriseCustomer that the enrollemnt is being done. - course_modes: iterable with dictionaries containing a required 'final_price' key - """ - if not enterprise_customer.hide_course_price_when_zero: - return course_modes - - for mode in course_modes: - mode['hide_price'] = False - try: - numbers = re.findall(r'\d+', mode['final_price']) - mode['hide_price'] = int(''.join(numbers)) == 0 - except ValueError: - LOGGER.warning( - 'hide_price_when_zero: Could not convert price "%s" of course mode "%s" to int.', - mode['final_price'], - mode['title'] - ) - return course_modes - - def ensure_course_enrollment_is_allowed(course_id, email, enrollment_api_client): """ Create a CourseEnrollmentAllowed object for invitation-only courses. diff --git a/enterprise/views.py b/enterprise/views.py index 0fa0f7f97e..4b78baf67d 100644 --- a/enterprise/views.py +++ b/enterprise/views.py @@ -77,7 +77,6 @@ get_enterprise_customer_user, get_platform_logo_url, get_program_type_description, - hide_price_when_zero, is_course_run_enrollable, localized_utcnow, track_enrollment, @@ -1544,9 +1543,6 @@ def get_enterprise_course_enrollment_page( # Filter audit course modes. course_modes = filter_audit_course_modes(enterprise_customer, course_modes) - # Set a flag to hide the $0 when the customer doesn't want it to be shown - course_modes = hide_price_when_zero(enterprise_customer, course_modes) - # Allows automatic assignment to a cohort upon enrollment. cohort = request.GET.get('cohort') # Add a message to the message display queue if the learner diff --git a/tests/test_enterprise/test_utils.py b/tests/test_enterprise/test_utils.py index 2b3ef75a4e..278767b543 100644 --- a/tests/test_enterprise/test_utils.py +++ b/tests/test_enterprise/test_utils.py @@ -17,7 +17,6 @@ ensure_course_enrollment_is_allowed, get_idiff_list, get_platform_logo_url, - hide_price_when_zero, is_pending_user, parse_lms_api_datetime, serialize_notification_content, @@ -495,33 +494,6 @@ def expected_email_item(user, activation_links): expected_email_items = [expected_email_item(user, activation_links) for user in users] assert email_items == expected_email_items - @ddt.data(True, False) - def test_hide_course_price_when_zero(self, hide_price): - customer = factories.EnterpriseCustomerFactory() - zero_modes = [ - {"final_price": "$0"}, - {"final_price": "$0.000"}, - {"final_price": "Rs. 0.00"}, - {"final_price": "0.00 EURO"}, - ] - non_zero_modes = [ - {"final_price": "$100"}, - {"final_price": "$73.50"}, - {"final_price": "Rs.8000.00"}, - {"final_price": "4000 Euros"}, - ] - customer.hide_course_price_when_zero = hide_price - - processed_zero_modes = hide_price_when_zero(customer, zero_modes) - processed_non_zero_modes = hide_price_when_zero(customer, non_zero_modes) - - if hide_price: - self.assertTrue(all(mode["hide_price"] for mode in processed_zero_modes)) - self.assertFalse(all(mode["hide_price"] for mode in processed_non_zero_modes)) - else: - self.assertEqual(zero_modes, processed_zero_modes) - self.assertEqual(non_zero_modes, processed_non_zero_modes) - @ddt.data(True, False) @mock.patch("enterprise.utils.CourseEnrollmentAllowed") def test_ensure_course_enrollment_is_allowed(self, invite_only, mock_cea): From 4e5c4fca6ba29bbabaf7dacabf8712c58b9d6238 Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Mon, 2 Dec 2024 18:38:56 +1100 Subject: [PATCH 2/3] fix: remove outdated reference --- tests/test_utilities.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 7bd9affb94..b4a9f69ddd 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -168,7 +168,6 @@ def setUp(self): "system_wide_role_assignments", "reply_to", "hide_labor_market_data", - "hide_course_price_when_zero", ] ), ( From 19c85a7b76dc60b9bf9bdbfb078a208fcf96dcec Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Mon, 2 Dec 2024 18:46:10 +1100 Subject: [PATCH 3/3] fix: remove merge artifact causing test failure --- tests/test_enterprise/test_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_enterprise/test_utils.py b/tests/test_enterprise/test_utils.py index 0a10770b27..bf1cee17c1 100644 --- a/tests/test_enterprise/test_utils.py +++ b/tests/test_enterprise/test_utils.py @@ -495,8 +495,7 @@ def expected_email_item(user, activation_links): assert email_items == expected_email_items @ddt.data(True, False) - @mock.patch("enterprise.utils.CourseEnrollmentAllowed") - def test_ensure_course_enrollment_is_allowed(self, invite_only, mock_cea): + def test_ensure_course_enrollment_is_allowed(self, invite_only): """ Test that the enrollment allow endpoint is called for the "invite_only" courses. """