Permalink
Browse files

fix wiki tests too

  • Loading branch information...
1 parent 231f532 commit 6c9959c34b403c2b1e3088d34b67bef5c79ee9fc @mcdonc mcdonc committed Jul 1, 2011
Showing with 762 additions and 7 deletions.
  1. +3 −3 CHANGES.txt
  2. +5 −0 docs/tutorials/wiki/src/tests/CHANGES.txt
  3. +2 −0 docs/tutorials/wiki/src/tests/MANIFEST.in
  4. +4 −0 docs/tutorials/wiki/src/tests/README.txt
  5. +52 −0 docs/tutorials/wiki/src/tests/development.ini
  6. +71 −0 docs/tutorials/wiki/src/tests/production.ini
  7. +28 −0 docs/tutorials/wiki/src/tests/setup.cfg
  8. +47 −0 docs/tutorials/wiki/src/tests/setup.py
  9. +31 −0 docs/tutorials/wiki/src/tests/tutorial/__init__.py
  10. +45 −0 docs/tutorials/wiki/src/tests/tutorial/login.py
  11. +27 −0 docs/tutorials/wiki/src/tests/tutorial/models.py
  12. +8 −0 docs/tutorials/wiki/src/tests/tutorial/security.py
  13. BIN docs/tutorials/wiki/src/tests/tutorial/static/favicon.ico
  14. BIN docs/tutorials/wiki/src/tests/tutorial/static/footerbg.png
  15. BIN docs/tutorials/wiki/src/tests/tutorial/static/headerbg.png
  16. +8 −0 docs/tutorials/wiki/src/tests/tutorial/static/ie6.css
  17. BIN docs/tutorials/wiki/src/tests/tutorial/static/middlebg.png
  18. +65 −0 docs/tutorials/wiki/src/tests/tutorial/static/pylons.css
  19. BIN docs/tutorials/wiki/src/tests/tutorial/static/pyramid-small.png
  20. BIN docs/tutorials/wiki/src/tests/tutorial/static/pyramid.png
  21. BIN docs/tutorials/wiki/src/tests/tutorial/static/transparent.gif
  22. +62 −0 docs/tutorials/wiki/src/tests/tutorial/templates/edit.pt
  23. +58 −0 docs/tutorials/wiki/src/tests/tutorial/templates/login.pt
  24. +75 −0 docs/tutorials/wiki/src/tests/tutorial/templates/mytemplate.pt
  25. +65 −0 docs/tutorials/wiki/src/tests/tutorial/templates/view.pt
  26. +2 −2 docs/tutorials/wiki/src/tests/tutorial/tests.py
  27. +76 −0 docs/tutorials/wiki/src/tests/tutorial/views.py
  28. +28 −2 docs/tutorials/wiki/tests.rst
