Skip to content

Commit

Permalink
fix: get_response issue for middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Dec 27, 2023
1 parent 78d3735 commit b19d991
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ecommerce/extensions/analytics/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
38 changes: 18 additions & 20 deletions ecommerce/extensions/catalogue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,6 @@ 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:
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(
'Notification email must be a valid email address.'
)
except AttributeError:
pass


@receiver(post_init, sender=Product)
def update_original_expires(sender, **kwargs): # pylint: disable=unused-argument
Expand Down Expand Up @@ -153,6 +133,24 @@ def update_enrollment_code(sender, **kwargs): # pylint: disable=unused-argument
class ProductAttributeValue(AbstractProductAttributeValue):
history = CreateSafeHistoricalRecords()

def save(self, *args, **kwargs):
if self.id:
if self.attribute.code == 'note':
if not isinstance(self.value_text, str) and self.value_text is not None:
log_message_and_raise_validation_error(
'Failed to create Product. Product note value must be of type string'
)
if self.attribute.code == 'notify_email':
try:
if self.value_text is not None:
validate_email(self.value_text)
except ValidationError:
log_message_and_raise_validation_error(
'Notification email must be a valid email address.'
)

super(ProductAttributeValue, self).save(*args, **kwargs) # pylint: disable=bad-super-call


class Catalog(models.Model):
name = models.CharField(max_length=255)
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/extensions/partner/apps.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion ecommerce/extensions/payment/core/tests/test_sdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b19d991

Please sign in to comment.