-
Notifications
You must be signed in to change notification settings - Fork 9
/
tests.py
138 lines (99 loc) · 4.46 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import os
import unittest
import json
import requests
from mock import patch
import vero
class VeroEventLoggerTests(unittest.TestCase):
def setUp(self):
self.auth_token = os.environ['VERO_AUTH_TOKEN']
self.logger = vero.client.VeroEventLogger(self.auth_token)
self.user_id = 1
self.user_email = '[email protected]'
self.user_data = {
'name': 'John Smith',
'height': 72,
'weight': 180,
'title': 'Mr.',
'favourites': {
'color': 'red',
'ice cream': 'chocolate'
}
}
self.user_changes = {
'height': 73,
'extra': 'extra'
}
self.user_tags = ['x', 'y', 'z']
self.event_name = 'test event'
self.event_data = {
'string data': 'a',
'numeric data': 123,
'float data': 1.23,
'list data': ['a', 1],
'tuple data': ('a', 1),
'dict data': {
'a': 1,
1: 'a'
}
}
def test_fire_request(self):
endpoint = vero.client.VeroEndpoints.ADD_USER
payload = {
'test': 1
}
with patch('requests.request') as mock_request:
self.logger._fire_request(endpoint, payload)
mock_request.assert_called_once_with(endpoint.method, self.logger.base_url + endpoint.url, data=json.dumps(payload))
def test_add_user(self):
req = self.logger.add_user(self.user_id, self.user_data)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_user__with_email(self):
req = self.logger.add_user(self.user_id, self.user_data, user_email=self.user_email)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_user__development_mode(self):
req = self.logger.add_user(self.user_id, self.user_data, development_mode=True)
self.assertEqual(req.status_code, requests.codes.ok)
def test_edit_user(self):
req = self.logger.edit_user(self.user_id, self.user_changes)
self.assertEqual(req.status_code, requests.codes.ok)
def test_edit_user__development_mode(self):
req = self.logger.edit_user(self.user_id, self.user_changes, development_mode=True)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_tags(self):
req = self.logger.add_tags(self.user_id, self.user_tags)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_tags__empyty_list(self):
req = self.logger.add_tags(self.user_id, [])
self.assertEqual(req.status_code, requests.codes.bad)
def test_add_tags__development_mode(self):
req = self.logger.add_tags(self.user_id, self.user_tags, development_mode=True)
self.assertEqual(req.status_code, requests.codes.ok)
def test_remove_tags(self):
req = self.logger.remove_tags(self.user_id, self.user_tags)
self.assertEqual(req.status_code, requests.codes.ok)
def test_remove_tags__empyty_list(self):
req = self.logger.add_tags(self.user_id, [])
self.assertEqual(req.status_code, requests.codes.bad)
def test_remove_tags__development_mode(self):
req = self.logger.remove_tags(self.user_id, self.user_tags, development_mode=True)
self.assertEqual(req.status_code, requests.codes.ok)
def test_unsubscribe_user(self):
req = self.logger.unsubscribe_user(self.user_id)
self.assertEqual(req.status_code, requests.codes.ok)
def test_unsubscribe_user__development_mode(self):
req = self.logger.unsubscribe_user(self.user_id, development_mode=True)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_event(self):
req = self.logger.add_event(self.event_name, self.event_data, self.user_id)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_event__with_email(self):
req = self.logger.add_event(self.event_name, self.event_data, self.user_id, user_email=self.user_email)
self.assertEqual(req.status_code, requests.codes.ok)
def test_add_event__development_mode(self):
req = self.logger.add_event(self.event_name, self.event_data, self.user_id, development_mode=True)
self.assertEqual(req.status_code, requests.codes.ok)
if __name__ == "__main__":
if os.environ.get('VERO_AUTH_TOKEN', None) is None:
exit('error: must set environment variable VERO_AUTH_TOKEN')
unittest.main()