Skip to content

Commit

Permalink
Using now infrae.testbrowser
Browse files Browse the repository at this point in the history
Removed tests from features we no longer want to support
  • Loading branch information
trollfot committed Mar 17, 2011
2 parents 06bcc95 + 65333df commit d23cc1a
Show file tree
Hide file tree
Showing 26 changed files with 865 additions and 91 deletions.
9 changes: 8 additions & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ parts =
test
versions = versions
extensions = mr.developer buildout.dumppickedversions
always-checkout = true
auto-checkout = cromlech.io
cromlech.bootstrap
cromlech.publication
cromlech.request

[sources]
cromlech.io = git gitosis@devel.dolmen-project.org:cromlech.io.git
cromlech.bootstrap = git gitosis@devel.dolmen-project.org:cromlech.bootstrap.git
cromlech.publication = git gitosis@devel.dolmen-project.org:cromlech.publication.git
cromlech.request = git gitosis@devel.dolmen-project.org:cromlech.request.git

[versions]
grokcore.view =
Expand All @@ -22,5 +29,5 @@ interpreter = python
[test]
recipe = zc.recipe.testrunner
eggs = grokcore.view
grokcore.view[test]
grokcore.view [test, security]
defaults = ['--tests-pattern', '^f?tests$', '-v', '--auto-color', '--auto-progress']
41 changes: 26 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,34 @@ def read(*rnames):
)

install_requires = [
'setuptools',
'WebOb',
'cromlech.io',
'grokcore.component >= 2.1',
'grokcore.security >= 1.5',
'martian >= 0.13',
'setuptools',
'zc.buildout',
'zope.component',
'zope.interface',
'zope.location',
'zope.pagetemplate',
'zope.publisher',
'zope.security',
'zope.schema',
'zope.traversing',
'cromlech.io',
]

tests_require = [
'WebOb',
'zope.container',
'zope.securitypolicy',
'zope.site',
'zope.browserpage',
'zope.publisher',
'infrae.testbrowser',
'cromlech.publication',
'cromlech.bootstrap',
'cromlech.request',
]

security_require = [
'zope.security',
'zope.securitypolicy',
'zope.principalregistry',
]

Expand All @@ -43,19 +52,21 @@ def read(*rnames):
description='Grok-like configuration for Zope browser pages',
long_description=long_description,
license='ZPL',
classifiers=['Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Framework :: Zope3',
],

classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
],
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['grokcore'],
include_package_data = True,
zip_safe=False,
install_requires=install_requires,
tests_require=tests_require,
extras_require={'test': tests_require},
extras_require={
'test': tests_require,
'security': security_require,
},
)
5 changes: 4 additions & 1 deletion src/grokcore/view/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class Response(webob.Response):
interface.implements(IResponse)

charset = 'utf8'
charset = 'utf-8'

@apply
def body():
Expand Down Expand Up @@ -61,6 +61,9 @@ def redirect(self, url, status=302, trusted=False):
self.location = url
self.status = status

def __str__(self):
return self.body


class ViewSupport(object):
"""Mixin class providing methods and properties generally
Expand Down
18 changes: 7 additions & 11 deletions src/grokcore/view/ftesting.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@
i18n_domain="grokcore.view"
package="grokcore.view">

<include package="zope.security" />
<include package="zope.securitypolicy" />

<include package="zope.component" file="meta.zcml" />
<include package="grokcore.view" file="meta.zcml" />

<include package="zope.security" />
<include package="zope.site" />
<include package="zope.container" />
<include package="zope.publisher" />
<include package="zope.traversing" />
<include package="zope.traversing.browser" />
<include package="cromlech.bootstrap" />
<include package="cromlech.publication" file="publish.zcml" />
<include package="cromlech.publication" file="traverse.zcml" />
<include package="cromlech.request" file="webob.zcml" />

<include package="grokcore.view" />
<grok:grok package="grokcore.view.ftests" />

<browser:defaultView
for="grokcore.component.interfaces.IContext"
name="index"
/>

</configure>
1 change: 1 addition & 0 deletions src/grokcore/view/ftests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this is a package
1 change: 1 addition & 0 deletions src/grokcore/view/ftests/staticdir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this is a package
48 changes: 48 additions & 0 deletions src/grokcore/view/ftests/staticdir/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
We use a special name 'static' in page templates to allow easy linking
to resources.
In the context of a grok application, you can use fanstatic (through zope.fanstatic)
instead of the dummy implementation in this test:
>>> from zope.app.wsgi.testlayer import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
>>> root = getRootFolder()
>>> from grokcore.view.ftests.staticdir.simple_fixture.ellie import Mammoth
>>> root[u'ellie'] = Mammoth()
>>> browser.open('http://localhost/ellie')
>>> print browser.contents
<html>
<body>
<a href="dummy:/file.txt">Some text in a file</a>
</body>
</html>
"""
import zope.interface
import zope.component

from zope.traversing.interfaces import ITraversable
from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.publisher.interfaces.browser import IBrowserRequest

class DummyResource(object):
""" Dummy resource implementation. """
zope.interface.implements(ITraversable, IAbsoluteURL)

