bug: merge fail

This commit is contained in:
jrconlin 2017-12-04 15:31:40 -08:00
parent f7e887cfee
commit cb00ae0482
4 changed files with 31 additions and 11 deletions

View File

@ -121,8 +121,8 @@ object.
The following methods are available:
``.send(data, headers={}, ttl=0, gcm_key="", reg_id="", content_encoding="aesgcm", curl=False)``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``.send(data, headers={}, ttl=0, gcm_key="", reg_id="", content_encoding="aesgcm", curl=False, timeout=None)``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Send the data using additional parameters. On error, returns a
``WebPushException``
@ -149,6 +149,9 @@ will write the encrypted content to a local file named
``encrpypted.data``. This command is meant to be used for debugging
purposes.
*timeout* timeout for requests POST query. See `requests
documentation <http://docs.python-requests.org/en/master/user/quickstart/#timeouts>`__.
**Example**
to send from Chrome using the old GCM mode:

View File

@ -326,8 +326,9 @@ def webpush(subscription_info,
:type subscription_info: dict
:param data: Serialized data to send
:type data: str
:param vapid_private_key: Path to vapid private key PEM or encoded str
:type vapid_private_key: str
:param vapid_private_key: Vapid instance or path to vapid private key PEM \
or encoded str
:type vapid_private_key: Union[Vapid, str]
:param vapid_claims: Dictionary of claims ('sub' required)
:type vapid_claims: dict
:param content_encoding: Optional content type string
@ -347,7 +348,9 @@ def webpush(subscription_info,
vapid_claims['aud'] = aud
if not vapid_private_key:
raise WebPushException("VAPID dict missing 'private_key'")
if os.path.isfile(vapid_private_key):
if isinstance(vapid_private_key, Vapid):
vv = vapid_private_key
elif os.path.isfile(vapid_private_key):
# Presume that key from file is handled correctly by
# py_vapid.
vv = Vapid.from_file(

View File

@ -3,11 +3,12 @@ import json
import os
import unittest
from mock import patch, Mock
from mock import patch
from nose.tools import eq_, ok_, assert_raises
import http_ece
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.backends import default_backend
import py_vapid
from pywebpush import WebPusher, WebPushException, CaseInsensitiveDict, webpush
@ -138,7 +139,6 @@ class WebpushTestCase(unittest.TestCase):
@patch("requests.post")
def test_send_vapid(self, mock_post):
mock_post.return_value = Mock()
mock_post.return_value.status_code = 200
subscription_info = self._gen_subscription_info()
data = "Mary had a little lamb"
@ -168,9 +168,25 @@ class WebpushTestCase(unittest.TestCase):
ok_('dh=' in ckey)
eq_(pheaders.get('content-encoding'), 'aesgcm')
@patch.object(WebPusher, "send")
@patch.object(py_vapid.Vapid, "sign")
def test_webpush_vapid_instance(self, vapid_sign, pusher_send):
pusher_send.return_value.status_code = 200
subscription_info = self._gen_subscription_info()
data = "Mary had a little lamb"
vapid_key = py_vapid.Vapid.from_string(self.vapid_key)
claims = dict(sub="mailto:ops@example.com", aud="https://example.com")
webpush(
subscription_info=subscription_info,
data=data,
vapid_private_key=vapid_key,
vapid_claims=claims,
)
vapid_sign.assert_called_once_with(claims)
pusher_send.assert_called_once()
@patch("requests.post")
def test_send_bad_vapid_no_key(self, mock_post):
mock_post.return_value = Mock()
mock_post.return_value.status_code = 200
subscription_info = self._gen_subscription_info()
@ -187,7 +203,6 @@ class WebpushTestCase(unittest.TestCase):
@patch("requests.post")
def test_send_bad_vapid_bad_return(self, mock_post):
mock_post.return_value = Mock()
mock_post.return_value.status_code = 410
subscription_info = self._gen_subscription_info()
@ -297,7 +312,6 @@ class WebpushTestCase(unittest.TestCase):
@patch("requests.post")
def test_timeout(self, mock_post):
mock_post.return_value = Mock()
mock_post.return_value.status_code = 200
subscription_info = self._gen_subscription_info()
WebPusher(subscription_info).send(timeout=5.2)

View File

@ -3,7 +3,7 @@ import os
from setuptools import find_packages, setup
__version__ = "1.1.1"
__version__ = "1.3.1"
def read_from(file):