This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kinto-pusher plugin version in the capability.
- Loading branch information
Rémy HUBSCHER
committed
Jul 27, 2016
1 parent
26b7a10
commit a1ebec8
Showing
7 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ __pycache__/ | |
# Distribution / packaging | ||
.Python | ||
env/ | ||
.venv/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
VIRTUALENV = virtualenv | ||
VENV := $(shell echo $${VIRTUAL_ENV-.venv}) | ||
PYTHON = $(VENV)/bin/python | ||
TOX = $(VENV)/bin/tox | ||
TEMPDIR := $(shell mktemp -d) | ||
|
||
build-requirements: | ||
$(VIRTUALENV) $(TEMPDIR) | ||
$(TEMPDIR)/bin/pip install -U pip | ||
$(TEMPDIR)/bin/pip install -Ue . | ||
$(TEMPDIR)/bin/pip freeze > requirements.txt | ||
|
||
virtualenv: $(PYTHON) | ||
$(PYTHON): | ||
virtualenv $(VENV) | ||
|
||
tox: $(TOX) | ||
$(TOX): virtualenv | ||
$(VENV)/bin/pip install tox | ||
|
||
tests-once: tox | ||
$(VENV)/bin/tox -e py27 | ||
|
||
tests: tox | ||
$(VENV)/bin/tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
import kinto.core | ||
import webtest | ||
|
||
from kinto.core.utils import random_bytes_hex | ||
from pyramid.config import Configurator | ||
|
||
|
||
def get_request_class(prefix): | ||
|
||
class PrefixedRequestClass(webtest.app.TestRequest): | ||
|
||
@classmethod | ||
def blank(cls, path, *args, **kwargs): | ||
path = '/%s%s' % (prefix, path) | ||
return webtest.app.TestRequest.blank(path, *args, **kwargs) | ||
|
||
return PrefixedRequestClass | ||
|
||
|
||
class BaseWebTest(object): | ||
"""Base Web Test to test your cornice service. | ||
It setups the database before each test and delete it after. | ||
""" | ||
|
||
api_prefix = "v1" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(BaseWebTest, self).__init__(*args, **kwargs) | ||
self.app = self._get_test_app() | ||
self.headers = { | ||
'Content-Type': 'application/json', | ||
} | ||
|
||
def _get_test_app(self, settings=None): | ||
config = self._get_app_config(settings) | ||
wsgi_app = config.make_wsgi_app() | ||
app = webtest.TestApp(wsgi_app) | ||
app.RequestClass = get_request_class(self.api_prefix) | ||
return app | ||
|
||
def _get_app_config(self, settings=None): | ||
config = Configurator(settings=self.get_app_settings(settings)) | ||
kinto.core.initialize(config, version='1.0.1') | ||
return config | ||
|
||
def get_app_settings(self, additional_settings=None): | ||
""" | ||
kinto.includes = kinto_pusher | ||
kinto.event_listeners = pusher | ||
kinto.event_listeners.pusher.use = kinto_pusher.listener | ||
kinto.event_listeners.pusher.resources = <list of resource names> | ||
kinto.event_listeners.pusher.channel = <channel-name or pattern> | ||
pusher.app_id = <pusher-app-id> | ||
pusher.key = <pusher-key> | ||
pusher.secret = <pusher-secret> | ||
""" | ||
settings = kinto.core.DEFAULT_SETTINGS.copy() | ||
settings['includes'] = 'kinto_pusher' | ||
settings['cache_backend'] = 'kinto.core.cache.memory' | ||
settings['cache_backend'] = 'kinto.core.cache.memory' | ||
settings['userid_hmac_secret'] = random_bytes_hex(16) | ||
settings['event_listeners'] = "pusher" | ||
settings['event_listeners.pusher.use'] = "kinto_pusher.listener" | ||
settings['event_listeners.pusher.resources'] = "records" | ||
pattern = "{bucket_id}-{collection_id}-{resource_name}" | ||
settings['event_listeners.pusher.channel'] = pattern | ||
settings['pusher.app_id'] = "12345" | ||
settings['pusher.key'] = "demo-key" | ||
settings['pusher.secret'] = "demo-secret" | ||
|
||
if additional_settings is not None: | ||
settings.update(additional_settings) | ||
return settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from kinto.tests.support import unittest | ||
from . import BaseWebTest | ||
|
||
from kinto_pusher import __version__ as pusher_version | ||
|
||
|
||
class CapabilityTestView(BaseWebTest, unittest.TestCase): | ||
|
||
def test_fxa_capability(self, additional_settings=None): | ||
resp = self.app.get('/') | ||
capabilities = resp.json['capabilities'] | ||
self.assertIn('pusher', capabilities) | ||
expected = { | ||
"version": pusher_version, | ||
"url": "https://github.com/Kinto/kinto-pusher", | ||
"description": "Notify Pusher when somethings changes.", | ||
"app_id": "12345", | ||
"key": "demo-key" | ||
} | ||
self.assertEqual(expected, capabilities['pusher']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters