From 788ef786e8bfa332af26bb2498eee4fefce4abf0 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 8 Mar 2012 12:42:41 -0500 Subject: [PATCH] A bunch of work on the default `pecan create` project scaffold: * Simpified the quickstart app. Now it's a simple intro w/ a "documentation" search form. * Updated the quickstart's project to no longer use py.test. * Added some simple illustration tests into the default scaffolded project to illustrate the correct approach for integration and functional tests. --- pecan/configuration.py | 1 + .../project/+package+/controllers/root.py | 16 ++++---- .../project/+package+/templates/index.html | 20 +++------ .../project/+package+/templates/success.html | 13 ------ .../project/+package+/tests/__init__.py | 0 .../project/+package+/tests/__init__.py_tmpl | 18 ++++++++ .../project/+package+/tests/config.py_tmpl | 27 ++++++++++++ .../project/+package+/tests/test_config.py | 41 ------------------- .../project/+package+/tests/test_root.py_tmpl | 8 +--- pecan/templates/project/public/css/style.css | 10 +++-- .../project/public/javascript/shared.js | 0 pecan/templates/project/setup.cfg | 2 - pecan/templates/project/setup.py_tmpl | 1 + 13 files changed, 69 insertions(+), 88 deletions(-) delete mode 100644 pecan/templates/project/+package+/templates/success.html delete mode 100644 pecan/templates/project/+package+/tests/__init__.py create mode 100644 pecan/templates/project/+package+/tests/__init__.py_tmpl create mode 100644 pecan/templates/project/+package+/tests/config.py_tmpl delete mode 100644 pecan/templates/project/+package+/tests/test_config.py delete mode 100644 pecan/templates/project/public/javascript/shared.js delete mode 100644 pecan/templates/project/setup.cfg diff --git a/pecan/configuration.py b/pecan/configuration.py index b2d08f6..4489bb7 100644 --- a/pecan/configuration.py +++ b/pecan/configuration.py @@ -19,6 +19,7 @@ DEFAULT = { 'static_root' : 'public', 'template_path' : '', 'debug' : False, + 'logging' : False, 'force_canonical' : True, 'errors' : { '__force_dict__' : True diff --git a/pecan/templates/project/+package+/controllers/root.py b/pecan/templates/project/+package+/controllers/root.py index f5f61d3..6f031b9 100644 --- a/pecan/templates/project/+package+/controllers/root.py +++ b/pecan/templates/project/+package+/controllers/root.py @@ -1,11 +1,10 @@ -from pecan import expose +from pecan import expose, redirect from formencode import Schema, validators as v from webob.exc import status_map -class SampleForm(Schema): - name = v.String(not_empty=True) - age = v.Int(not_empty=True) +class SearchForm(Schema): + q = v.String(not_empty=True) class RootController(object): @@ -19,13 +18,12 @@ class RootController(object): @index.when( method = 'POST', - template = 'success.html', - schema = SampleForm(), + schema = SearchForm(), error_handler = '/index', - htmlfill = dict(auto_insert_errors = True, prefix_error = False) + htmlfill = dict(auto_insert_errors = True) ) - def index_post(self, name, age): - return dict(name=name) + def index_post(self, q): + redirect('http://pecan.readthedocs.org/en/latest/search.html?q=%s' % q) @expose('error.html') def error(self, status): diff --git a/pecan/templates/project/+package+/templates/index.html b/pecan/templates/project/+package+/templates/index.html index 5385e88..5215546 100644 --- a/pecan/templates/project/+package+/templates/index.html +++ b/pecan/templates/project/+package+/templates/index.html @@ -20,23 +20,15 @@

- To get an idea of how to develop applications with Pecan, - here is a simple form: + ...or you can search the documentation here:

- - - - - - - - - -
- - +
+ + +
+ Enter search terms or a module, class or function name. diff --git a/pecan/templates/project/+package+/templates/success.html b/pecan/templates/project/+package+/templates/success.html deleted file mode 100644 index 938f006..0000000 --- a/pecan/templates/project/+package+/templates/success.html +++ /dev/null @@ -1,13 +0,0 @@ -<%inherit file="layout.html"/> - -## override the title -<%def name="title()"> - Success! - - -## now define the body -
-

-
-

Your form submission was successful! Thanks, ${name}!

-

Go Back

diff --git a/pecan/templates/project/+package+/tests/__init__.py b/pecan/templates/project/+package+/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pecan/templates/project/+package+/tests/__init__.py_tmpl b/pecan/templates/project/+package+/tests/__init__.py_tmpl new file mode 100644 index 0000000..1af16c3 --- /dev/null +++ b/pecan/templates/project/+package+/tests/__init__.py_tmpl @@ -0,0 +1,18 @@ +from unittest import TestCase +from pecan.configuration import set_config +from pecan.testing import load_test_app + +__all__ = ['EnvironmentTest'] + + +class EnvironmentTest(TestCase): + """ + Used for integration or functional tests where you need to test your + literal application of its integration with the framework. + """ + + def setUp(self): + self.app = load_test_app('config.py') + + def tearDown(self): + set_config({}, overwrite=True) diff --git a/pecan/templates/project/+package+/tests/config.py_tmpl b/pecan/templates/project/+package+/tests/config.py_tmpl new file mode 100644 index 0000000..3ef9c49 --- /dev/null +++ b/pecan/templates/project/+package+/tests/config.py_tmpl @@ -0,0 +1,27 @@ +# Server Specific Configurations +server = { + 'port' : '8080', + 'host' : '0.0.0.0' +} + +# Pecan Application Configurations +app = { + 'root' : '${package}.controllers.root.RootController', + 'modules' : ['${package}'], + 'static_root' : '%(confdir)s/public', + 'template_path' : '%(confdir)s/${package}/templates', + 'reload' : True, + 'debug' : True, + 'logging' : False, + 'errors' : { + '404' : '/error/404', + '__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/templates/project/+package+/tests/test_config.py b/pecan/templates/project/+package+/tests/test_config.py deleted file mode 100644 index b5bcbfd..0000000 --- a/pecan/templates/project/+package+/tests/test_config.py +++ /dev/null @@ -1,41 +0,0 @@ -from unittest import TestCase -import config - - -class TestConfigServer(TestCase): - - def test_server_port(self): - assert config.server['port'] == '8080' - - def test_server_host(self): - assert config.server['host'] == '0.0.0.0' - - -class TestConfigApp(TestCase): - - def test_app_root(self): - root = config.app['root'] - assert root.__class__.__name__ == 'RootController' - - def test_app_modules(self): - assert len(config.app['modules']) == 1 - - def test_app_static_root(self): - assert 'public' in config.app['static_root'] - - def test_app_template_path(self): - assert 'templates' in config.app['template_path'] - - def test_app_reload(self): - assert config.app['reload'] - - def test_app_debug(self): - assert config.app['debug'] - - def test_app_errors(self): - errors = { - '404' : '/error/404', - '__force_dict__' : True - } - - assert config.app['errors'] == errors diff --git a/pecan/templates/project/+package+/tests/test_root.py_tmpl b/pecan/templates/project/+package+/tests/test_root.py_tmpl index 84d38e8..2d08997 100644 --- a/pecan/templates/project/+package+/tests/test_root.py_tmpl +++ b/pecan/templates/project/+package+/tests/test_root.py_tmpl @@ -1,13 +1,9 @@ from unittest import TestCase from webtest import TestApp - -import py.test +from ${package}.tests import EnvironmentTest -class TestRootController(TestCase): - - def setUp(self): - self.app = TestApp(py.test.wsgi_app) +class TestRootController(EnvironmentTest): def test_get(self): response = self.app.get('/') diff --git a/pecan/templates/project/public/css/style.css b/pecan/templates/project/public/css/style.css index 8acc9f7..55c9db5 100644 --- a/pecan/templates/project/public/css/style.css +++ b/pecan/templates/project/public/css/style.css @@ -20,9 +20,13 @@ div#content { } form { - margin: 0 1em; - padding: 1em; - border: 5px transparent; + margin: 0; + padding: 0; + border: 0; +} + +fieldset { + border: 0; } input.error { diff --git a/pecan/templates/project/public/javascript/shared.js b/pecan/templates/project/public/javascript/shared.js deleted file mode 100644 index e69de29..0000000 diff --git a/pecan/templates/project/setup.cfg b/pecan/templates/project/setup.cfg deleted file mode 100644 index aad259c..0000000 --- a/pecan/templates/project/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = -p pecan.testing --with-config=./config.py diff --git a/pecan/templates/project/setup.py_tmpl b/pecan/templates/project/setup.py_tmpl index 864c61c..6a61f15 100644 --- a/pecan/templates/project/setup.py_tmpl +++ b/pecan/templates/project/setup.py_tmpl @@ -15,6 +15,7 @@ setup( install_requires = [ "pecan", ], + test_suite = '${package}', zip_safe = False, paster_plugins = ${egg_plugins}, include_package_data = True,