-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
115 lines (89 loc) · 4.36 KB
/
Copy pathtest.py
File metadata and controls
115 lines (89 loc) · 4.36 KB
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
import unittest
import uuid
from notification_service_client import NotificationServiceClient
from datetime import datetime, timedelta
class TestNotificationServiceClient(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.client = NotificationServiceClient()
def generate_unique(self, prefix):
return f"{prefix}_{uuid.uuid4().hex}"
def test_health_check(self):
response = self.client.health_check()
self.assertIsInstance(response, dict)
def test_register_token(self):
token = self.generate_unique("test_token")
session_id = self.generate_unique("test_session")
self.addCleanup(self.client.delete_token, token)
response = self.client.register_token(
token=token,
platform="ios",
session_id=session_id,
user_id="dd3838c",
username="msebsbe",
first_name="Michael",
last_name="sebseb",
expires_at= datetime.now() + timedelta(seconds=10)
)
# print("LOCAL: ", (datetime.now().astimezone() + timedelta(seconds=10)).isoformat())
# print("UTC: ", (datetime.now(timezone.utc) + timedelta(seconds=10)).isoformat())
# print(response)
self.assertEqual(response["token"], token)
self.assertEqual(response["platform"], "ios")
self.assertEqual(response["sessionId"], session_id)
def test_update_token(self):
old_token = self.generate_unique("old_token")
new_token = self.generate_unique("new_token")
self.addCleanup(self.client.delete_token, old_token)
self.addCleanup(self.client.delete_token, new_token)
# Register old token
self.client.register_token(token=old_token, platform="ios")
# Update token
response = self.client.update_token(old_token, new_token)
self.assertEqual(response["token"], new_token)
def test_delete_token(self):
token = self.generate_unique("test_token")
self.client.register_token(token=token, platform="ios")
response = self.client.delete_token(token)
self.assertTrue(response["success"])
def test_delete_user_tokens(self):
user_id = self.generate_unique("user_id")
token = self.generate_unique("test_token")
self.addCleanup(self.client.delete_user_tokens, user_id)
self.client.register_token(token=token, platform="ios", user_id=user_id)
response = self.client.delete_user_tokens(user_id)
self.assertTrue(response["success"])
def test_delete_session_token(self):
session_id = self.generate_unique("session_id")
token = self.generate_unique("test_token")
self.client.register_token(token=token, platform="ios", session_id=session_id)
response = self.client.delete_session_token(session_id)
self.assertTrue(response["success"])
def test_broadcast_notification(self):
response = self.client.broadcast_notification("Test Title", "Test Body")
print(response)
self.assertIsInstance(response, dict)
self.assertIn("success", response)
self.assertIn("sent", response)
self.assertIn("failed", response)
def test_send_to_users(self):
user_id = self.generate_unique("user_id")
token = self.generate_unique("test_token")
self.addCleanup(self.client.delete_user_tokens, user_id)
self.client.register_token(token=token, platform="ios", user_id=user_id)
response = self.client.send_to_users([user_id], "Test Title", "Test Body")
self.assertTrue(response["success"])
self.assertGreaterEqual(response["sent"], 0)
def test_send_to_platforms(self):
response = self.client.send_to_platforms(["ios"], "Test Platform", "Tim Cook says hi")
self.assertTrue(response["success"])
self.assertGreaterEqual(response["sent"], 0)
def test_send_to_tokens(self):
token = self.generate_unique("test_token")
self.addCleanup(self.client.delete_token, token)
self.client.register_token(token=token, platform="ios")
response = self.client.send_to_tokens([token], "Test Title", "Test Body")
self.assertTrue(response["success"])
self.assertGreaterEqual(response["sent"], 0)
if __name__ == '__main__':
unittest.main(verbosity=2)