-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed tests from features we no longer want to support
- Loading branch information
Showing
26 changed files
with
865 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# this is a package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# this is a package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# this is a package |
14 changes: 14 additions & 0 deletions
14
src/grokcore/view/ftests/staticdir/simple_fixture/ellie.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.