From 87422a98451b2e4c61d1f9edfd5569a17cc05465 Mon Sep 17 00:00:00 2001 From: Amit Mathew Date: Tue, 25 Jul 2023 10:47:01 -0400 Subject: [PATCH] Fix subscription creation webhook failing due to case sensitivity issues when finding users by email address. --- djpaddle/mappers.py | 2 +- tests/test_mappers.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/djpaddle/mappers.py b/djpaddle/mappers.py index 692d18a..32ce95e 100644 --- a/djpaddle/mappers.py +++ b/djpaddle/mappers.py @@ -29,7 +29,7 @@ def subscriber_by_payload(Subscriber, payload): """ if "email" not in payload: raise Subscriber.DoesNotExist("'email' missing in payload") - return Subscriber.objects.get(email=payload["email"]) + return Subscriber.objects.get(email__iexact=payload["email"]) def subscriptions_by_subscriber(subscriber, queryset): diff --git a/tests/test_mappers.py b/tests/test_mappers.py index a0491e7..e7ad8af 100644 --- a/tests/test_mappers.py +++ b/tests/test_mappers.py @@ -6,13 +6,27 @@ class TestPaddleMappers(TestCase): - def test_get_subscriber_by_payload(self): + def test_get_subscriber_by_payload_does_not_exist(self): Subscriber = settings.get_subscriber_model() payload = {"email": "nonexistent@email.com"} with self.assertRaises(Subscriber.DoesNotExist): mappers.get_subscriber_by_payload(Subscriber, payload) + def test_get_subscriber_by_payload(self): + Subscriber = settings.get_subscriber_model() + subscriber = Subscriber.objects.create(username="user", email="test@example.com") + payload = {"email": "test@example.com"} + fetched_subscriber = mappers.get_subscriber_by_payload(Subscriber, payload) + self.assertEqual(fetched_subscriber.email, subscriber.email) + + def test_get_subscriber_by_payload_case_sensitive(self): + Subscriber = settings.get_subscriber_model() + subscriber = Subscriber.objects.create(username="user", email="Test@example.com") + payload = {"email": "test@example.com"} + fetched_subscriber = mappers.get_subscriber_by_payload(Subscriber, payload) + self.assertEqual(fetched_subscriber.email, subscriber.email) + def test_get_subscriber_by_payload_missing_email(self): Subscriber = settings.get_subscriber_model() payload = {"not-email": "nonexistent@email.com"}