Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in changes from trunk. These are necessary, since they remove all
services other than the utility, adapter and service service, which will be removed by the work of this branch.
- Loading branch information
0 parents
commit 58de0f8
Showing
1 changed file
with
99 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,99 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2004 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. | ||
# | ||
############################################################################## | ||
"""Session tests | ||
$Id$ | ||
""" | ||
import unittest, doctest, os, os.path, sys | ||
from zope.app import zapi | ||
from zope.app.testing import ztapi, placelesssetup | ||
|
||
from zope.app.session.interfaces import IClientId, IClientIdManager, ISession | ||
from zope.app.session.interfaces import ISessionDataContainer | ||
from zope.app.session.interfaces import ISessionPkgData, ISessionData | ||
|
||
from zope.app.session.session import ClientId, Session | ||
from zope.app.session.session import PersistentSessionDataContainer | ||
from zope.app.session.session import RAMSessionDataContainer | ||
|
||
from zope.app.session.http import CookieClientIdManager | ||
|
||
from zope.publisher.interfaces import IRequest | ||
from zope.publisher.http import HTTPRequest | ||
|
||
from zope.pagetemplate.pagetemplate import PageTemplate | ||
|
||
from zope.app.appsetup.tests import TestBootstrapSubscriber, EventStub | ||
from zope.app.appsetup.bootstrap import bootStrapSubscriber | ||
from zope.app.session.bootstrap import bootStrapSubscriber as \ | ||
sessionBootstrapSubscriber | ||
|
||
def setUp(session_data_container_class=PersistentSessionDataContainer): | ||
placelesssetup.setUp() | ||
ztapi.provideAdapter(IRequest, IClientId, ClientId) | ||
ztapi.provideAdapter(IRequest, ISession, Session) | ||
ztapi.provideUtility(IClientIdManager, CookieClientIdManager()) | ||
sdc = session_data_container_class() | ||
for product_id in ('', 'products.foo', 'products.bar', 'products.baz'): | ||
ztapi.provideUtility(ISessionDataContainer, sdc, product_id) | ||
request = HTTPRequest(None, None, {}, None) | ||
return request | ||
|
||
def tearDown(): | ||
placelesssetup.tearDown() | ||
|
||
class TestBootstrap(TestBootstrapSubscriber): | ||
|
||
def test_bootstrapSusbcriber(self): | ||
bootStrapSubscriber(EventStub(self.db)) | ||
|
||
sessionBootstrapSubscriber(EventStub(self.db)) | ||
|
||
from zope.app.publication.zopepublication import ZopePublication | ||
from zope.app.component.hooks import setSite | ||
from zope.app import zapi | ||
|
||
cx = self.db.open() | ||
root = cx.root() | ||
root_folder = root[ZopePublication.root_name] | ||
setSite(root_folder) | ||
|
||
zapi.getUtility(IClientIdManager) | ||
zapi.getUtility(ISessionDataContainer) | ||
|
||
|
||
cx.close() | ||
|
||
# Test the code in our API documentation is correct | ||
def test_documentation(): | ||
pass | ||
test_documentation.__doc__ = ''' | ||
>>> request = setUp(RAMSessionDataContainer) | ||
%s | ||
>>> tearDown() | ||
''' % (open(os.path.join(os.path.dirname(__file__), 'api.txt')).read(),) | ||
|
||
def test_suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(TestBootstrap)) | ||
suite.addTest(doctest.DocTestSuite()) | ||
suite.addTest(doctest.DocTestSuite('zope.app.session.session')) | ||
suite.addTest(doctest.DocTestSuite('zope.app.session.http')) | ||
return suite | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |