3
3
import time
4
4
from stream .exceptions import ApiKeyException , InputException
5
5
import random
6
+ import jwt
6
7
from unittest .case import TestCase
7
8
8
9
import os
9
10
import datetime
10
11
from stream import serializer
11
12
from requests .exceptions import ConnectionError , MissingSchema
12
- from urlparse import urlparse
13
-
13
+ from urlparse import urlparse , parse_qs
14
14
15
15
def connect_debug ():
16
16
return stream .connect (
@@ -644,7 +644,6 @@ def test_create_email_redirect(self):
644
644
'auth_type=jwt' ,
645
645
'url=http%3A%2F%2Fgoogle.com%2F%3Fa%3Db%26c%3Dd' ,
646
646
'api_key=ahj2ndz7gsan' ,
647
- 'authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY3Rpb24iOiIqIiwidXNlcl9pZCI6InRvbW1hc28iLCJyZXNvdXJjZSI6InJlZGlyZWN0X2FuZF90cmFjayJ9.pQ2cBmC7l0WGP9LP7RrvLEbtrw8YWcFtjOqSfoSr2s0' ,
648
647
'events=%5B%7B%22foreign_ids%22%3A+%5B%22tweet%3A1%22%2C+%22tweet%3A2%22%2C+%22tweet%3A3%22%2C+%22tweet%3A4%22%2C+%22tweet%3A5%22%5D%2C+%22feed_id%22%3A+%22user%3Aglobal%22%2C+%22user_id%22%3A+%22tommaso%22%2C+%22location%22%3A+%22email%22%7D%2C+%7B%22user_id%22%3A+%22tommaso%22%2C+%22label%22%3A+%22click%22%2C+%22feed_id%22%3A+%22user%3Aglobal%22%2C+%22location%22%3A+%22email%22%2C+%22position%22%3A+3%2C+%22foreign_id%22%3A+%22tweet%3A1%22%7D%5D' ,
649
648
]
650
649
engagement = {'foreign_id' : 'tweet:1' , 'label' : 'click' , 'position' : 3 , 'user_id' : 'tommaso' , 'location' : 'email' , 'feed_id' : 'user:global' }
@@ -655,6 +654,17 @@ def test_create_email_redirect(self):
655
654
user_id = 'tommaso'
656
655
redirect_url = self .c .create_redirect_url (target_url , user_id , events )
657
656
657
+ parsed_url = urlparse (redirect_url )
658
+ qs = parse_qs (parsed_url .query )
659
+
660
+ decoded = jwt .decode (qs ['authorization' ][0 ], 'gthc2t9gh7pzq52f6cky8w4r4up9dr6rju9w3fjgmkv6cdvvav2ufe5fv7e2r9qy' )
661
+
662
+ self .assertEqual (decoded , {
663
+ 'resource' : 'redirect_and_track' ,
664
+ 'action' : '*' ,
665
+ 'user_id' : 'tommaso'
666
+ })
667
+
658
668
for part in expected_parts :
659
669
if part not in redirect_url :
660
670
raise ValueError ('didnt find %s in url \n %s' % (part , redirect_url ))
0 commit comments