Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r26524 | srichter | 2004-07-14 03:45:38 -0400 (Wed, 14 Jul 2004) | 6 lines r26551 | srichter | 2004-07-15 03:06:37 -0400 (Thu, 15 Jul 2004) | 6 lines r26522 | pruggera | 2004-07-14 01:42:06 -0400 (Wed, 14 Jul 2004) | 1 line r26531 | pruggera | 2004-07-14 13:00:15 -0400 (Wed, 14 Jul 2004) | 1 line r26534 | pruggera | 2004-07-14 15:55:34 -0400 (Wed, 14 Jul 2004) | 1 line r26540 | pruggera | 2004-07-14 18:14:25 -0400 (Wed, 14 Jul 2004) | 1 line
- Loading branch information
Showing
5 changed files
with
216 additions
and
36 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,57 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 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. | ||
# | ||
############################################################################## | ||
"""HTTP Factory | ||
$Id$ | ||
""" | ||
from zope.interface import implements | ||
from zope.publisher.http import HTTPRequest | ||
from zope.publisher.browser import BrowserRequest | ||
from zope.publisher.xmlrpc import XMLRPCRequest | ||
|
||
from zope.app.publication.interfaces import IPublicationRequestFactory | ||
|
||
from zope.app.publication.http import HTTPPublication | ||
from zope.app.publication.browser import BrowserPublication | ||
from zope.app.publication.xmlrpc import XMLRPCPublication | ||
|
||
_browser_methods = 'GET', 'POST', 'HEAD' | ||
|
||
class HTTPPublicationRequestFactory(object): | ||
implements(IPublicationRequestFactory) | ||
|
||
def __init__(self, db): | ||
"""See zope.app.publication.interfaces.IPublicationRequestFactory""" | ||
self._http = HTTPPublication(db) | ||
self._brower = BrowserPublication(db) | ||
self._xmlrpc = XMLRPCPublication(db) | ||
|
||
def __call__(self, input_stream, output_steam, env): | ||
"""See zope.app.publication.interfaces.IPublicationRequestFactory""" | ||
method = env.get('REQUEST_METHOD', 'GET').upper() | ||
|
||
if method in _browser_methods: | ||
if (method == 'POST' and | ||
env.get('CONTENT_TYPE', '').startswith('text/xml') | ||
): | ||
request = XMLRPCRequest(input_stream, output_steam, env) | ||
request.setPublication(self._xmlrpc) | ||
else: | ||
request = BrowserRequest(input_stream, output_steam, env) | ||
request.setPublication(self._brower) | ||
else: | ||
request = HTTPRequest(input_stream, output_steam, env) | ||
request.setPublication(self._http) | ||
|
||
return request |
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,63 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2003 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 HTTP Publication | ||
$Id$ | ||
""" | ||
from unittest import TestCase, TestSuite, main, makeSuite | ||
from zope.app import zapi | ||
import zope.app.publication.http | ||
from zope.publisher.http import HTTPRequest | ||
from zope.app.tests.placelesssetup import PlacelessSetup | ||
from StringIO import StringIO | ||
from zope.interface import Interface, implements | ||
from zope.publisher.interfaces.http import IHTTPRequest | ||
|
||
class I(Interface): pass | ||
class C(object): | ||
spammed = 0 | ||
implements(I) | ||
|
||
class V(object): | ||
|
||
def __init__(self, context, request): | ||
self.context = context | ||
|
||
def SPAM(self): | ||
self.context.spammed += 1 | ||
|
||
|
||
class Test(PlacelessSetup, TestCase): | ||
# Note that zope publication tests cover all of the code but callObject | ||
|
||
def test_callObject(self): | ||
pub = zope.app.publication.http.HTTPPublication(None) | ||
request = HTTPRequest(StringIO(''), StringIO(), {}) | ||
request.method = 'SPAM' | ||
|
||
s = zapi.getGlobalService(zapi.servicenames.Presentation) | ||
s.provideView(I, 'SPAM', IHTTPRequest, V) | ||
|
||
ob = C() | ||
pub.callObject(request, ob) | ||
self.assertEqual(ob.spammed, 1) | ||
|
||
|
||
def test_suite(): | ||
return TestSuite(( | ||
makeSuite(Test), | ||
)) | ||
|
||
if __name__=='__main__': | ||
main(defaultTest='test_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,83 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 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 Component Traverser Test | ||
$Id$ | ||
""" | ||
import unittest | ||
from zope.component.tests.request import Request | ||
from zope.app.publication.traversers import SimpleComponentTraverser | ||
from zope.component import getService | ||
from zope.app.servicenames import Presentation | ||
from zope.interface import Interface | ||
from zope.exceptions import NotFoundError | ||
from zope.app.tests.placelesssetup import PlacelessSetup | ||
|
||
class I(Interface): | ||
pass | ||
|
||
|
||
class Container(object): | ||
def __init__(self, **kw): | ||
for k in kw: | ||
setattr(self, k , kw[k]) | ||
|
||
def get(self, name, default=None): | ||
return getattr(self, name, default) | ||
|
||
|
||
class Request(Request): | ||
def getEffectiveURL(self): | ||
return '' | ||
|
||
|
||
class View(object): | ||
def __init__(self, comp, request): | ||
self._comp = comp | ||
|
||
|
||
class Test(PlacelessSetup, unittest.TestCase): | ||
def testAttr(self): | ||
# test container traver | ||
foo = Container() | ||
c = Container(foo=foo) | ||
req = Request(I, '') | ||
|
||
T = SimpleComponentTraverser(c, req) | ||
|
||
self.assertRaises(NotFoundError , T.publishTraverse, req ,'foo') | ||
|
||
|
||
def testView(self): | ||
# test getting a view | ||
foo = Container() | ||
c = Container(foo=foo) | ||
req = Request(I, '') | ||
|
||
T = SimpleComponentTraverser(c, req) | ||
getService(Presentation).provideView(None , 'foo', I, View) | ||
|
||
self.failUnless(T.publishTraverse(req,'foo').__class__ is View ) | ||
|
||
self.assertRaises(NotFoundError , T.publishTraverse, req ,'morebar') | ||
|
||
|
||
|
||
def test_suite(): | ||
loader = unittest.TestLoader() | ||
return loader.loadTestsFromTestCase(Test) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.TextTestRunner().run(test_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