Skip to content

Commit

Permalink
Massage the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
thefunny42 committed Jan 12, 2016
1 parent c4d7372 commit 6082d65
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
7 changes: 7 additions & 0 deletions src/grokcore/view/ftesting.zcml
Expand Up @@ -65,4 +65,11 @@
<grantAll role="zope.Manager" />
<grant role="zope.Manager" principal="zope.mgr" />

<!-- Register a test fixture -->
<adapter
factory="grokcore.view.ftests.static.simple.DummyResource"
for="zope.publisher.interfaces.browser.IBrowserRequest"
provides="zope.interface.Interface"
name="grokcore.view.ftests.static.simple_fixture" />

</configure>
14 changes: 4 additions & 10 deletions src/grokcore/view/ftests/static/simple.py
@@ -1,9 +1,8 @@
"""
We use a special name 'static' in page templates to allow easy linking
"""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:
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()
Expand All @@ -25,7 +24,7 @@

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. """
Expand All @@ -41,8 +40,3 @@ def traverse(self, name, furtherPath):

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

zope.component.provideAdapter(factory=DummyResource,
adapts=(IBrowserRequest,),
provides=zope.interface.Interface,
name='grokcore.view.ftests.static.simple_fixture')
2 changes: 2 additions & 0 deletions src/grokcore/view/ftests/static/simple_fixture/ellie.py
@@ -1,8 +1,10 @@
import grokcore.view as grok


class Mammoth(grok.Context):
pass


class Index(grok.View):
pass

Expand Down
5 changes: 5 additions & 0 deletions src/grokcore/view/ftests/url/redirect.py
Expand Up @@ -30,21 +30,26 @@
"""
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"
19 changes: 15 additions & 4 deletions src/grokcore/view/ftests/url/url.py
Expand Up @@ -155,9 +155,10 @@
>>> print result
http://127.0.0.1/herd/manfred/index?key=%C3%A9&key=2
>>> import cgi
>>> print unicode(cgi.parse_qs(result.split('?')[1])['key'][0], 'utf-8')
é
>>> from cgi import parse_qs
>>> expected = unicode('é', 'UTF-8')
>>> unicode(parse_qs(result.split('?')[1])['key'][0], 'UTF-8') == expected
True
Zope magic!! Here we test casting parameters in the CGI query string:
Expand Down Expand Up @@ -213,40 +214,50 @@
import grokcore.view as grok
from zope.container.contained import Contained


class Mammoth(Contained):
pass


grok.context(Mammoth)


class Index(grok.View):
def render(self):
return self.url()


class Another(grok.View):
def render(self):
return self.url()


class YetAnother(grok.View):
pass


class Multiplier(grok.View):
def update(self, age=0):
self.age = age

def render(self):
return unicode(self.age * 2)


yetanother = grok.PageTemplate('<p tal:replace="view/url" />')


class URLTestingSkin(grok.IBrowserRequest):
grok.skin('urltesting')


class AnotherURLTestingSkin(grok.IBrowserRequest):
grok.skin('anotherurltesting')


class URLTestingViewOnASkin(grok.View):
grok.layer(URLTestingSkin)
grok.name('test')

def render(self):
return u"I'm on a url testing skin: %s" % self.url()
return u"I'm on a url testing skin: {}".format(self.url())
12 changes: 8 additions & 4 deletions src/grokcore/view/ftests/url/url_function.py
Expand Up @@ -68,10 +68,10 @@
>>> url(request, herd, '@@sample_view', data=dict(age=28))
'http://127.0.0.1/herd/@@sample_view?age=28'
>>> url(request, herd, data=dict(age=28))
'http://127.0.0.1/herd?age=28'
There is no problem putting one of the 'reserved' arguments inside the data
argument or explicitely supplying 'None':
Expand All @@ -92,10 +92,10 @@
>>> withquery = url(request, herd, 'sample_view', data=dict(a=1, b=2, c=3))
>>> withquery.find('a=1') > -1
True
>>> withquery.find('b=2') > -1
True
>>> withquery.find('c=3') > -1
True
Expand All @@ -109,15 +109,19 @@
from grokcore.view import url
from zope.container.contained import Contained


class Mammoth(Contained):
pass


grok.context(Mammoth)


class Index(grok.View):
def render(self):
return url(self.request, self)


class Another(grok.View):
def render(self):
return url(self.request, self)
2 changes: 1 addition & 1 deletion src/grokcore/view/meta/directoryresource.py
Expand Up @@ -15,7 +15,7 @@

import os

from zope import interface, component
from zope import interface
from zope.security.checker import NamesChecker
from zope.publisher.interfaces.browser import IDefaultBrowserLayer

Expand Down

0 comments on commit 6082d65

Please sign in to comment.