11from copy import deepcopy
22from unittest import mock
33
4+ from django .conf import settings
45from django .urls import reverse
56from django .test import TestCase , Client
67
78from . import FAKE_ALERT_TEST_SUBSCRIPTION_CREATED
9+ from djpaddle .models import Plan , Subscription
810
911
1012class TestWebhook (TestCase ):
@@ -15,6 +17,7 @@ def _send_alert(self, data):
1517 def test_webhook_is_valid_alert (self , is_valid_webhook ):
1618 valid_alert = deepcopy (FAKE_ALERT_TEST_SUBSCRIPTION_CREATED )
1719 valid_alert ["p_signature" ] = "valid-signature"
20+ plan = Plan .objects .create (pk = 1 , name = "monthly-subscription" , billing_type = "month" , billing_period = 1 , trial_days = 0 )
1821
1922 resp = self ._send_alert (valid_alert )
2023 self .assertTrue (is_valid_webhook .called )
@@ -26,3 +29,13 @@ def test_webhook_is_invalid_signature(self):
2629
2730 resp = self ._send_alert (invalid_alert )
2831 self .assertEqual (resp .status_code , 400 )
32+
33+ @mock .patch ("djpaddle.views.is_valid_webhook" , return_value = True )
34+ def test_subscription_created_webhook (self , is_valid_webhook ):
35+ payload = deepcopy (FAKE_ALERT_TEST_SUBSCRIPTION_CREATED )
36+ payload ["p_signature" ] = "valid-signature"
37+ plan = Plan .objects .create (pk = 1 , name = "monthly-subscription" , billing_type = "month" , billing_period = 1 , trial_days = 0 )
38+
39+ resp = self ._send_alert (payload )
40+ subscription = Subscription .objects .get (email = payload ["email" ])
41+ self .assertEqual (subscription .email , "gardner.wuckert@example.org" )
0 commit comments