diff options
Diffstat (limited to 'pecan/scaffolds/rest-api')
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/__init__.py | 0 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/app.py_tmpl | 16 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/controllers/__init__.py | 0 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/controllers/root.py | 53 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/errors.py | 18 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/model/__init__.py | 15 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/tests/__init__.py_tmpl | 22 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/tests/config.py_tmpl | 19 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/tests/test_functional.py_tmpl | 37 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/+package+/tests/test_units.py | 7 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/config.py_tmpl | 48 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/setup.cfg_tmpl | 6 | ||||
-rw-r--r-- | pecan/scaffolds/rest-api/setup.py_tmpl | 22 |
13 files changed, 0 insertions, 263 deletions
diff --git a/pecan/scaffolds/rest-api/+package+/__init__.py b/pecan/scaffolds/rest-api/+package+/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/pecan/scaffolds/rest-api/+package+/__init__.py +++ /dev/null diff --git a/pecan/scaffolds/rest-api/+package+/app.py_tmpl b/pecan/scaffolds/rest-api/+package+/app.py_tmpl deleted file mode 100644 index 3eb5edf..0000000 --- a/pecan/scaffolds/rest-api/+package+/app.py_tmpl +++ /dev/null @@ -1,16 +0,0 @@ -from pecan import make_app -from ${package} import model -from ${package}.errors import JSONErrorHook - - -def setup_app(config): - - model.init_model() - app_conf = dict(config.app) - - return make_app( - app_conf.pop('root'), - logging=getattr(config, 'logging', {}), - hooks=[JSONErrorHook()], - **app_conf - ) diff --git a/pecan/scaffolds/rest-api/+package+/controllers/__init__.py b/pecan/scaffolds/rest-api/+package+/controllers/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/pecan/scaffolds/rest-api/+package+/controllers/__init__.py +++ /dev/null diff --git a/pecan/scaffolds/rest-api/+package+/controllers/root.py b/pecan/scaffolds/rest-api/+package+/controllers/root.py deleted file mode 100644 index f106bb2..0000000 --- a/pecan/scaffolds/rest-api/+package+/controllers/root.py +++ /dev/null @@ -1,53 +0,0 @@ -from pecan import expose, response, abort - -people = { - 1: 'Luke', - 2: 'Leia', - 3: 'Han', - 4: 'Anakin' -} - - -class PersonController(object): - - def __init__(self, person_id): - self.person_id = person_id - - @expose(generic=True) - def index(self): - return people.get(self.person_id) or abort(404) - - @index.when(method='PUT') - def put(self): - # TODO: Idempotent PUT (returns 200 or 204) - response.status = 204 - - @index.when(method='DELETE') - def delete(self): - # TODO: Idempotent DELETE - response.status = 204 - - -class PeopleController(object): - - @expose() - def _lookup(self, person_id, *remainder): - return PersonController(int(person_id)), remainder - - @expose(generic=True, template='json') - def index(self): - return people - - @index.when(method='POST', template='json') - def post(self): - # TODO: Create a new person - response.status = 201 - - -class RootController(object): - - people = PeopleController() - - @expose() - def index(self): - return "Hello, World!" diff --git a/pecan/scaffolds/rest-api/+package+/errors.py b/pecan/scaffolds/rest-api/+package+/errors.py deleted file mode 100644 index 4d4d06c..0000000 --- a/pecan/scaffolds/rest-api/+package+/errors.py +++ /dev/null @@ -1,18 +0,0 @@ -import json -import webob -from pecan.hooks import PecanHook - - -class JSONErrorHook(PecanHook): - """ - A pecan hook that translates webob HTTP errors into a JSON format. - """ - - def on_error(self, state, exc): - if isinstance(exc, webob.exc.HTTPError): - return webob.Response( - body=json.dumps({'reason': str(exc)}), - status=exc.status, - headerlist=exc.headerlist, - content_type='application/json' - ) diff --git a/pecan/scaffolds/rest-api/+package+/model/__init__.py b/pecan/scaffolds/rest-api/+package+/model/__init__.py deleted file mode 100644 index d983f7b..0000000 --- a/pecan/scaffolds/rest-api/+package+/model/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -from pecan import conf # noqa - - -def init_model(): - """ - This is a stub method which is called at application startup time. - - If you need to bind to a parsed database configuration, set up tables or - ORM classes, or perform any database initialization, this is the - recommended place to do it. - - For more information working with databases, and some common recipes, - see http://pecan.readthedocs.org/en/latest/databases.html - """ - pass diff --git a/pecan/scaffolds/rest-api/+package+/tests/__init__.py_tmpl b/pecan/scaffolds/rest-api/+package+/tests/__init__.py_tmpl deleted file mode 100644 index 78ea527..0000000 --- a/pecan/scaffolds/rest-api/+package+/tests/__init__.py_tmpl +++ /dev/null @@ -1,22 +0,0 @@ -import os -from unittest import TestCase -from pecan import set_config -from pecan.testing import load_test_app - -__all__ = ['FunctionalTest'] - - -class FunctionalTest(TestCase): - """ - Used for functional tests where you need to test your - literal application and its integration with the framework. - """ - - def setUp(self): - self.app = load_test_app(os.path.join( - os.path.dirname(__file__), - 'config.py' - )) - - def tearDown(self): - set_config({}, overwrite=True) diff --git a/pecan/scaffolds/rest-api/+package+/tests/config.py_tmpl b/pecan/scaffolds/rest-api/+package+/tests/config.py_tmpl deleted file mode 100644 index 09efcb7..0000000 --- a/pecan/scaffolds/rest-api/+package+/tests/config.py_tmpl +++ /dev/null @@ -1,19 +0,0 @@ -# Server Specific Configurations -server = { - 'port': '8080', - 'host': '0.0.0.0' -} - -# Pecan Application Configurations -app = { - 'root': '${package}.controllers.root.RootController', - 'modules': ['${package}'], - 'debug': True -} - -# Custom Configurations must be in Python dictionary format:: -# -# foo = {'bar':'baz'} -# -# All configurations are accessible at:: -# pecan.conf diff --git a/pecan/scaffolds/rest-api/+package+/tests/test_functional.py_tmpl b/pecan/scaffolds/rest-api/+package+/tests/test_functional.py_tmpl deleted file mode 100644 index db414db..0000000 --- a/pecan/scaffolds/rest-api/+package+/tests/test_functional.py_tmpl +++ /dev/null @@ -1,37 +0,0 @@ -import json -from ${package}.tests import FunctionalTest - - -class TestRootController(FunctionalTest): - - def test_get_all(self): - response = self.app.get('/people/') - assert response.status_int == 200 - assert response.namespace[1] == 'Luke' - assert response.namespace[2] == 'Leia' - assert response.namespace[3] == 'Han' - assert response.namespace[4] == 'Anakin' - - def test_get_one(self): - response = self.app.get('/people/1/') - assert response.status_int == 200 - assert response.body.decode() == 'Luke' - - def test_post(self): - response = self.app.post('/people/') - assert response.status_int == 201 - - def test_put(self): - response = self.app.put('/people/1/') - assert response.status_int == 204 - - def test_delete(self): - response = self.app.delete('/people/1/') - assert response.status_int == 204 - - def test_not_found(self): - response = self.app.get('/missing/', expect_errors=True) - assert response.status_int == 404 - assert json.loads(response.body.decode()) == { - 'reason': 'The resource could not be found.' - } diff --git a/pecan/scaffolds/rest-api/+package+/tests/test_units.py b/pecan/scaffolds/rest-api/+package+/tests/test_units.py deleted file mode 100644 index 573fb68..0000000 --- a/pecan/scaffolds/rest-api/+package+/tests/test_units.py +++ /dev/null @@ -1,7 +0,0 @@ -from unittest import TestCase - - -class TestUnits(TestCase): - - def test_units(self): - assert 5 * 5 == 25 diff --git a/pecan/scaffolds/rest-api/config.py_tmpl b/pecan/scaffolds/rest-api/config.py_tmpl deleted file mode 100644 index a865c6c..0000000 --- a/pecan/scaffolds/rest-api/config.py_tmpl +++ /dev/null @@ -1,48 +0,0 @@ -# Server Specific Configurations -server = { - 'port': '8080', - 'host': '0.0.0.0' -} - -# Pecan Application Configurations -app = { - 'root': '${package}.controllers.root.RootController', - 'modules': ['${package}'], - 'debug': True -} - -logging = { - 'root': {'level': 'INFO', 'handlers': ['console']}, - 'loggers': { - '${package}': {'level': 'DEBUG', 'handlers': ['console']}, - 'pecan': {'level': 'DEBUG', 'handlers': ['console']}, - 'py.warnings': {'handlers': ['console']}, - '__force_dict__': True - }, - 'handlers': { - 'console': { - 'level': 'DEBUG', - 'class': 'logging.StreamHandler', - 'formatter': 'color' - } - }, - 'formatters': { - 'simple': { - 'format': ('%(asctime)s %(levelname)-5.5s [%(name)s]' - '[%(threadName)s] %(message)s') - }, - 'color': { - '()': 'pecan.log.ColorFormatter', - 'format': ('%(asctime)s [%(padded_color_levelname)s] [%(name)s]' - '[%(threadName)s] %(message)s'), - '__force_dict__': True - } - } -} - -# Custom Configurations must be in Python dictionary format:: -# -# foo = {'bar':'baz'} -# -# All configurations are accessible at:: -# pecan.conf diff --git a/pecan/scaffolds/rest-api/setup.cfg_tmpl b/pecan/scaffolds/rest-api/setup.cfg_tmpl deleted file mode 100644 index 111f7cc..0000000 --- a/pecan/scaffolds/rest-api/setup.cfg_tmpl +++ /dev/null @@ -1,6 +0,0 @@ -[nosetests] -match=^test -where=${package} -nocapture=1 -cover-package=${package} -cover-erase=1 diff --git a/pecan/scaffolds/rest-api/setup.py_tmpl b/pecan/scaffolds/rest-api/setup.py_tmpl deleted file mode 100644 index ec47896..0000000 --- a/pecan/scaffolds/rest-api/setup.py_tmpl +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -try: - from setuptools import setup, find_packages -except ImportError: - from ez_setup import use_setuptools - use_setuptools() - from setuptools import setup, find_packages - -setup( - name='${package}', - version='0.1', - description='', - author='', - author_email='', - install_requires=[ - "pecan", - ], - test_suite='${package}', - zip_safe=False, - include_package_data=True, - packages=find_packages(exclude=['ez_setup']) -) |