Skip to content

Commit 39435ef

Browse files
authored
Merge pull request GetStream#45 from GetStream/fix-travis
Fix some of the tests
2 parents 36498ab + bb0d85f commit 39435ef

4 files changed

Lines changed: 72 additions & 27 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ coverage.xml
5252
# Sphinx documentation
5353
docs/_build/
5454

55+
secrets.*sh

‎.travis.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ notifications:
88
email:
99
- thierryschellenbach@gmail.com
1010
- tbarbugli@gmail.com
11+
12+
env:
13+
secure: G4nELnequtvrwsK0waSmkeikVaF+HSeLgeoM2F8eN22vo92VZKrnz9r0zinBnX/VHGEJ3yNmrQ+XbStb9UuWUL9S23iy/KF2M+f0NbSHsD3iNCuCYCa6c2bQ9O9EjV3NJljXDzJgRCX3UkHq3jueLfx6rXP3Pdhz9FIUhg2F8Ok=
14+
secure: M2XYAJE6WQkhcAtj7W3DMcVH4B9N82JyhTYhABXw4qpmhDEeIO5sJWodkoIKmh+nnWnbY0S6lubk6kcs8OwKk4/YMCbIcZ7iyDCJFwT6kyEwIiGyQ3YZkpwZvF5pWyxga78WgH3snTDnx1d6w5MwrKN5c5jsDpm70vrVxT0BT0U=
1115
install:
12-
- pip install pep8==1.5.7 --use-mirrors
13-
- pip install python-coveralls --use-mirrors
14-
- pip install python-dateutil --use-mirrors
15-
- pip install pytest-cov==1.8.1 --use-mirrors
16-
- pip install -e .
16+
- pip install -r dev_requirements.txt
1717
script:
1818
- py.test stream/tests.py -slv --cov stream --cov-report term-missing
1919
after_script:

‎dev_requirements.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pep8
2+
python-coveralls
3+
python-dateutil
4+
pytest-cov
5+
-e .

‎stream/tests.py‎

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,37 @@
55
import random
66
import jwt
77
from unittest.case import TestCase
8+
import json
89

910
import os
11+
import sys
1012
import datetime
1113
import copy
1214
import requests
1315
from stream import serializer
14-
from requests.exceptions import ConnectionError, MissingSchema
16+
from requests.exceptions import MissingSchema
1517

1618
try:
1719
from urlparse import urlparse, parse_qs
1820
except ImportError:
1921
from urllib.parse import urlparse, parse_qs
2022

23+
2124
def connect_debug():
25+
try:
26+
key = os.environ['STREAM_KEY']
27+
secret = os.environ['STREAM_SECRET']
28+
except KeyError:
29+
print('To run the tests the STREAM_KEY and STREAM_SECRET variables '
30+
'need to be available. \n'
31+
'Please create a pull request if you are an external '
32+
'contributor, because these variables are automatically added '
33+
'by Travis.')
34+
sys.exit(1)
35+
2236
return stream.connect(
23-
'q56mdvdzreye',
24-
'spmf6x2b2v2tqg93sfp5t393wfcxru58zm7jr3ynf7dmmndw5y8chux25hs63znf',
37+
key,
38+
secret,
2539
location='us-east',
2640
timeout=10
2741
)
@@ -385,15 +399,20 @@ def test_follow_and_delete(self):
385399
agg_feed.follow(user_feed.slug, user_feed.user_id)
386400
user_feed.remove_activity(activity_id)
387401

388-
self._test_sleep(10, 0.25)
389-
390-
for x in range(5):
402+
for x in range(40):
391403
activities = agg_feed.get(limit=3)['results']
392404
activity = self._get_first_aggregated_activity(activities)
393-
activity_id_found = activity['id'] if activity is not None else None
394-
self.assertNotEqual(activity_id_found, activity_id)
395-
# self._test_sleep(1, 0.1)
405+
activity_id_found = (activity['id'] if activity is not None
406+
else None)
407+
408+
try:
409+
self.assertNotEqual(activity_id_found, activity_id)
410+
except AssertionError:
411+
self._test_sleep(1, 0.1)
412+
else:
413+
break
396414

415+
self.assertNotEqual(activity_id_found, activity_id)
397416

398417
# def test_follow_private(self):
399418
# feed = getfeed('secret', 'py1')
@@ -842,18 +861,29 @@ def test_add_to_many(self):
842861
self.assertEqual(feed.get()['results'][0]['custom'], 'data')
843862

844863
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]
855864
target_url = 'http://google.com/?a=b&c=d'
856865
user_id = 'tommaso'
866+
867+
impression = {
868+
'foreign_ids': ['tweet:1',
869+
'tweet:2',
870+
'tweet:3',
871+
'tweet:4',
872+
'tweet:5'],
873+
'feed_id': 'user:global',
874+
'user_id': user_id,
875+
'location': 'email'
876+
}
877+
engagement = {
878+
'user_id': user_id,
879+
'label': 'click',
880+
'feed_id': 'user:global',
881+
'location': 'email',
882+
'position': 3,
883+
'foreign_id': 'tweet:1'
884+
}
885+
events = [impression, engagement]
886+
857887
redirect_url = self.c.create_redirect_url(target_url, user_id, events)
858888

859889
parsed_url = urlparse(redirect_url)
@@ -867,9 +897,18 @@ def test_create_email_redirect(self):
867897
'user_id': 'tommaso'
868898
})
869899

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))
900+
expected_params = {
901+
'auth_type': 'jwt',
902+
'url': target_url,
903+
'api_key': self.c.api_key,
904+
}
905+
906+
for k, v in expected_params.items():
907+
self.assertEqual(qs[k][0], v)
908+
909+
self.assertEqual(json.loads(qs['events'][0]), events)
910+
911+
873912

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

0 commit comments

Comments
 (0)