From b1b92284f496800a4dfd2cea72cb9be07ba8661c Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 16:52:14 -0400 Subject: First cut at import of quick tutorial. --- .../request_response/development.ini | 41 ++++++++++++++++ docs/quick_tutorial/request_response/setup.py | 13 ++++++ .../request_response/tutorial/__init__.py | 9 ++++ .../request_response/tutorial/home.pt | 9 ++++ .../request_response/tutorial/tests.py | 54 ++++++++++++++++++++++ .../request_response/tutorial/views.py | 22 +++++++++ 6 files changed, 148 insertions(+) create mode 100644 docs/quick_tutorial/request_response/development.ini create mode 100644 docs/quick_tutorial/request_response/setup.py create mode 100644 docs/quick_tutorial/request_response/tutorial/__init__.py create mode 100644 docs/quick_tutorial/request_response/tutorial/home.pt create mode 100644 docs/quick_tutorial/request_response/tutorial/tests.py create mode 100644 docs/quick_tutorial/request_response/tutorial/views.py (limited to 'docs/quick_tutorial/request_response') diff --git a/docs/quick_tutorial/request_response/development.ini b/docs/quick_tutorial/request_response/development.ini new file mode 100644 index 000000000..62e0c5123 --- /dev/null +++ b/docs/quick_tutorial/request_response/development.ini @@ -0,0 +1,41 @@ +[app:main] +use = egg:tutorial +pyramid.reload_templates = true +pyramid.includes = + pyramid_debugtoolbar + +[server:main] +use = egg:pyramid#wsgiref +host = 0.0.0.0 +port = 6543 + +# Begin logging configuration + +[loggers] +keys = root, tutorial + +[logger_tutorial] +level = DEBUG +handlers = +qualname = tutorial + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = INFO +handlers = console + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s + +# End logging configuration diff --git a/docs/quick_tutorial/request_response/setup.py b/docs/quick_tutorial/request_response/setup.py new file mode 100644 index 000000000..9997984d3 --- /dev/null +++ b/docs/quick_tutorial/request_response/setup.py @@ -0,0 +1,13 @@ +from setuptools import setup + +requires = [ + 'pyramid', +] + +setup(name='tutorial', + install_requires=requires, + entry_points="""\ + [paste.app_factory] + main = tutorial:main + """, +) \ No newline at end of file diff --git a/docs/quick_tutorial/request_response/tutorial/__init__.py b/docs/quick_tutorial/request_response/tutorial/__init__.py new file mode 100644 index 000000000..77a172888 --- /dev/null +++ b/docs/quick_tutorial/request_response/tutorial/__init__.py @@ -0,0 +1,9 @@ +from pyramid.config import Configurator + + +def main(global_config, **settings): + config = Configurator(settings=settings) + config.add_route('home', '/') + config.add_route('plain', '/plain') + config.scan('.views') + return config.make_wsgi_app() \ No newline at end of file diff --git a/docs/quick_tutorial/request_response/tutorial/home.pt b/docs/quick_tutorial/request_response/tutorial/home.pt new file mode 100644 index 000000000..a0cc08e7a --- /dev/null +++ b/docs/quick_tutorial/request_response/tutorial/home.pt @@ -0,0 +1,9 @@ + + + + Quick Tour: ${name} + + +

Hi ${name}

