Skip to content

Commit b3d56c9

Browse files
author
Matej Vetrak
committed
Add test for requests session
1 parent b4ae4e1 commit b3d56c9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pywebpush/tests/test_webpush.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,19 @@ def test_timeout(self, mock_post):
318318
eq_(mock_post.call_args[1].get('timeout'), 5.2)
319319
webpush(subscription_info, timeout=10.001)
320320
eq_(mock_post.call_args[1].get('timeout'), 10.001)
321+
322+
@patch("requests.Session")
323+
def test_send_using_requests_session(self, mock_session):
324+
subscription_info = self._gen_subscription_info()
325+
headers = {"Crypto-Key": "pre-existing",
326+
"Authentication": "bearer vapid"}
327+
data = "Mary had a little lamb"
328+
WebPusher(subscription_info, requests_session=mock_session).send(data, headers)
329+
eq_(subscription_info.get('endpoint'), mock_session.post.call_args[0][0])
330+
pheaders = mock_session.post.call_args[1].get('headers')
331+
eq_(pheaders.get('ttl'), '0')
332+
ok_('encryption' in pheaders)
333+
eq_(pheaders.get('AUTHENTICATION'), headers.get('Authentication'))
334+
ckey = pheaders.get('crypto-key')
335+
ok_('pre-existing' in ckey)
336+
eq_(pheaders.get('content-encoding'), 'aesgcm')

0 commit comments

Comments
 (0)