-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demonstrate a view and template loaded directly from a ZIP archive,
and make it actually work
- Loading branch information
Showing
8 changed files
with
592 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2005 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Test harness for loading pages from packages contained in ZIP archives. | ||
""" | ||
__docformat__ = "reStructuredText" | ||
|
||
import os | ||
import sys | ||
|
||
from zope.app.testing import functional | ||
|
||
|
||
#### test setup #### | ||
|
||
class Layer(functional.ZCMLLayer): | ||
|
||
# This layer still can't be completely torn down due to the base | ||
# class, but tries to avoid doing more damage than it has to. | ||
|
||
def setUp(self): | ||
self.__sys_path = sys.path[:] | ||
here = os.path.dirname(__file__) | ||
zipfile = os.path.join(here, "testfiles", "zippedview.zip") | ||
sys.path.append(zipfile) | ||
functional.ZCMLLayer.setUp(self) | ||
|
||
def tearDown(self): | ||
sys.path[:] = self.__sys_path | ||
functional.ZCMLLayer.tearDown(self) | ||
|
||
|
||
ZippedViewLayer = Layer( | ||
os.path.join(os.path.dirname(__file__), "testfiles/zippedview.zcml"), | ||
__name__, "ZippedViewLayer") | ||
|
||
def test_suite(): | ||
suite = functional.FunctionalDocFileSuite("zipped.txt") | ||
suite.layer = ZippedViewLayer | ||
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,22 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
package="zope.app.publisher.browser.tests" | ||
> | ||
|
||
<!-- This is a functional testing layer that adds the `sampleview` | ||
package from a ZIP file to test that browser view defined by | ||
products in zipped packages (such as eggs). | ||
--> | ||
|
||
<include package="zope.app"/> | ||
<include package="sampleview"/> | ||
|
||
<unauthenticatedPrincipal | ||
id="zope.anybody" | ||
title="Unauthenticated User" /> | ||
|
||
<securityPolicy | ||
component="zope.security.simplepolicies.PermissiveSecurityPolicy" | ||
/> | ||
|
||
</configure> |
Binary file not shown.
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,24 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2005 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Sample view code. | ||
This is used to test views extracted from ZIP files. | ||
""" | ||
|
||
|
||
class MyView(object): | ||
|
||
def sometext(self): | ||
return u"(This is some text.)" |
15 changes: 15 additions & 0 deletions
15
browser/tests/testfiles/zipsource/sampleview/configure.zcml
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:browser="http://namespaces.zope.org/browser" | ||
> | ||
|
||
<browser:page | ||
name="sometext.html" | ||
permission="zope.Public" | ||
for="zope.interface.Interface" | ||
template="myview.pt" | ||
class=".MyView" | ||
/> | ||
|
||
</configure> |
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 @@ | ||
<div tal:content="view/sometext"/> |
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,25 @@ | ||
================================== | ||
Publishing views from ZIP archives | ||
================================== | ||
|
||
Python packages can be imported from ZIP files. Zope supports using | ||
such packages as extension providers: ZCML can be loaded from them and | ||
they can provide views based on templates or other data contained | ||
inside the archive. | ||
|
||
This document demonstrates this facility. The Python harness for this | ||
test (test_zipped.py) has added a ZIP file containing a sample package | ||
to sys.path, and loaded ZCML that loads a view from that package. | ||
|
||
Since the ZCML has already been loaded, we can check that our view is | ||
available:: | ||
|
||
>>> print http(""" | ||
... GET /@@sometext.html HTTP/1.1 | ||
... """) | ||
HTTP/1.1 200 ... | ||
<div>(This is some text.)</div> | ||
|
||
This is the text provided by the view class in in the `sampleview` | ||
package's __init__.py, wrapped in the <div> element from the myview.pt | ||
template also contained in that package. |
Oops, something went wrong.