diff options
| author | Chris McDonough <chrism@plope.com> | 2013-10-01 10:49:37 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-10-01 10:49:37 -0400 |
| commit | 5f3405096173450e43152c2d7172cca97512ac4e (patch) | |
| tree | 0f6b27ad2f0244d488454c572b869a3501d2acda /docs/quick_tutorial/jinja2/tutorial | |
| parent | d65b1597ddbdfb161a0c83c46b5ebad878571c76 (diff) | |
| parent | 1a76ed41b133ea73c7d40997c6f564fd72d7273e (diff) | |
| download | pyramid-5f3405096173450e43152c2d7172cca97512ac4e.tar.gz pyramid-5f3405096173450e43152c2d7172cca97512ac4e.tar.bz2 pyramid-5f3405096173450e43152c2d7172cca97512ac4e.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/quick_tutorial/jinja2/tutorial')
| -rw-r--r-- | docs/quick_tutorial/jinja2/tutorial/__init__.py | 9 | ||||
| -rw-r--r-- | docs/quick_tutorial/jinja2/tutorial/home.jinja2 | 9 | ||||
| -rw-r--r-- | docs/quick_tutorial/jinja2/tutorial/tests.py | 50 | ||||
| -rw-r--r-- | docs/quick_tutorial/jinja2/tutorial/views.py | 18 |
4 files changed, 86 insertions, 0 deletions
diff --git a/docs/quick_tutorial/jinja2/tutorial/__init__.py b/docs/quick_tutorial/jinja2/tutorial/__init__.py new file mode 100644 index 000000000..013d4538f --- /dev/null +++ b/docs/quick_tutorial/jinja2/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('hello', '/howdy') + config.scan('.views') + return config.make_wsgi_app()
\ No newline at end of file diff --git a/docs/quick_tutorial/jinja2/tutorial/home.jinja2 b/docs/quick_tutorial/jinja2/tutorial/home.jinja2 new file mode 100644 index 000000000..975323169 --- /dev/null +++ b/docs/quick_tutorial/jinja2/tutorial/home.jinja2 @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Quick Tour: {{ name }}</title> +</head> +<body> +<h1>Hi {{ name }}</h1> +</body> +</html>
\ No newline at end of file diff --git a/docs/quick_tutorial/jinja2/tutorial/tests.py b/docs/quick_tutorial/jinja2/tutorial/tests.py new file mode 100644 index 000000000..0b22946f3 --- /dev/null +++ b/docs/quick_tutorial/jinja2/tutorial/tests.py @@ -0,0 +1,50 @@ +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('Home View', response['name']) + + def test_hello(self): + from .views import TutorialViews + + request = testing.DummyRequest() + inst = TutorialViews(request) + response = inst.hello() + self.assertEqual('Hello View', response['name']) + + +class TutorialFunctionalTests(unittest.TestCase): + def setUp(self): + from tutorial import main + + settings = { + 'pyramid.includes': [ + 'pyramid_jinja2' + ] + } + app = main({}, **settings) + from webtest import TestApp + + self.testapp = TestApp(app) + + def test_home(self): + res = self.testapp.get('/', status=200) + self.assertIn(b'<h1>Hi Home View', res.body) + + def test_hello(self): + res = self.testapp.get('/howdy', status=200) + self.assertIn(b'<h1>Hi Hello View', res.body) diff --git a/docs/quick_tutorial/jinja2/tutorial/views.py b/docs/quick_tutorial/jinja2/tutorial/views.py new file mode 100644 index 000000000..fa9ec5121 --- /dev/null +++ b/docs/quick_tutorial/jinja2/tutorial/views.py @@ -0,0 +1,18 @@ +from pyramid.view import ( + view_config, + view_defaults + ) + + +@view_defaults(renderer='home.jinja2') +class TutorialViews: + def __init__(self, request): + self.request = request + + @view_config(route_name='home') + def home(self): + return {'name': 'Home View'} + + @view_config(route_name='hello') + def hello(self): + return {'name': 'Hello View'} |
