Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
Add kinto-pusher plugin version in the capability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Jul 27, 2016
1 parent 26b7a10 commit a1ebec8
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
.venv/
build/
develop-eggs/
dist/
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
0.4.0 (unreleased)
------------------

- Nothing changed yet.
- Add the plugin version in the capability.


0.3.0 (2016-05-23)
Expand Down
17 changes: 17 additions & 0 deletions Makefile
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
13 changes: 13 additions & 0 deletions kinto_pusher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import pkg_resources

from pusher import Pusher

#: Module version, as defined in PEP-0396.
__version__ = pkg_resources.get_distribution(__package__).version


def includeme(config):
settings = config.get_settings()
Expand All @@ -9,3 +14,11 @@ def includeme(config):
secret = settings['pusher.secret']

config.registry.pusher = Pusher(app_id, key, secret)

config.add_api_capability(
"pusher",
version=__version__,
description="Notify Pusher when somethings changes.",
url="https://github.com/Kinto/kinto-pusher",
app_id=app_id,
key=key)
76 changes: 76 additions & 0 deletions tests/__init__.py
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
20 changes: 20 additions & 0 deletions tests/test_plugin_setup.py
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'])
30 changes: 26 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
[tox]
envlist = py27,py34,flake8
envlist = py27,py34,kinto-master,flake8

[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/kinto_pusher
commands = python setup.py test
commands = py.test tests --cov-report term-missing --cov kinto_pusher {posargs}
deps =
pytest
pytest-cache
pytest-cover
pytest-sugar
pytest-xdist
pytest-capturelog
mock
unittest2
webtest

[testenv:kinto-master]
commands = py.test tests --cov-report term-missing --cov kinto_pusher {posargs}
deps =
https://github.com/Kinto/kinto/tarball/master
pytest
pytest-cache
pytest-cover
pytest-sugar
pytest-xdist
pytest-capturelog
mock
unittest2
webtest

[testenv:flake8]
commands = flake8 kinto_pusher
Expand Down

0 comments on commit a1ebec8

Please sign in to comment.