Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- The Wiki2 tutorial "Tests" chapter had two bugs: it did not tell th…

…e user

  to depend on WebTest, and 2 tests failed as the result of changes to
  Pyramid itself.  These issues have been fixed.
  • Loading branch information...
commit 05a1b4a37df7e855747f66174a472b0de3ce1c9e 1 parent 371a670
@mcdonc mcdonc authored
Showing with 788 additions and 5 deletions.
  1. +7 −0 CHANGES.txt
  2. +4 −0 docs/tutorials/wiki2/src/tests/CHANGES.txt
  3. +2 −0  docs/tutorials/wiki2/src/tests/MANIFEST.in
  4. +4 −0 docs/tutorials/wiki2/src/tests/README.txt
  5. +58 −0 docs/tutorials/wiki2/src/tests/development.ini
  6. +77 −0 docs/tutorials/wiki2/src/tests/production.ini
  7. +27 −0 docs/tutorials/wiki2/src/tests/setup.cfg
  8. +49 −0 docs/tutorials/wiki2/src/tests/setup.py
  9. +45 −0 docs/tutorials/wiki2/src/tests/tutorial/__init__.py
  10. +38 −0 docs/tutorials/wiki2/src/tests/tutorial/login.py
  11. +50 −0 docs/tutorials/wiki2/src/tests/tutorial/models.py
  12. +8 −0 docs/tutorials/wiki2/src/tests/tutorial/security.py
  13. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/favicon.ico
  14. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/footerbg.png
  15. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/headerbg.png
  16. +8 −0 docs/tutorials/wiki2/src/tests/tutorial/static/ie6.css
  17. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/middlebg.png
  18. +65 −0 docs/tutorials/wiki2/src/tests/tutorial/static/pylons.css
  19. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/pyramid-small.png
  20. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/pyramid.png
  21. BIN  docs/tutorials/wiki2/src/tests/tutorial/static/transparent.gif
  22. +62 −0 docs/tutorials/wiki2/src/tests/tutorial/templates/edit.pt
  23. +58 −0 docs/tutorials/wiki2/src/tests/tutorial/templates/login.pt
  24. +75 −0 docs/tutorials/wiki2/src/tests/tutorial/templates/mytemplate.pt
  25. +65 −0 docs/tutorials/wiki2/src/tests/tutorial/templates/view.pt
  26. +3 −3 docs/tutorials/wiki2/src/tests/tutorial/tests.py
  27. +72 −0 docs/tutorials/wiki2/src/tests/tutorial/views.py
  28. +11 −2 docs/tutorials/wiki2/tests.rst
