summaryrefslogtreecommitdiff
path: root/docs/quick_tutorial/views/tutorial
diff options
context:
space:
mode:
authorChristoph Zwerschke <cito@online.de>2016-04-19 20:07:12 +0200
committerChristoph Zwerschke <cito@online.de>2016-04-19 20:07:12 +0200
commit3629c49e46207ff5162a82883c14937e6ef4c186 (patch)
tree1306181202cb8313f16080789f5b9ab1eeb61d53 /docs/quick_tutorial/views/tutorial
parent804ba0b2f434781e77d2b5191f1cd76a490f6610 (diff)
parent6c16fb020027fac47e4d2e335cd9e264dba8aa3b (diff)
downloadpyramid-3629c49e46207ff5162a82883c14937e6ef4c186.tar.gz
pyramid-3629c49e46207ff5162a82883c14937e6ef4c186.tar.bz2
pyramid-3629c49e46207ff5162a82883c14937e6ef4c186.zip
Merge remote-tracking branch 'refs/remotes/Pylons/master'
Diffstat (limited to 'docs/quick_tutorial/views/tutorial')
-rw-r--r--docs/quick_tutorial/views/tutorial/__init__.py9
-rw-r--r--docs/quick_tutorial/views/tutorial/tests.py44
-rw-r--r--docs/quick_tutorial/views/tutorial/views.py14
3 files changed, 67 insertions, 0 deletions
diff --git a/docs/quick_tutorial/views/tutorial/__init__.py b/docs/quick_tutorial/views/tutorial/__init__.py
new file mode 100644
index 000000000..013d4538f
--- /dev/null
+++ b/docs/quick_tutorial/views/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/views/tutorial/tests.py b/docs/quick_tutorial/views/tutorial/tests.py
new file mode 100644
index 000000000..f1757757c
--- /dev/null
+++ b/docs/quick_tutorial/views/tutorial/tests.py
@@ -0,0 +1,44 @@
+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 home
+
+ request = testing.DummyRequest()
+ response = home(request)
+ self.assertEqual(response.status_code, 200)
+ self.assertIn(b'Visit', response.body)
+
+ def test_hello(self):
+ from .views import hello
+
+ request = testing.DummyRequest()
+ response = hello(request)
+ self.assertEqual(response.status_code, 200)
+ self.assertIn(b'Go back', 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_home(self):
+ res = self.testapp.get('/', status=200)
+ self.assertIn(b'<body>Visit', res.body)
+
+ def test_hello(self):
+ res = self.testapp.get('/howdy', status=200)
+ self.assertIn(b'<body>Go back', res.body)
diff --git a/docs/quick_tutorial/views/tutorial/views.py b/docs/quick_tutorial/views/tutorial/views.py
new file mode 100644
index 000000000..6ff149d7b
--- /dev/null
+++ b/docs/quick_tutorial/views/tutorial/views.py
@@ -0,0 +1,14 @@
+from pyramid.response import Response
+from pyramid.view import view_config
+
+
+# First view, available at http://localhost:6543/
+@view_config(route_name='home')
+def home(request):
+ return Response('<body>Visit <a href="/howdy">hello</a></body>')
+
+
+# /howdy
+@view_config(route_name='hello')
+def hello(request):
+ return Response('<body>Go back <a href="/">home</a></body>')