From a38a340b1affd620426ba0e50fb821046d3454ee Mon Sep 17 00:00:00 2001 From: Jamie Patel Date: Thu, 28 May 2015 15:05:05 +0100 Subject: [PATCH 1/2] Made amendments to urlfetch backend. Addresses #54 --- README.md | 4 ++-- pusher/{urlfetch.py => gae.py} | 6 +++--- ...est_urlfetch_adapter.py => test_gae_adapter.py} | 14 ++++++++++---- setup.py | 3 +-- 4 files changed, 16 insertions(+), 11 deletions(-) rename pusher/{urlfetch.py => gae.py} (86%) rename pusher_tests/{test_urlfetch_adapter.py => test_gae_adapter.py} (64%) diff --git a/README.md b/README.md index 581993f..b1e0322 100644 --- a/README.md +++ b/README.md @@ -289,13 +289,13 @@ Users can configure the library to use different backends to send calls to our A * [Requests](http://docs.python-requests.org/en/latest/) (`pusher.requests.RequestsBackend`). This is used by default. * [Tornado](http://www.tornadoweb.org/en/stable/) (`pusher.tornado.TornadoBackend`). * [AsyncIO](http://asyncio.org/) (`pusher.aiohttp.AsyncIOBackend`). -* [URLFetch](https://pypi.python.org/pypi/urlfetch) (`pusher.urlfetch.URLFetchBackend`). +* [Google App Engine](https://cloud.google.com/appengine/docs/python/urlfetch/) (`pusher.gae.GAEBackend`). Upon initializing a Pusher instance, pass in any of these options to the `backend` keyword argument. ### Google App Engine -GAE users are advised to use the URLFetch backend to ensure compatability. +GAE users are advised to use the `pusher.gae.GAEBackend` backend to ensure compatability. ## Feature Support diff --git a/pusher/urlfetch.py b/pusher/gae.py similarity index 86% rename from pusher/urlfetch.py rename to pusher/gae.py index a507549..97f72f2 100644 --- a/pusher/urlfetch.py +++ b/pusher/gae.py @@ -3,10 +3,10 @@ from __future__ import (print_function, unicode_literals, absolute_import, division) -import urlfetch +from google.appengine.api import urlfetch from pusher.http import process_response -class URLFetchBackend(object): +class GAEBackend(object): """Adapter for the URLFetch Module. Necessary for using this library with Google App Engine""" @@ -19,7 +19,7 @@ def send_request(self, request): url=request.url, headers=request.headers, method=request.method, - data=request.body, + payload=request.body, deadline=self.config.timeout, **self.options ) diff --git a/pusher_tests/test_urlfetch_adapter.py b/pusher_tests/test_gae_adapter.py similarity index 64% rename from pusher_tests/test_urlfetch_adapter.py rename to pusher_tests/test_gae_adapter.py index 9ada60e..b1fd8a6 100644 --- a/pusher_tests/test_urlfetch_adapter.py +++ b/pusher_tests/test_gae_adapter.py @@ -12,15 +12,21 @@ import unittest @unittest.skipIf(sys.version_info >= (3,), "skip") -class TestURLFetchBackend(unittest.TestCase): +class TestGAEBackend(unittest.TestCase): def setUp(self): - import pusher.urlfetch + import pusher.gae + from google.appengine.api import apiproxy_stub_map, urlfetch_stub + + apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() + apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', + urlfetch_stub.URLFetchServiceStub()) + self.p = pusher.Pusher.from_url(u'http://key:secret@api.pusherapp.com/apps/4', - backend=pusher.urlfetch.URLFetchBackend) + backend=pusher.gae.GAEBackend) @httpretty.activate - def test_trigger_urlfetch_success(self): + def test_trigger_gae_success(self): httpretty.register_uri(httpretty.POST, "http://api.pusherapp.com/apps/4/events", body="{}", content_type="application/json") diff --git a/setup.py b/setup.py index c35e316..377f90c 100644 --- a/setup.py +++ b/setup.py @@ -26,8 +26,7 @@ extras_require={ 'aiohttp': ["aiohttp>=0.9.0"], - 'tornado': ['tornado>=4.0.0'], - 'urlfetch': ['urlfetch>=1.0'] + 'tornado': ['tornado>=4.0.0'] }, test_suite='pusher_tests', From 8e139280186d5364c84027a0504f697877744639 Mon Sep 17 00:00:00 2001 From: Jamie Patel Date: Thu, 28 May 2015 15:23:27 +0100 Subject: [PATCH 2/2] Ignore GAE test on travis --- .travis.yml | 1 - pusher_tests/test_gae_adapter.py | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5daf16d..7fe26b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: python python: - "2.6" - "2.7" -# - "3.2" - "3.3" install: - "python setup.py develop" diff --git a/pusher_tests/test_gae_adapter.py b/pusher_tests/test_gae_adapter.py index b1fd8a6..f50ef49 100644 --- a/pusher_tests/test_gae_adapter.py +++ b/pusher_tests/test_gae_adapter.py @@ -5,13 +5,16 @@ import pusher import httpretty import sys +import os if (sys.version_info < (2,7)): import unittest2 as unittest else: import unittest -@unittest.skipIf(sys.version_info >= (3,), "skip") +skip_test = (sys.version_info[0:2] != (2,7)) or os.environ.get("TRAVIS_PYTHON_VERSION") + +@unittest.skipIf(skip_test, "skip") class TestGAEBackend(unittest.TestCase): def setUp(self):