Skip to content

Commit 03133b5

Browse files
committed
Tests: Fix test_create_email_redirect
1 parent 9338915 commit 03133b5

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

‎stream/tests.py‎

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
import random
66
import jwt
77
from unittest.case import TestCase
8+
import json
89

910
import os
1011
import datetime
1112
import copy
1213
import requests
1314
from stream import serializer
14-
from requests.exceptions import ConnectionError, MissingSchema
15+
from requests.exceptions import MissingSchema
1516

1617
try:
1718
from urlparse import urlparse, parse_qs
1819
except ImportError:
1920
from urllib.parse import urlparse, parse_qs
2021

22+
2123
def connect_debug():
2224
return stream.connect(
2325
'q56mdvdzreye',
@@ -842,18 +844,29 @@ def test_add_to_many(self):
842844
self.assertEqual(feed.get()['results'][0]['custom'], 'data')
843845

844846
def test_create_email_redirect(self):
845-
expected_parts = ['https://analytics.getstream.io/analytics/redirect/',
846-
'auth_type=jwt',
847-
'url=http%3A%2F%2Fgoogle.com%2F%3Fa%3Db%26c%3Dd',
848-
'api_key=%s' % self.c.api_key,
849-
'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',
850-
]
851-
engagement = {'foreign_id': 'tweet:1', 'label': 'click', 'position': 3, 'user_id': 'tommaso', 'location': 'email', 'feed_id': 'user:global'}
852-
impression = {'foreign_ids': ['tweet:1', 'tweet:2', 'tweet:3', 'tweet:4', 'tweet:5'], 'user_id':
853-
'tommaso', 'location': 'email', 'feed_id': 'user:global'}
854-
events = [impression, engagement]
855847
target_url = 'http://google.com/?a=b&c=d'
856848
user_id = 'tommaso'
849+
850+
impression = {
851+
'foreign_ids': ['tweet:1',
852+
'tweet:2',
853+
'tweet:3',
854+
'tweet:4',
855+
'tweet:5'],
856+
'feed_id': 'user:global',
857+
'user_id': user_id,
858+
'location': 'email'
859+
}
860+
engagement = {
861+
'user_id': user_id,
862+
'label': 'click',
863+
'feed_id': 'user:global',
864+
'location': 'email',
865+
'position': 3,
866+
'foreign_id': 'tweet:1'
867+
}
868+
events = [impression, engagement]
869+
857870
redirect_url = self.c.create_redirect_url(target_url, user_id, events)
858871

859872
parsed_url = urlparse(redirect_url)
@@ -867,9 +880,18 @@ def test_create_email_redirect(self):
867880
'user_id': 'tommaso'
868881
})
869882

870-
for part in expected_parts:
871-
if part not in redirect_url:
872-
raise ValueError('didnt find %s in url \n %s' % (part, redirect_url))
883+
expected_params = {
884+
'auth_type': 'jwt',
885+
'url': target_url,
886+
'api_key': self.c.api_key,
887+
}
888+
889+
for k, v in expected_params.items():
890+
self.assertEqual(qs[k][0], v)
891+
892+
self.assertEqual(json.loads(qs['events'][0]), events)
893+
894+
873895

874896
def test_email_redirect_invalid_target(self):
875897
engagement = {'foreign_id': 'tweet:1', 'label': 'click', 'position': 3, 'user_id': 'tommaso', 'location': 'email', 'feed_id': 'user:global'}

0 commit comments

Comments
 (0)