View
@@ -25,9 +25,9 @@ Deprecations
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.
+- The Wiki and Wiki2 tutorial "Tests" chapters each had two bugs: neither did
+ told the user to depend on WebTest, and 2 tests failed in each as the
+ result of changes to Pyramid itself. These issues have been fixed.
1.1a3 (2011-06-26)
==================
@@ -0,0 +1,5 @@
+0.0
+---
+
+- Initial version
+
@@ -0,0 +1,2 @@
+include *.txt *.ini *.cfg *.rst
+recursive-include tutorial *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
@@ -0,0 +1,4 @@
+tutorial README
+
+
+
@@ -0,0 +1,52 @@
+[app:tutorial]
+use = egg:tutorial
+reload_templates = true
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = true
+default_locale_name = en
+zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
+
+[pipeline:main]
+pipeline =
+ egg:WebError#evalerror
+ egg:repoze.zodbconn#closer
+ egg:repoze.retry#retry
+ 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
+
+[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
@@ -0,0 +1,71 @@
+[app:tutorial]
+use = egg:tutorial
+reload_templates = false
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = false
+default_locale_name = en
+zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
+
+[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
+ egg:repoze.zodbconn#closer
+ egg:repoze.retry#retry
+ tm
+ tutorial
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, tutorial
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+
+[logger_tutorial]
+level = WARN
+handlers =
+qualname = tutorial
+
+[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
@@ -0,0 +1,28 @@
+[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
+
@@ -0,0 +1,47 @@
+import os
+
+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',
+ 'repoze.zodbconn',
+ 'repoze.tm2>=1.0b1',
+ 'repoze.retry',
+ 'ZODB3',
+ 'WebError',
+ 'docutils',
+ 'WebTest', # add this
+ ]
+
+setup(name='tutorial',
+ version='0.0',
+ description='tutorial',
+ long_description=README + '\n\n' + CHANGES,
+ classifiers=[
+ "Intended Audience :: Developers",
+ "Framework :: Pylons",
+ "Programming Language :: Python",
+ "Topic :: Internet :: WWW/HTTP",
+ "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+ ],
+ author='',
+ author_email='',
+ url='',
+ keywords='web pylons pyramid',
+ packages=find_packages(),
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=requires,
+ tests_require=requires,
+ test_suite="tutorial",
+ entry_points = """\
+ [paste.app_factory]
+ main = tutorial:main
+ """,
+ paster_plugins=['pyramid'],
+ )
+
@@ -0,0 +1,31 @@
+from repoze.zodbconn.finder import PersistentApplicationFinder
+
+from pyramid.config import Configurator
+from pyramid.authentication import AuthTktAuthenticationPolicy
+from pyramid.authorization import ACLAuthorizationPolicy
+
+from tutorial.models import appmaker
+from tutorial.security import groupfinder
+
+def main(global_config, **settings):
+ """ This function returns a WSGI application.
+
+ It is usually called by the PasteDeploy framework during
+ ``paster serve``.
+ """
+ authn_policy = AuthTktAuthenticationPolicy(secret='sosecret',
+ callback=groupfinder)
+ authz_policy = ACLAuthorizationPolicy()
+ zodb_uri = settings.get('zodb_uri', False)
+ if zodb_uri is False:
+ raise ValueError("No 'zodb_uri' in application configuration.")
+
+ finder = PersistentApplicationFinder(zodb_uri, appmaker)
+ def get_root(request):
+ return finder(request.environ)
+ config = Configurator(root_factory=get_root, settings=settings,
+ authentication_policy=authn_policy,
+ authorization_policy=authz_policy)
+ config.add_static_view('static', 'tutorial:static')
+ config.scan('tutorial')
+ return config.make_wsgi_app()
@@ -0,0 +1,45 @@
+from pyramid.httpexceptions import HTTPFound
+
+from pyramid.security import remember
+from pyramid.security import forget
+from pyramid.view import view_config
+from pyramid.url import resource_url
+
+from tutorial.security import USERS
+
+@view_config(context='tutorial.models.Wiki', name='login',
+ renderer='templates/login.pt')
+@view_config(context='pyramid.httpexceptions.HTTPForbidden',
+ renderer='templates/login.pt')
+def login(request):
+ login_url = resource_url(request.context, request, 'login')
+ 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,
+ )
+
+@view_config(context='tutorial.models.Wiki', name='logout')
+def logout(request):
+ headers = forget(request)
+ return HTTPFound(location = resource_url(request.context, request),
+ headers = headers)
+
@@ -0,0 +1,27 @@
+from persistent import Persistent
+from persistent.mapping import PersistentMapping
+
+from pyramid.security import Allow
+from pyramid.security import Everyone
+
+class Wiki(PersistentMapping):
+ __name__ = None
+ __parent__ = None
+ __acl__ = [ (Allow, Everyone, 'view'),
+ (Allow, 'group:editors', 'edit') ]
+
+class Page(Persistent):
+ def __init__(self, data):
+ self.data = data
+
+def appmaker(zodb_root):
+ if not 'app_root' in zodb_root:
+ app_root = Wiki()
+ frontpage = Page('This is the front page')
+ app_root['FrontPage'] = frontpage
+ frontpage.__name__ = 'FrontPage'
+ frontpage.__parent__ = app_root
+ zodb_root['app_root'] = app_root
+ import transaction
+ transaction.commit()
+ return zodb_root['app_root']
@@ -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, [])
+
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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%}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 6c9959c

Please sign in to comment.