+ + \ No newline at end of file diff --git a/docs/quick_tutorial/request_response/tutorial/tests.py b/docs/quick_tutorial/request_response/tutorial/tests.py new file mode 100644 index 000000000..87c853375 --- /dev/null +++ b/docs/quick_tutorial/request_response/tutorial/tests.py @@ -0,0 +1,54 @@ +import unittest + +from pyramid import testing + + +class TutorialViewTests(unittest.TestCase): + def setUp(self): + self.config = testing.setUp() + + def tearDown(self): + testing.tearDown() + + def test_home(self): + from .views import TutorialViews + + request = testing.DummyRequest() + inst = TutorialViews(request) + response = inst.home() + self.assertEqual(response.status, '302 Found') + + def test_plain_without_name(self): + from .views import TutorialViews + + request = testing.DummyRequest() + inst = TutorialViews(request) + response = inst.plain() + self.assertIn('No Name Provided', response.body) + + def test_plain_with_name(self): + from .views import TutorialViews + + request = testing.DummyRequest() + request.GET['name'] = 'Jane Doe' + inst = TutorialViews(request) + response = inst.plain() + self.assertIn('Jane Doe', response.body) + + +class TutorialFunctionalTests(unittest.TestCase): + def setUp(self): + from tutorial import main + + app = main({}) + from webtest import TestApp + + self.testapp = TestApp(app) + + def test_plain_without_name(self): + res = self.testapp.get('/plain', status=200) + self.assertIn(b'No Name Provided', res.body) + + def test_plain_with_name(self): + res = self.testapp.get('/plain?name=Jane%20Doe', status=200) + self.assertIn(b'Jane Doe', res.body) diff --git a/docs/quick_tutorial/request_response/tutorial/views.py b/docs/quick_tutorial/request_response/tutorial/views.py new file mode 100644 index 000000000..8c7ff5f37 --- /dev/null +++ b/docs/quick_tutorial/request_response/tutorial/views.py @@ -0,0 +1,22 @@ +from pyramid.httpexceptions import HTTPFound +from pyramid.response import Response +from pyramid.view import view_config + + +class TutorialViews: + def __init__(self, request): + self.request = request + + @view_config(route_name='home') + def home(self): + return HTTPFound(location='/plain') + + @view_config(route_name='plain') + def plain(self): + name = self.request.params.get('name', 'No Name Provided') + + body = 'URL %s with name: %s' % (self.request.url, name) + return Response( + content_type='text/plain', + body=body + ) -- cgit v1.2.3 From 34e974e360184baef873da55f31379697e367f32 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Wed, 25 Sep 2013 12:08:33 -0400 Subject: Get pyramid_chameleon added to the quick tutorial, plus some other fixes for Python 3. --- docs/quick_tutorial/request_response/tutorial/home.pt | 9 --------- docs/quick_tutorial/request_response/tutorial/tests.py | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 docs/quick_tutorial/request_response/tutorial/home.pt (limited to 'docs/quick_tutorial/request_response') diff --git a/docs/quick_tutorial/request_response/tutorial/home.pt b/docs/quick_tutorial/request_response/tutorial/home.pt deleted file mode 100644 index a0cc08e7a..000000000 --- a/docs/quick_tutorial/request_response/tutorial/home.pt +++ /dev/null @@ -1,9 +0,0 @@ - - - - Quick Tour: ${name} - - -

Hi ${name}

- - \ No newline at end of file diff --git a/docs/quick_tutorial/request_response/tutorial/tests.py b/docs/quick_tutorial/request_response/tutorial/tests.py index 87c853375..7486c2b2d 100644 --- a/docs/quick_tutorial/request_response/tutorial/tests.py +++ b/docs/quick_tutorial/request_response/tutorial/tests.py @@ -24,7 +24,7 @@ class TutorialViewTests(unittest.TestCase): request = testing.DummyRequest() inst = TutorialViews(request) response = inst.plain() - self.assertIn('No Name Provided', response.body) + self.assertIn(b'No Name Provided', response.body) def test_plain_with_name(self): from .views import TutorialViews @@ -33,7 +33,7 @@ class TutorialViewTests(unittest.TestCase): request.GET['name'] = 'Jane Doe' inst = TutorialViews(request) response = inst.plain() - self.assertIn('Jane Doe', response.body) + self.assertIn(b'Jane Doe', response.body) class TutorialFunctionalTests(unittest.TestCase): -- cgit v1.2.3 From ba85e591d563ed654f492f7cab5ca492a32a86d7 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Thu, 13 Mar 2014 18:17:43 -0400 Subject: Strip redundant logging config from tutorial INI files. Leave it for the 'logging' and 'scaffolds' sections, where it is germane. --- .../request_response/development.ini | 31 ---------------------- 1 file changed, 31 deletions(-) (limited to 'docs/quick_tutorial/request_response') diff --git a/docs/quick_tutorial/request_response/development.ini b/docs/quick_tutorial/request_response/development.ini index 62e0c5123..4d47e54a5 100644 --- a/docs/quick_tutorial/request_response/development.ini +++ b/docs/quick_tutorial/request_response/development.ini @@ -8,34 +8,3 @@ pyramid.includes = use = egg:pyramid#wsgiref host = 0.0.0.0 port = 6543 - -# Begin logging configuration - -[loggers] -keys = root, tutorial - -[logger_tutorial] -level = DEBUG -handlers = -qualname = tutorial - -[handlers] -keys = console - -[formatters] -keys = generic - -[logger_root] -level = INFO -handlers = console - -[handler_console] -class = StreamHandler -args = (sys.stderr,) -level = NOTSET -formatter = generic - -[formatter_generic] -format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration -- cgit v1.2.3