-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_push.py
More file actions
44 lines (35 loc) · 1.62 KB
/
test_push.py
File metadata and controls
44 lines (35 loc) · 1.62 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
'''Test api endpoints'''
import json
import unittest
from unittest.mock import patch
from app import create_app
from service.push_notification import PushNotification
class api_test_case(unittest.TestCase):
def setUp(self):
self.app = create_app(config_name="testing")
self.client = self.app.test_client
def tearDown(self):
pass
@patch("service.push_notification.PushNotification.subscribe", spec=True)
def test_subscribe(self, mock_get_json):
subscription_info = json.dumps({
"subscriber_info": {
"platform": "web",
"subscription_info": "url",
"calendars": []
}
})
mock_get_json.return_value = {'platform': 'web', 'subscription_info': 'url', 'calendars': [],
'subscriber_key': '98261828-b45d-407e-9684-8ed22f95509d'}
response = self.client().post("/subscription", data=subscription_info, content_type="application/json")
self.assertEqual(response.status_code, 201)
@patch("requests.post", spec=True)
def test_send_rest_notification(self, mock_request):
PushNotification().send_rest_notification("url", "calendar_id")
mock_request.assert_called_with(json='calendar_id', url='url')
@patch("requests.post", spec=True)
def test_send_graphql_notification(self, mock_request):
PushNotification().send_graphql_notification("url", "calendar_id")
mock_request.assert_called_with(json={'query': 'mutation{mrmNotification(calendarId:"calendar_id"){message}}'}, url='url')
if __name__ == "__main__":
unittest.main()