def __init__(self, request, name=''):
self.request = request
self.name = name

def traverse(self, name, furtherPath):
name = '%s/%s' % (self.name, name)
return DummyResource(self.request, name=name)

def __str__(self):
return 'dummy:%s' % self.name

zope.component.provideAdapter(factory=DummyResource,
adapts=(IBrowserRequest,),
provides=zope.interface.Interface,
name='grokcore.view.ftests.staticdir.simple_fixture')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this is a package
14 changes: 14 additions & 0 deletions src/grokcore/view/ftests/staticdir/simple_fixture/ellie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import grokcore.view as grok

class Mammoth(grok.Context):
pass

class Index(grok.View):
pass

index = grok.PageTemplate("""\
<html>
<body>
<a tal:attributes="href static/file.txt">Some text in a file</a>
</body>
</html>""")
112 changes: 112 additions & 0 deletions src/grokcore/view/ftests/test_functional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-

import doctest
import grokcore.component
import grokcore.view
import os.path
import re
import types
import unittest
import webob.dec

from cromlech.bootstrap.testlayer import ZODBLayer
from persistent.interfaces import IPersistent
from pkg_resources import resource_listdir
from zope.component import getMultiAdapter
from zope.event import notify
from zope.lifecycleevent import ObjectCreatedEvent
from zope.publisher.interfaces import IRequest, IPublication
from zope.publisher.publish import publish
from zope.site.interfaces import IRootFolder
from zope.site.folder import rootFolder


ROOT = 'grok'

@grokcore.component.implementer(IRootFolder)
@grokcore.component.adapter(IPersistent, types.BooleanType)
def test_root(db_root, creation=False):
folder = db_root.get(ROOT, None)
if folder is None and creation is True:
folder = rootFolder()
notify(ObjectCreatedEvent(folder))
db_root[ROOT] = folder
return folder


class WSGIApplication(object):

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

@webob.dec.wsgify
def __call__(self, webob_req):

# We want an interaction here
# XXXX

# We get a valid zope request
request = IRequest(webob_req)

# Here, we keep the zope compatibility. It will go away
request.setPublication(getMultiAdapter(
(request, self.db), IPublication))

# publishing
response = publish(request)

# Return the WSGI server response
return response


class BrowserLayer(ZODBLayer):
"""This create a test layer with a test database and register a wsgi
application to use that test database.
A wsgi_intercept handler is installed as well, so you can use a
WSGI version of zope.testbrowser Browser instance to access the
application.
"""

def testSetUp(self):
ZODBLayer.testSetUp(self)
self.application = WSGIApplication(self.db)

def getApplication(self):
return self.application


FunctionalLayer = BrowserLayer(grokcore.view)


def suiteFromPackage(name):
files = resource_listdir(__name__, name)
suite = unittest.TestSuite()

for filename in files:
if not filename.endswith('.py'):
continue
if filename == '__init__.py':
continue

dottedname = 'grokcore.view.ftests.%s.%s' % (name, filename[:-3])
test = doctest.DocTestSuite(
dottedname,
extraglobs=dict(
getRootFolder=FunctionalLayer.getRootFolder,
getApplication=FunctionalLayer.getApplication),
optionflags=(doctest.ELLIPSIS+
doctest.NORMALIZE_WHITESPACE+
doctest.REPORT_NDIFF),
)
test.layer = FunctionalLayer

suite.addTest(test)
return suite


def test_suite():
suite = unittest.TestSuite()
for name in ['view', 'staticdir', 'url']:
suite.addTest(suiteFromPackage(name))
return suite
1 change: 1 addition & 0 deletions src/grokcore/view/ftests/url/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
50 changes: 50 additions & 0 deletions src/grokcore/view/ftests/url/redirect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Views have a redirect() method to easily create redirects:
>>> getRootFolder()['manfred'] = manfred = Mammoth()
Since the index view redirects to mammoth, we expect to see the URL
point to mammoth:
>>> from zope.app.wsgi.testlayer import Browser, http
>>> browser = Browser()
>>> browser.handleErrors = False
>>> browser.open('http://localhost/manfred')
>>> browser.url
'http://localhost/manfred/another'
>>> response = http('GET /manfred/trustedredirect HTTP/1.0')
>>> response.getStatus()
302
>>> response.getHeader('location')
'http://www.google.com/ncr'
>>> browser.open('http://localhost/manfred/redirectwithstatus')
Traceback (most recent call last):
...
HTTPError: HTTP Error 418: Unknown
>>> browser.url
'http://localhost/manfred/redirectwithstatus'
"""
import grokcore.view as grok

class Mammoth(grok.Context):
pass

class Index(grok.View):
def render(self):
self.redirect(self.url('another'))

class TrustedRedirect(grok.View):
def render(self):
self.redirect('http://www.google.com/ncr', trusted=True)

class RedirectWithStatus(grok.View):
def render(self):
self.redirect(self.url(), status=418)

class Another(grok.View):
def render(self):
return "Another view"
Loading

0 comments on commit d23cc1a

Please sign in to comment.