Skip to content

Commit

Permalink
Remove test dependency on zope.pagetemplate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Sutherland committed May 12, 2011
1 parent 438ee38 commit 3ab0e05
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
4.0.2 (unreleased)
------------------

- Nothing changed yet.
- Remove test dependency on zope.pagetemplate.


4.0.1 (2011-05-04)
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
)

tests_require = ['zope.testing',
'zope.pagetemplate',
'WebTest'],
'WebTest']

setup(
name = 'zope.testbrowser',
Expand Down
52 changes: 17 additions & 35 deletions src/zope/testbrowser/ftests/controls.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,27 @@ <h1>Controls Tests</h1>

<div>
<label for="text-value">Text Control</label>
<em tal:condition="request/params/text-value|nothing"
tal:content="request/params/text-value"></em>
<input type="text" name="text-value" id="text-value"
value="Some Text" />
<em>%(text-value)s</em>
<input type="text" name="text-value" id="text-value" value="Some Text" />
</div>

<div>
<label for="password-value">Password Control</label>
<em tal:condition="request/params/password-value|nothing"
tal:content="request/params/password-value"></em>
<em>%(password-value)s</em>
<input type="password" name="password-value" id="password-value"
value="Password" />
</div>

<div>
<label for="hidden-value">Hidden Control</label> (label: hee hee)
<em tal:condition="request/params/hidden-value|nothing"
tal:content="request/params/hidden-value"></em>
<em>%(hidden-value)s</em>
<input type="hidden" name="hidden-value" id="hidden-value"
value="Hidden" />
</div>

<div>
<label for="textarea-value">Text Area Control</label>
<em tal:condition="request/params/textarea-value|nothing"
tal:content="request/params/textarea-value"></em>
<em>%(textarea-value)s</em>
<textarea name="textarea-value" id="textarea-value">
Text inside
area!
Expand All @@ -41,15 +36,13 @@ <h1>Controls Tests</h1>

<div>
<label for="file-value">File Control</label>
<em tal:condition="request/params/file-value|nothing"
tal:content="request/params/file-value"></em>
<em>%(file-value)s</em>
<input type="file" name="file-value" id="file-value" />
</div>

<div>
<label for="single-select-value">Single Select Control</label>
<em tal:condition="request/params/single-select-value|nothing"
tal:content="request/params/single-select-value"></em>
<em>%(single-select-value)s</em>
<select name="single-select-value" id="single-select-value">
<option value="1">Uno</option>
<option value="2">Dos</option>
Expand All @@ -59,8 +52,7 @@ <h1>Controls Tests</h1>

<div>
<label for="multi-select-value">Multiple Select Control</label>
<em tal:condition="request/params/multi-select-value|nothing"
tal:content="request/params/multi-select-value"></em>
<em>%(multi-select-value)s</em>
<select name="multi-select-value" id="multi-select-value"
multiple="multiple">
<option value="1">Un</option>
Expand All @@ -70,17 +62,14 @@ <h1>Controls Tests</h1>
</div>

<div>
<em tal:condition="request/params/single-unvalued-checkbox-value|nothing"
tal:content="request/params/single-unvalued-checkbox-value"></em>
<em>%(single-unvalued-checkbox-value)s</em>
<input type="checkbox" name="single-unvalued-checkbox-value"
id="single-unvalued-checkbox" checked="checked" />
<label for="single-unvalued-checkbox">Single Unvalued Checkbox</label>
</div>

<div>
<em tal:condition="
request/params/single-disabled-unvalued-checkbox-value|nothing"
tal:content="request/params/single-disabled-unvalued-checkbox-value"></em>
<em>%(single-disabled-unvalued-checkbox-value)s</em>
<input type="checkbox" name="single-disabled-unvalued-checkbox-value"
id="single-disabled-unvalued-checkbox" checked="checked"
disabled="disabled" />
Expand All @@ -90,17 +79,15 @@ <h1>Controls Tests</h1>
</div>

<div>
<em tal:condition="request/params/single-valued-checkbox-value|nothing"
tal:content="request/params/single-valued-checkbox-value"></em>
<em>%(single-valued-checkbox-value)s</em>
<label><input type="checkbox" name="single-valued-checkbox-value"
value="1" checked="checked" />Single Valued Checkbox
</label>
</div>

<div>
(Multi checkbox: options have the labels)
<em tal:condition="request/params/multi-checkbox-value|nothing"
tal:content="request/params/multi-checkbox-value"></em>
<em>%(multi-checkbox-value)s</em>
<label><input type="checkbox" name="multi-checkbox-value" value="1"
checked="checked" /> One</label>
<input type="checkbox" name="multi-checkbox-value" value="2"
Expand All @@ -114,8 +101,7 @@ <h1>Controls Tests</h1>

<div>
(Radio: options have the labels)
<em tal:condition="request/params/radio-value|nothing"
tal:content="request/params/radio-value"></em>
<em>%(radio-value)s</em>
<label><input type="radio" name="radio-value" value="1" />Ein</label>
<input type="radio" name="radio-value" id="radio-value-2" value="2"
checked="checked" />
Expand All @@ -127,20 +113,16 @@ <h1>Controls Tests</h1>

<div>
<label for="image-value">Image Control</label>
<em tal:condition="request/params/image-value.x|nothing"
tal:content="request/params/image-value.x"></em>
<em tal:condition="request/params/image-value.y|nothing"
tal:content="request/params/image-value.y"></em>
<em>%(image-value.x)s</em>
<em>%(image-value.y)s</em>
<input type="image" name="image-value" id="image-value"
src="zope3logo.gif" />
</div>

<div>
<label for="submit-value">Standard Submit Control</label>
<em tal:condition="request/params/submit-value|nothing"
tal:content="request/params/submit-value"></em>
<input type="submit" name="submit-value" id="submit-value"
value="Submit This" />
<em>%(submit-value)s</em>
<input type="submit" name="submit-value" id="submit-value" value="Submit This" />
</div>

<div>
Expand Down
7 changes: 2 additions & 5 deletions src/zope/testbrowser/ftests/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

<h1>Forms Tests</h1>

<em tal:condition="request/params/text-value|nothing"
tal:content="request/params/text-value" />
<em>%(text-value)s</em>

<form id="1" name="one" action="forms.html">
<input type="text" name="text-value" value="First Text" />
Expand All @@ -28,9 +27,7 @@ <h1>Forms Tests</h1>
<label for="text-value-4">Text Control</label>
<input type="text" name="text-value" id="text-value-4"
value="Fourth Text" />
<em tal:condition="python: 'hidden-4' in request.params and
'submit-4' not in request.params"
>Submitted without the submit button.</em>
<em>%(no-submit-button)s</em>
<input type="submit" name="submit-4" value="Don't Submit Me" />
<input type="hidden" name="hidden-4" value="marker" />
</form>
Expand Down
4 changes: 1 addition & 3 deletions src/zope/testbrowser/ftests/navigate.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

<h1>Navigation Tests</h1>

<p tal:condition="request/params/message|nothing">
Message: <em tal:content="request/params/message">Message</em>
</p>
<p>Message: <em>%(message)s</em></p>

<a href="navigate.html?message=By+Link+Text">Link Text</a>

Expand Down
38 changes: 25 additions & 13 deletions src/zope/testbrowser/ftests/wsgitestapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,25 @@
"""A minimal WSGI application used as a test fixture."""

import os
import cgi
import mimetypes
from datetime import datetime

from webob import Request, Response
from zope.pagetemplate.pagetemplatefile import PageTemplateFile

class NotFound(Exception):
pass

_HERE = os.path.dirname(__file__)

class MyPageTemplateFile(PageTemplateFile):

def pt_getContext(self, args, *extra_args, **kw):
namespace = super(MyPageTemplateFile, self).pt_getContext(args, *extra_args, **kw)
namespace['request'] = args[0]
return namespace

class WSGITestApplication(object):

def __call__(self, environ, start_response):
req = Request(environ)
handler = {'/set_status.html': set_status,
'/echo.html': echo,
'/redirect.html': redirect,
'/@@/testbrowser/forms.html': forms,
'/echo_one.html': echo_one,
'/set_header.html': set_header,
'/set_cookie.html': set_cookie,
Expand Down Expand Up @@ -67,17 +61,35 @@ def __call__(self, environ, start_response):
def handle_notfound(req):
raise NotFound(req.path_info)

def handle_resource(req):
class ParamsWrapper(object):

def __init__(self, params):
self.params = params

def __getitem__(self, key):
if key in self.params:
return cgi.escape(self.params[key])
return ''

def handle_resource(req, extra=None):
filename = req.path_info.split('/')[-1]
type, _ = mimetypes.guess_type(filename)
path = os.path.join(_HERE, filename)
contents = open(path, 'r').read()
if type == 'text/html':
pt = MyPageTemplateFile(path)
contents = pt(req)
else:
contents = open(path, 'r').read()
params = {}
params.update(req.params)
if extra is not None:
params.update(extra)
contents = contents % ParamsWrapper(params)
return Response(contents, content_type=type)

def forms(req):
extra = {}
if 'hidden-4' in req.params and 'submit-4' not in req.params:
extra['no-submit-button'] = 'Submitted without the submit button.'
return handle_resource(req, extra)

def get_cookie(req):
cookies = ['%s: %s' % i for i in sorted(req.cookies.items())]
return Response('\n'.join(cookies))
Expand Down

0 comments on commit 3ab0e05

Please sign in to comment.