From 9213f1c60a92a537f0e6f950387eb788c1467dc3 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 | 34 ++++++++++--------- ecommerce/extensions/partner/apps.py | 4 +-- .../extensions/payment/core/tests/test_sdn.py | 2 +- 4 files changed, 22 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..1dbef563cc0 100644 --- a/ecommerce/extensions/catalogue/models.py +++ b/ecommerce/extensions/catalogue/models.py @@ -98,24 +98,26 @@ def is_executive_education_2u_product(self): ] 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