From 70462bf0ce9b8873ffb3389a900550c2d0d3b3e5 Mon Sep 17 00:00:00 2001 From: Muhammad Umar Khan Date: Thu, 21 Dec 2023 16:40:30 +0500 Subject: [PATCH] fix: get_response issue for middleware --- .../analytics/tests/test_middleware.py | 2 +- ecommerce/extensions/catalogue/models.py | 35 ++++++++++--------- ecommerce/extensions/partner/apps.py | 4 +-- .../extensions/payment/core/tests/test_sdn.py | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/ecommerce/extensions/analytics/tests/test_middleware.py b/ecommerce/extensions/analytics/tests/test_middleware.py index 64adfd5ac3d..b37526b63c1 100644 --- a/ecommerce/extensions/analytics/tests/test_middleware.py +++ b/ecommerce/extensions/analytics/tests/test_middleware.py @@ -19,7 +19,7 @@ class TrackingMiddlewareTests(TestCase): def setUp(self): super(TrackingMiddlewareTests, self).setUp() - self.middleware = middleware.TrackingMiddleware() + self.middleware = middleware.TrackingMiddleware(get_response=lambda request: None) self.request_factory = RequestFactory() self.user = self.create_user() diff --git a/ecommerce/extensions/catalogue/models.py b/ecommerce/extensions/catalogue/models.py index 98049598ed7..39f90249e66 100644 --- a/ecommerce/extensions/catalogue/models.py +++ b/ecommerce/extensions/catalogue/models.py @@ -97,25 +97,28 @@ def is_executive_education_2u_product(self): CertificateType.UNPAID_EXECUTIVE_EDUCATION ] + def save(self, *args, **kwargs): - super(Product, self).save(*args, **kwargs) # pylint: disable=bad-super-call - try: - if not isinstance(self.attr.note, str) and self.attr.note is not None: + if self.id: + try: + if not isinstance(self.attr.note, str) and self.attr.note is not None: + log_message_and_raise_validation_error( + 'Failed to create Product. Product note value must be of type string' + ) + except AttributeError: + pass + + try: + if self.attr.notify_email is not None: + validate_email(self.attr.notify_email) + except ValidationError: log_message_and_raise_validation_error( - 'Failed to create Product. Product note value must be of type string' + 'Notification email must be a valid email address.' ) - except AttributeError: - pass - - try: - if self.attr.notify_email is not None: - validate_email(self.attr.notify_email) - except ValidationError: - log_message_and_raise_validation_error( - 'Notification email must be a valid email address.' - ) - except AttributeError: - pass + except AttributeError: + pass + + super(Product, self).save(*args, **kwargs) # pylint: disable=bad-super-call @receiver(post_init, sender=Product) diff --git a/ecommerce/extensions/partner/apps.py b/ecommerce/extensions/partner/apps.py index 8d7820235c1..4d867c3f459 100644 --- a/ecommerce/extensions/partner/apps.py +++ b/ecommerce/extensions/partner/apps.py @@ -1,7 +1,7 @@ -from oscar.apps.partner.apps import PartnerConfig as CorePartnerConfig +from oscar.apps.partner import apps -class PartnerConfig(CorePartnerConfig): +class PartnerConfig(apps.PartnerConfig): name = 'ecommerce.extensions.partner' diff --git a/ecommerce/extensions/payment/core/tests/test_sdn.py b/ecommerce/extensions/payment/core/tests/test_sdn.py index 2597a5b9203..00497a261bb 100644 --- a/ecommerce/extensions/payment/core/tests/test_sdn.py +++ b/ecommerce/extensions/payment/core/tests/test_sdn.py @@ -479,7 +479,7 @@ def test_sdn_is_down_sdn_fallback_called( If there is no hit, allow purchase. """ request = RequestFactory().post('/payment/cybersource/submit/') - middleware = SessionMiddleware() + middleware = SessionMiddleware(get_response=lambda request: None) middleware.process_request(request) request.session.save() site_configuration = self.site.siteconfiguration