Skip to content

Commit 1d1e1d4

Browse files
committed
bug: merge fail
1 parent 87fc0d8 commit 1d1e1d4

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ object.
121121

122122
The following methods are available:
123123

124-
``.send(data, headers={}, ttl=0, gcm_key="", reg_id="", content_encoding="aesgcm", curl=False)``
125-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124+
``.send(data, headers={}, ttl=0, gcm_key="", reg_id="", content_encoding="aesgcm", curl=False, timeout=None)``
125+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126126

127127
Send the data using additional parameters. On error, returns a
128128
``WebPushException``
@@ -149,6 +149,9 @@ will write the encrypted content to a local file named
149149
``encrpypted.data``. This command is meant to be used for debugging
150150
purposes.
151151

152+
*timeout* timeout for requests POST query. See `requests
153+
documentation <http://docs.python-requests.org/en/master/user/quickstart/#timeouts>`__.
154+
152155
**Example**
153156

154157
to send from Chrome using the old GCM mode:

pywebpush/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ def webpush(subscription_info,
326326
:type subscription_info: dict
327327
:param data: Serialized data to send
328328
:type data: str
329-
:param vapid_private_key: Path to vapid private key PEM or encoded str
330-
:type vapid_private_key: str
329+
:param vapid_private_key: Vapid instance or path to vapid private key PEM \
330+
or encoded str
331+
:type vapid_private_key: Union[Vapid, str]
331332
:param vapid_claims: Dictionary of claims ('sub' required)
332333
:type vapid_claims: dict
333334
:param content_encoding: Optional content type string
@@ -347,7 +348,9 @@ def webpush(subscription_info,
347348
vapid_claims['aud'] = aud
348349
if not vapid_private_key:
349350
raise WebPushException("VAPID dict missing 'private_key'")
350-
if os.path.isfile(vapid_private_key):
351+
if isinstance(vapid_private_key, Vapid):
352+
vv = vapid_private_key
353+
elif os.path.isfile(vapid_private_key):
351354
# Presume that key from file is handled correctly by
352355
# py_vapid.
353356
vv = Vapid.from_file(

pywebpush/tests/test_webpush.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import os
44
import unittest
55

6-
from mock import patch, Mock
6+
from mock import patch
77
from nose.tools import eq_, ok_, assert_raises
88
import http_ece
99
from cryptography.hazmat.primitives.asymmetric import ec
1010
from cryptography.hazmat.backends import default_backend
11+
import py_vapid
1112

1213
from pywebpush import WebPusher, WebPushException, CaseInsensitiveDict, webpush
1314

@@ -138,7 +139,6 @@ def test_send(self, mock_post):
138139

139140
@patch("requests.post")
140141
def test_send_vapid(self, mock_post):
141-
mock_post.return_value = Mock()
142142
mock_post.return_value.status_code = 200
143143
subscription_info = self._gen_subscription_info()
144144
data = "Mary had a little lamb"
@@ -168,9 +168,25 @@ def repad(str):
168168
ok_('dh=' in ckey)
169169
eq_(pheaders.get('content-encoding'), 'aesgcm')
170170

171+
@patch.object(WebPusher, "send")
172+
@patch.object(py_vapid.Vapid, "sign")
173+
def test_webpush_vapid_instance(self, vapid_sign, pusher_send):
174+
pusher_send.return_value.status_code = 200
175+
subscription_info = self._gen_subscription_info()
176+
data = "Mary had a little lamb"
177+
vapid_key = py_vapid.Vapid.from_string(self.vapid_key)
178+
claims = dict(sub="mailto:[email protected]", aud="https://example.com")
179+
webpush(
180+
subscription_info=subscription_info,
181+
data=data,
182+
vapid_private_key=vapid_key,
183+
vapid_claims=claims,
184+
)
185+
vapid_sign.assert_called_once_with(claims)
186+
pusher_send.assert_called_once()
187+
171188
@patch("requests.post")
172189
def test_send_bad_vapid_no_key(self, mock_post):
173-
mock_post.return_value = Mock()
174190
mock_post.return_value.status_code = 200
175191

176192
subscription_info = self._gen_subscription_info()
@@ -187,7 +203,6 @@ def test_send_bad_vapid_no_key(self, mock_post):
187203

188204
@patch("requests.post")
189205
def test_send_bad_vapid_bad_return(self, mock_post):
190-
mock_post.return_value = Mock()
191206
mock_post.return_value.status_code = 410
192207

193208
subscription_info = self._gen_subscription_info()
@@ -297,7 +312,6 @@ def test_gcm(self, mock_post):
297312

298313
@patch("requests.post")
299314
def test_timeout(self, mock_post):
300-
mock_post.return_value = Mock()
301315
mock_post.return_value.status_code = 200
302316
subscription_info = self._gen_subscription_info()
303317
WebPusher(subscription_info).send(timeout=5.2)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from setuptools import find_packages, setup
55

6-
__version__ = "1.1.1"
6+
__version__ = "1.3.1"
77

88

99
def read_from(file):

0 commit comments

Comments
 (0)