View
7 CHANGES.txt
@@ -22,6 +22,13 @@ Deprecations
- Deprecated the ``set_renderer_globals_factory`` method of the Configurator
and the ``renderer_globals`` Configurator constructor parameter.
+Documentation
+-------------
+
+- The Wiki2 tutorial "Tests" chapter had two bugs: it did not tell the user
+ to depend on WebTest, and 2 tests failed as the result of changes to
+ Pyramid itself. These issues have been fixed.
+
1.1a3 (2011-06-26)
==================
View
4 docs/tutorials/wiki2/src/tests/CHANGES.txt
@@ -0,0 +1,4 @@
+0.0
+---
+
+- Initial version
View
2  docs/tutorials/wiki2/src/tests/MANIFEST.in
@@ -0,0 +1,2 @@
+include *.txt *.ini *.cfg *.rst
+recursive-include tutorial *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
View
4 docs/tutorials/wiki2/src/tests/README.txt
@@ -0,0 +1,4 @@
+tutorial README
+
+
+
View
58 docs/tutorials/wiki2/src/tests/development.ini
@@ -0,0 +1,58 @@
+[app:tutorial]
+use = egg:tutorial
+reload_templates = true
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = true
+default_locale_name = en
+sqlalchemy.url = sqlite:///%(here)s/tutorial.db
+
+[pipeline:main]
+pipeline =
+ egg:WebError#evalerror
+ tm
+ tutorial
+
+[filter:tm]
+use = egg:repoze.tm2#tm
+commit_veto = repoze.tm:default_commit_veto
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, sqlalchemy
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_sqlalchemy]
+level = INFO
+handlers =
+qualname = sqlalchemy.engine
+# "level = INFO" logs SQL queries.
+# "level = DEBUG" logs SQL queries and results.
+# "level = WARN" logs neither. (Recommended for production systems.)
+
+[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
View
77 docs/tutorials/wiki2/src/tests/production.ini
@@ -0,0 +1,77 @@
+[app:tutorial]
+use = egg:tutorial
+reload_templates = false
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = false
+default_locale_name = en
+sqlalchemy.url = sqlite:///%(here)s/tutorial.db
+
+[filter:weberror]
+use = egg:WebError#error_catcher
+debug = false
+;error_log =
+;show_exceptions_in_wsgi_errors = true
+;smtp_server = localhost
+;error_email = janitor@example.com
+;smtp_username = janitor
+;smtp_password = "janitor's password"
+;from_address = paste@localhost
+;error_subject_prefix = "Pyramid Error"
+;smtp_use_tls =
+;error_message =
+
+[filter:tm]
+use = egg:repoze.tm2#tm
+commit_veto = repoze.tm:default_commit_veto
+
+[pipeline:main]
+pipeline =
+ weberror
+ tm
+ tutorial
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, tutorial, sqlalchemy
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+
+[logger_tutorial]
+level = WARN
+handlers =
+qualname = tutorial
+
+[logger_sqlalchemy]
+level = WARN
+handlers =
+qualname = sqlalchemy.engine
+# "level = INFO" logs SQL queries.
+# "level = DEBUG" logs SQL queries and results.
+# "level = WARN" logs neither. (Recommended for production systems.)
+
+[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
View
27 docs/tutorials/wiki2/src/tests/setup.cfg
@@ -0,0 +1,27 @@
+[nosetests]
+match=^test
+nocapture=1
+cover-package=tutorial
+with-coverage=1
+cover-erase=1
+
+[compile_catalog]
+directory = tutorial/locale
+domain = tutorial
+statistics = true
+
+[extract_messages]
+add_comments = TRANSLATORS:
+output_file = tutorial/locale/tutorial.pot
+width = 80
+
+[init_catalog]
+domain = tutorial
+input_file = tutorial/locale/tutorial.pot
+output_dir = tutorial/locale
+
+[update_catalog]
+domain = tutorial
+input_file = tutorial/locale/tutorial.pot
+output_dir = tutorial/locale
+previous = true
View
49 docs/tutorials/wiki2/src/tests/setup.py
@@ -0,0 +1,49 @@
+import os
+import sys
+
+from setuptools import setup, find_packages
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.txt')).read()
+CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
+
+requires = [
+ 'pyramid',
+ 'SQLAlchemy',
+ 'transaction',
+ 'repoze.tm2>=1.0b1',
+ 'zope.sqlalchemy',
+ 'WebError',
+ 'docutils',
+ 'WebTest', # add this
+ ]
+
+if sys.version_info[:3] < (2,5,0):
+ requires.append('pysqlite')
+
+setup(name='tutorial',
+ version='0.0',
+ description='tutorial',
+ long_description=README + '\n\n' + CHANGES,
+ classifiers=[
+ "Programming Language :: Python",
+ "Framework :: Pylons",
+ "Topic :: Internet :: WWW/HTTP",
+ "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+ ],
+ author='',
+ author_email='',
+ url='',
+ keywords='web wsgi bfg pylons pyramid',
+ packages=find_packages(),
+ include_package_data=True,
+ zip_safe=False,
+ test_suite='tutorial',
+ install_requires = requires,
+ entry_points = """\
+ [paste.app_factory]
+ main = tutorial:main
+ """,
+ paster_plugins=['pyramid'],
+ )
+
View
45 docs/tutorials/wiki2/src/tests/tutorial/__init__.py
@@ -0,0 +1,45 @@
+from pyramid.config import Configurator
+from pyramid.authentication import AuthTktAuthenticationPolicy
+from pyramid.authorization import ACLAuthorizationPolicy
+
+from sqlalchemy import engine_from_config
+
+from tutorial.models import initialize_sql
+from tutorial.security import groupfinder
+
+def main(global_config, **settings):
+ """ This function returns a WSGI application.
+ """
+ engine = engine_from_config(settings, 'sqlalchemy.')
+ initialize_sql(engine)
+ authn_policy = AuthTktAuthenticationPolicy(
+ 'sosecret', callback=groupfinder)
+ authz_policy = ACLAuthorizationPolicy()
+ config = Configurator(settings=settings,
+ root_factory='tutorial.models.RootFactory',
+ authentication_policy=authn_policy,
+ authorization_policy=authz_policy)
+ config.add_static_view('static', 'tutorial:static')
+
+ config.add_route('view_wiki', '/')
+ config.add_route('login', '/login')
+ config.add_route('logout', '/logout')
+ config.add_route('view_page', '/{pagename}')
+ config.add_route('add_page', '/add_page/{pagename}')
+ config.add_route('edit_page', '/{pagename}/edit_page')
+
+ config.add_view('tutorial.views.view_wiki', route_name='view_wiki')
+ config.add_view('tutorial.login.login', route_name='login',
+ renderer='tutorial:templates/login.pt')
+ config.add_view('tutorial.login.logout', route_name='logout')
+ config.add_view('tutorial.views.view_page', route_name='view_page',
+ renderer='tutorial:templates/view.pt')
+ config.add_view('tutorial.views.add_page', route_name='add_page',
+ renderer='tutorial:templates/edit.pt', permission='edit')
+ config.add_view('tutorial.views.edit_page', route_name='edit_page',
+ renderer='tutorial:templates/edit.pt', permission='edit')
+ config.add_view('tutorial.login.login',
+ context='pyramid.httpexceptions.HTTPForbidden',
+ renderer='tutorial:templates/login.pt')
+ return config.make_wsgi_app()
+
View
38 docs/tutorials/wiki2/src/tests/tutorial/login.py
@@ -0,0 +1,38 @@
+from pyramid.httpexceptions import HTTPFound
+from pyramid.security import remember
+from pyramid.security import forget
+from pyramid.url import route_url
+
+from tutorial.security import USERS
+
+def login(request):
+ login_url = route_url('login', request)
+ referrer = request.url
+ if referrer == login_url:
+ referrer = '/' # never use the login form itself as came_from
+ came_from = request.params.get('came_from', referrer)
+ message = ''
+ login = ''
+ password = ''
+ if 'form.submitted' in request.params:
+ login = request.params['login']
+ password = request.params['password']
+ if USERS.get(login) == password:
+ headers = remember(request, login)
+ return HTTPFound(location = came_from,
+ headers = headers)
+ message = 'Failed login'
+
+ return dict(
+ message = message,
+ url = request.application_url + '/login',
+ came_from = came_from,
+ login = login,
+ password = password,
+ )
+
+def logout(request):
+ headers = forget(request)
+ return HTTPFound(location = route_url('view_wiki', request),
+ headers = headers)
+
View
50 docs/tutorials/wiki2/src/tests/tutorial/models.py
@@ -0,0 +1,50 @@
+import transaction
+
+from pyramid.security import Allow
+from pyramid.security import Everyone
+
+from sqlalchemy import Column
+from sqlalchemy import Integer
+from sqlalchemy import Text
+
+from sqlalchemy.exc import IntegrityError
+from sqlalchemy.ext.declarative import declarative_base
+
+from sqlalchemy.orm import scoped_session
+from sqlalchemy.orm import sessionmaker
+
+from zope.sqlalchemy import ZopeTransactionExtension
+
+DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
+Base = declarative_base()
+
+class Page(Base):
+ """ The SQLAlchemy declarative model class for a Page object. """
+ __tablename__ = 'pages'
+ id = Column(Integer, primary_key=True)
+ name = Column(Text, unique=True)
+ data = Column(Text)
+
+ def __init__(self, name, data):
+ self.name = name
+ self.data = data
+
+def initialize_sql(engine):
+ DBSession.configure(bind=engine)
+ Base.metadata.bind = engine
+ Base.metadata.create_all(engine)
+ try:
+ transaction.begin()
+ session = DBSession()
+ page = Page('FrontPage', 'This is the front page')
+ session.add(page)
+ transaction.commit()
+ except IntegrityError:
+ # already created
+ pass
+
+class RootFactory(object):
+ __acl__ = [ (Allow, Everyone, 'view'),
+ (Allow, 'group:editors', 'edit') ]
+ def __init__(self, request):
+ pass
View
8 docs/tutorials/wiki2/src/tests/tutorial/security.py
@@ -0,0 +1,8 @@
+USERS = {'editor':'editor',
+ 'viewer':'viewer'}
+GROUPS = {'editor':['group:editors']}
+
+def groupfinder(userid, request):
+ if userid in USERS:
+ return GROUPS.get(userid, [])
+
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/favicon.ico
Binary file not shown
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/footerbg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/headerbg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
8 docs/tutorials/wiki2/src/tests/tutorial/static/ie6.css
@@ -0,0 +1,8 @@
+* html img,
+* html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
+this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')",
+this.src = "static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
+this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')",
+this.runtimeStyle.backgroundImage = "none")),this.pngSet=true)
+);}
+#wrap{display:table;height:100%}
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/middlebg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
65 docs/tutorials/wiki2/src/tests/tutorial/static/pylons.css
@@ -0,0 +1,65 @@
+html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;/* 16px */
+vertical-align:baseline;background:transparent;}
+body{line-height:1;}
+ol,ul{list-style:none;}
+blockquote,q{quotes:none;}
+blockquote:before,blockquote:after,q:before,q:after{content:'';content:none;}
+:focus{outline:0;}
+ins{text-decoration:none;}
+del{text-decoration:line-through;}
+table{border-collapse:collapse;border-spacing:0;}
+sub{vertical-align:sub;font-size:smaller;line-height:normal;}
+sup{vertical-align:super;font-size:smaller;line-height:normal;}
+ul,menu,dir{display:block;list-style-type:disc;margin:1em 0;padding-left:40px;}
+ol{display:block;list-style-type:decimal-leading-zero;margin:1em 0;padding-left:40px;}
+li{display:list-item;}
+ul ul,ul ol,ul dir,ul menu,ul dl,ol ul,ol ol,ol dir,ol menu,ol dl,dir ul,dir ol,dir dir,dir menu,dir dl,menu ul,menu ol,menu dir,menu menu,menu dl,dl ul,dl ol,dl dir,dl menu,dl dl{margin-top:0;margin-bottom:0;}
+ol ul,ul ul,menu ul,dir ul,ol menu,ul menu,menu menu,dir menu,ol dir,ul dir,menu dir,dir dir{list-style-type:circle;}
+ol ol ul,ol ul ul,ol menu ul,ol dir ul,ol ol menu,ol ul menu,ol menu menu,ol dir menu,ol ol dir,ol ul dir,ol menu dir,ol dir dir,ul ol ul,ul ul ul,ul menu ul,ul dir ul,ul ol menu,ul ul menu,ul menu menu,ul dir menu,ul ol dir,ul ul dir,ul menu dir,ul dir dir,menu ol ul,menu ul ul,menu menu ul,menu dir ul,menu ol menu,menu ul menu,menu menu menu,menu dir menu,menu ol dir,menu ul dir,menu menu dir,menu dir dir,dir ol ul,dir ul ul,dir menu ul,dir dir ul,dir ol menu,dir ul menu,dir menu menu,dir dir menu,dir ol dir,dir ul dir,dir menu dir,dir dir dir{list-style-type:square;}
+.hidden{display:none;}
+p{line-height:1.5em;}
+h1{font-size:1.75em;line-height:1.7em;font-family:helvetica,verdana;}
+h2{font-size:1.5em;line-height:1.7em;font-family:helvetica,verdana;}
+h3{font-size:1.25em;line-height:1.7em;font-family:helvetica,verdana;}
+h4{font-size:1em;line-height:1.7em;font-family:helvetica,verdana;}
+html,body{width:100%;height:100%;}
+body{margin:0;padding:0;background-color:#ffffff;position:relative;font:16px/24px "Nobile","Lucida Grande",Lucida,Verdana,sans-serif;}
+a{color:#1b61d6;text-decoration:none;}
+a:hover{color:#e88f00;text-decoration:underline;}
+body h1,
+body h2,
+body h3,
+body h4,
+body h5,
+body h6{font-family:"Neuton","Lucida Grande",Lucida,Verdana,sans-serif;font-weight:normal;color:#373839;font-style:normal;}
+#wrap{min-height:100%;}
+#header,#footer{width:100%;color:#ffffff;height:40px;position:absolute;text-align:center;line-height:40px;overflow:hidden;font-size:12px;vertical-align:middle;}
+#header{background:#000000;top:0;font-size:14px;}
+#footer{bottom:0;background:#000000 url(footerbg.png) repeat-x 0 top;position:relative;margin-top:-40px;clear:both;}
+.header,.footer{width:750px;margin-right:auto;margin-left:auto;}
+.wrapper{width:100%}
+#top,#top-small,#bottom{width:100%;}
+#top{color:#000000;height:230px;background:#ffffff url(headerbg.png) repeat-x 0 top;position:relative;}
+#top-small{color:#000000;height:60px;background:#ffffff url(headerbg.png) repeat-x 0 top;position:relative;}
+#bottom{color:#222;background-color:#ffffff;}
+.top,.top-small,.middle,.bottom{width:750px;margin-right:auto;margin-left:auto;}
+.top{padding-top:40px;}
+.top-small{padding-top:10px;}
+#middle{width:100%;height:100px;background:url(middlebg.png) repeat-x;border-top:2px solid #ffffff;border-bottom:2px solid #b2b2b2;}
+.app-welcome{margin-top:25px;}
+.app-name{color:#000000;font-weight:bold;}
+.bottom{padding-top:50px;}
+#left{width:350px;float:left;padding-right:25px;}
+#right{width:350px;float:right;padding-left:25px;}
+.align-left{text-align:left;}
+.align-right{text-align:right;}
+.align-center{text-align:center;}
+ul.links{margin:0;padding:0;}
+ul.links li{list-style-type:none;font-size:14px;}
+form{border-style:none;}
+fieldset{border-style:none;}
+input{color:#222;border:1px solid #ccc;font-family:sans-serif;font-size:12px;line-height:16px;}
+input[type=text],input[type=password]{width:205px;}
+input[type=submit]{background-color:#ddd;font-weight:bold;}
+/*Opera Fix*/
+body:before{content:"";height:100%;float:left;width:0;margin-top:-32767px;}
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/pyramid-small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/pyramid.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  docs/tutorials/wiki2/src/tests/tutorial/static/transparent.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
62 docs/tutorials/wiki2/src/tests/tutorial/templates/edit.pt
@@ -0,0 +1,62 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ xmlns:tal="http://xml.zope.org/namespaces/tal">
+<head>
+ <title>${page.name} - Pyramid tutorial wiki (based on
+ TurboGears 20-Minute Wiki)</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <meta name="keywords" content="python web application" />
+ <meta name="description" content="pyramid web application" />
+ <link rel="shortcut icon"
+ href="${request.static_url('tutorial:static/favicon.ico')}" />
+ <link rel="stylesheet"
+ href="${request.static_url('tutorial:static/pylons.css')}"
+ type="text/css" media="screen" charset="utf-8" />
+ <!--[if lte IE 6]>
+ <link rel="stylesheet"
+ href="${request.static_url('tutorial:static/ie6.css')}"
+ type="text/css" media="screen" charset="utf-8" />
+ <![endif]-->
+</head>
+<body>
+ <div id="wrap">
+ <div id="top-small">
+ <div class="top-small align-center">
+ <div>
+ <img width="220" height="50" alt="pyramid"
+ src="${request.static_url('tutorial:static/pyramid-small.png')}" />
+ </div>
+ </div>
+ </div>
+ <div id="middle">
+ <div class="middle align-right">
+ <div id="left" class="app-welcome align-left">
+ Editing <b><span tal:replace="page.name">Page Name
+ Goes Here</span></b><br/>
+ You can return to the
+ <a href="${request.application_url}">FrontPage</a>.<br/>
+ </div>
+ <div id="right" class="app-welcome align-right">
+ <span tal:condition="logged_in">
+ <a href="${request.application_url}/logout">Logout</a>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div id="bottom">
+ <div class="bottom">
+ <form action="${save_url}" method="post">
+ <textarea name="body" tal:content="page.data" rows="10"
+ cols="60"/><br/>
+ <input type="submit" name="form.submitted" value="Save"/>
+ </form>
+ </div>
+ </div>
+ </div>
+ <div id="footer">
+ <div class="footer"
+ >&copy; Copyright 2008-2011, Agendaless Consulting.</div>
+ </div>
+</body>
+</html>
View
58 docs/tutorials/wiki2/src/tests/tutorial/templates/login.pt
@@ -0,0 +1,58 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ xmlns:tal="http://xml.zope.org/namespaces/tal">
+<head>
+ <title>Login - Pyramid tutorial wiki (based on TurboGears
+ 20-Minute Wiki)</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <meta name="keywords" content="python web application" />
+ <meta name="description" content="pyramid web application" />
+ <link rel="shortcut icon"
+ href="${request.static_url('tutorial:static/favicon.ico')}" />
+ <link rel="stylesheet"
+ href="${request.static_url('tutorial:static/pylons.css')}"
+ type="text/css" media="screen" charset="utf-8" />
+ <!--[if lte IE 6]>
+ <link rel="stylesheet"
+ href="${request.static_url('tutorial:static/ie6.css')}"
+ type="text/css" media="screen" charset="utf-8" />
+ <![endif]-->
+</head>
+<body>
+ <div id="wrap">
+ <div id="top-small">
+ <div class="top-small align-center">
+ <div>
+ <img width="220" height="50" alt="pyramid"
+ src="${request.static_url('tutorial:static/pyramid-small.png')}" />
+ </div>
+ </div>
+ </div>
+ <div id="middle">
+ <div class="middle align-right">
+ <div id="left" class="app-welcome align-left">
+ <b>Login</b><br/>
+ <span tal:replace="message"/>
+ </div>
+ <div id="right" class="app-welcome align-right"></div>
+ </div>
+ </div>
+ <div id="bottom">
+ <div class="bottom">
+ <form action="${url}" method="post">
+ <input type="hidden" name="came_from" value="${came_from}"/>
+ <input type="text" name="login" value="${login}"/><br/>
+ <input type="password" name="password"
+ value="${password}"/><br/>
+ <input type="submit" name="form.submitted" value="Log In"/>
+ </form>
+ </div>
+ </div>
+ </div>
+ <div id="footer">
+ <div class="footer"
+ >&copy; Copyright 2008-2011, Agendaless Consulting.</div>
+ </div>
+</body>
+</html>
View
75 docs/tutorials/wiki2/src/tests/tutorial/templates/mytemplate.pt
@@ -0,0 +1,75 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal">
+<head>
+ <title>The Pyramid Web Application Development Framework</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <meta name="keywords" content="python web application" />
+ <meta name="description" content="pyramid web application" />
+ <link rel="shortcut icon" href="${request.static_url('tutorial:static/favicon.ico')}" />
+ <link rel="stylesheet" href="${request.static_url('tutorial:static/pylons.css')}" type="text/css" media="screen" charset="utf-8" />
+ <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Neuton|Nobile:regular,i,b,bi&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
+ <!--[if lte IE 6]>
+ <link rel="stylesheet" href="${request.static_url('tutorial:static/ie6.css')}" type="text/css" media="screen" charset="utf-8" />
+ <![endif]-->
+</head>
+<body>
+ <div id="wrap">
+ <div id="top">
+ <div class="top align-center">
+ <div><img src="${request.static_url('tutorial:static/pyramid.png')}" width="750" height="169" alt="pyramid"/></div>
+ </div>
+ </div>
+ <div id="middle">
+ <div class="middle align-center">
+ <p class="app-welcome">
+ Welcome to <span class="app-name">${project}</span>, an application generated by<br/>
+ the Pyramid web application development framework.
+ </p>
+ </div>
+ </div>
+ <div id="bottom">
+ <div class="bottom">
+ <div id="left" class="align-right">
+ <h2>Search documentation</h2>
+ <form method="get" action="http://docs.pylonsproject.org/projects/pyramid/dev/search.html">
+ <input type="text" id="q" name="q" value="" />
+ <input type="submit" id="x" value="Go" />
+ </form>
+ </div>
+ <div id="right" class="align-left">
+ <h2>Pyramid links</h2>
+ <ul class="links">
+ <li>
+ <a href="http://pylonsproject.org">Pylons Website</a>
+ </li>
+ <li>
+ <a href="http://docs.pylonsproject.org/projects/pyramid/dev/#narrative-documentation">Narrative Documentation</a>
+ </li>
+ <li>
+ <a href="http://docs.pylonsproject.org/projects/pyramid/dev/#api-documentation">API Documentation</a>
+ </li>
+ <li>
+ <a href="http://docs.pylonsproject.org/projects/pyramid/dev/#tutorials">Tutorials</a>
+ </li>
+ <li>
+ <a href="http://docs.pylonsproject.org/projects/pyramid/dev/#change-history">Change History</a>
+ </li>
+ <li>
+ <a href="http://docs.pylonsproject.org/projects/pyramid/dev/#sample-applications">Sample Applications</a>
+ </li>
+ <li>
+ <a href="http://docs.pylonsproject.org/projects/pyramid/dev/#support-and-development">Support and Development</a>
+ </li>
+ <li>
+ <a href="irc://irc.freenode.net#pyramid">IRC Channel</a>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div id="footer">
+ <div class="footer">&copy; Copyright 2008-2011, Agendaless Consulting.</div>
+ </div>
+</body>
+</html>
View
65 docs/tutorials/wiki2/src/tests/tutorial/templates/view.pt
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ xmlns:tal="http://xml.zope.org/namespaces/tal">
+<head>
+ <title>${page.name} - Pyramid tutorial wiki (based on
+ TurboGears 20-Minute Wiki)</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+ <meta name="keywords" content="python web application" />
+ <meta name="description" content="pyramid web application" />
+ <link rel="shortcut icon"
+ href="${request.static_url('tutorial:static/favicon.ico')}" />
+ <link rel="stylesheet"
+ href="${request.static_url('tutorial:static/pylons.css')}"
+ type="text/css" media="screen" charset="utf-8" />
+ <!--[if lte IE 6]>
+ <link rel="stylesheet"
+ href="${request.static_url('tutorial:static/ie6.css')}"
+ type="text/css" media="screen" charset="utf-8" />
+ <![endif]-->
+</head>
+<body>
+ <div id="wrap">
+ <div id="top-small">
+ <div class="top-small align-center">
+ <div>
+ <img width="220" height="50" alt="pyramid"
+ src="${request.static_url('tutorial:static/pyramid-small.png')}" />
+ </div>
+ </div>
+ </div>
+ <div id="middle">
+ <div class="middle align-right">
+ <div id="left" class="app-welcome align-left">
+ Viewing <b><span tal:replace="page.name">Page Name
+ Goes Here</span></b><br/>
+ You can return to the
+ <a href="${request.application_url}">FrontPage</a>.<br/>
+ </div>
+ <div id="right" class="app-welcome align-right">
+ <span tal:condition="logged_in">
+ <a href="${request.application_url}/logout">Logout</a>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div id="bottom">
+ <div class="bottom">
+ <div tal:replace="structure content">
+ Page text goes here.
+ </div>
+ <p>
+ <a tal:attributes="href edit_url" href="">
+ Edit this page
+ </a>
+ </p>
+ </div>
+ </div>
+ </div>
+ <div id="footer">
+ <div class="footer"
+ >&copy; Copyright 2008-2011, Agendaless Consulting.</div>
+ </div>
+</body>
+</html>
View
6 docs/tutorials/wiki2/src/tests/tutorial/tests.py
@@ -204,18 +204,18 @@ def tearDown(self):
def test_root(self):
res = self.testapp.get('/', status=302)
- self.assertTrue(not res.body)
+ self.assertTrue(res.location, 'http://localhost/FrontPage')
def test_FrontPage(self):
res = self.testapp.get('/FrontPage', status=200)
self.assertTrue('FrontPage' in res.body)
def test_unexisting_page(self):
- res = self.testapp.get('/SomePage', status=404)
+ self.testapp.get('/SomePage', status=404)
def test_successful_log_in(self):
res = self.testapp.get(self.viewer_login, status=302)
- self.assertTrue(res.location == 'FrontPage')
+ self.assertTrue(res.location == 'http://localhost/FrontPage')
def test_failed_log_in(self):
res = self.testapp.get(self.viewer_wrong_login, status=200)
View
72 docs/tutorials/wiki2/src/tests/tutorial/views.py
@@ -0,0 +1,72 @@
+import re
+
+from docutils.core import publish_parts
+
+from pyramid.httpexceptions import HTTPFound, HTTPNotFound
+from pyramid.security import authenticated_userid
+from pyramid.url import route_url
+
+from tutorial.models import DBSession
+from tutorial.models import Page
+
+# regular expression used to find WikiWords
+wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)")
+
+def view_wiki(request):
+ return HTTPFound(location = route_url('view_page', request,
+ pagename='FrontPage'))
+
+def view_page(request):
+ pagename = request.matchdict['pagename']
+ session = DBSession()
+ page = session.query(Page).filter_by(name=pagename).first()
+ if page is None:
+ return HTTPNotFound('No such page')
+
+ def check(match):
+ word = match.group(1)
+ exists = session.query(Page).filter_by(name=word).all()
+ if exists:
+ view_url = route_url('view_page', request, pagename=word)
+ return '<a href="%s">%s</a>' % (view_url, word)
+ else:
+ add_url = route_url('add_page', request, pagename=word)
+ return '<a href="%s">%s</a>' % (add_url, word)
+
+ content = publish_parts(page.data, writer_name='html')['html_body']
+ content = wikiwords.sub(check, content)
+ edit_url = route_url('edit_page', request, pagename=pagename)
+ logged_in = authenticated_userid(request)
+ return dict(page=page, content=content, edit_url=edit_url,
+ logged_in=logged_in)
+
+def add_page(request):
+ name = request.matchdict['pagename']
+ if 'form.submitted' in request.params:
+ session = DBSession()
+ body = request.params['body']
+ page = Page(name, body)
+ session.add(page)
+ return HTTPFound(location = route_url('view_page', request,
+ pagename=name))
+ save_url = route_url('add_page', request, pagename=name)
+ page = Page('', '')
+ logged_in = authenticated_userid(request)
+ return dict(page=page, save_url=save_url, logged_in=logged_in)
+
+def edit_page(request):
+ name = request.matchdict['pagename']
+ session = DBSession()
+ page = session.query(Page).filter_by(name=name).one()
+ if 'form.submitted' in request.params:
+ page.data = request.params['body']
+ session.add(page)
+ return HTTPFound(location = route_url('view_page', request,
+ pagename=name))
+
+ logged_in = authenticated_userid(request)
+ return dict(
+ page=page,
+ save_url = route_url('edit_page', request, pagename=name),
+ logged_in = logged_in,
+ )
View
13 docs/tutorials/wiki2/tests.rst
@@ -48,8 +48,17 @@ Running the Tests
=================
We can run these tests by using ``setup.py test`` in the same way we did in
-:ref:`running_tests`. Assuming our shell's current working directory is the
-"tutorial" distribution directory:
+:ref:`running_tests`. However, first we must edit our ``setup.py`` to
+include a dependency on WebTest, which we've used in our ``tests.py``.
+Change the ``requires`` list in ``setup.py`` to include ``WebTest``.
+
+.. literalinclude:: src/tests/setup.py
+ :linenos:
+ :language: python
+ :lines: 10-19
+
+After we've added a dependency on WebTest in ``setup.py``, assuming our
+shell's current working directory is the "tutorial" distribution directory:
On UNIX:
Please sign in to comment.
Something went wrong with that request. Please try again.