File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FAKE_ALERT_TEST_SUBSCRIPTION_CREATED = {
2+ "alert_id" : 1 ,
3+ "alert_name" : "subscription_created" ,
4+ "cancel_url" : "https://checkout.paddle.com/subscription/cancel?user=1&subscription=2&hash=aaaaaa" ,
5+ "update_url" : "https://checkout.paddle.com/subscription/update?user=5&subscription=4&hash=aaaaaa" ,
6+ "checkout_id" : 1 ,
7+ "currency" : "EUR" ,
8+ "email" : "gardner.wuckert@example.org" ,
9+ "event_time" : "2020-01-13 19:19:18" ,
10+ "marketing_consent" : 1 ,
11+ "next_bill_date" : "2020-01-30" ,
12+ "passthrough" : "" ,
13+ "quantity" : 1 ,
14+ "source" : "" ,
15+ "status" : "active" ,
16+ "subscription_id" : 1 ,
17+ "subscription_plan_id" : 1 ,
18+ "unit_price" : 0 ,
19+ "user_id" : 1 ,
20+ }
Original file line number Diff line number Diff line change 1+ from copy import deepcopy
2+ from unittest import mock
3+
4+ from django .urls import reverse
5+ from django .test import TestCase , Client
6+
7+ from . import FAKE_ALERT_TEST_SUBSCRIPTION_CREATED
8+
9+
10+ class TestWebhook (TestCase ):
11+ def _send_alert (self , data ):
12+ return Client ().post (reverse ("djpaddle:webhook" ), data )
13+
14+ @mock .patch ("djpaddle.views.is_valid_webhook" , return_value = True )
15+ def test_webhook_is_valid_alert (self , is_valid_webhook ):
16+ valid_alert = deepcopy (FAKE_ALERT_TEST_SUBSCRIPTION_CREATED )
17+ valid_alert ["p_signature" ] = "valid-signature"
18+
19+ resp = self ._send_alert (valid_alert )
20+ self .assertTrue (is_valid_webhook .called )
21+ self .assertEqual (resp .status_code , 200 )
22+
23+ def test_webhook_is_invalid_signature (self ):
24+ invalid_alert = deepcopy (FAKE_ALERT_TEST_SUBSCRIPTION_CREATED )
25+ invalid_alert ["p_signature" ] = "invalid-signature"
26+
27+ resp = self ._send_alert (invalid_alert )
28+ self .assertEqual (resp .status_code , 400 )
You can’t perform that action at this time.
0 commit comments