[Zope3-checkins] CVS: Zope3/src/zope/app/browser/tests - __init__.py:1.2 test_absoluteurl.py:1.2 test_menu.py:1.2 test_objectname.py:1.2 test_undo.py:1.2 test_zodbundomanager.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:45 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/browser/tests

Added Files:
	__init__.py test_absoluteurl.py test_menu.py 
	test_objectname.py test_undo.py test_zodbundomanager.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/browser/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:44 2002
+++ Zope3/src/zope/app/browser/tests/__init__.py	Wed Dec 25 09:12:44 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/browser/tests/test_absoluteurl.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:44 2002
+++ Zope3/src/zope/app/browser/tests/test_absoluteurl.py	Wed Dec 25 09:12:44 2002
@@ -0,0 +1,135 @@
+##############################################################################
+#
+# 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.0 (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 the AbsoluteURL view
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interface import Interface
+
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component import getService, getView
+
+from zope.interfaces.i18n import IUserPreferredCharsets
+
+from zope.publisher.tests.httprequest import TestRequest
+from zope.publisher.http import IHTTPRequest
+from zope.publisher.http import HTTPCharsets
+from zope.publisher.interfaces.browser import IBrowserPresentation
+from zope.proxy.context import ContextWrapper
+
+
+class IRoot(Interface): pass
+
+class Root:
+    __implements__ = IRoot
+
+class TrivialContent(object):
+    """Trivial content object, used because instances of object are rocks."""
+
+class Test(PlacelessSetup, TestCase):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        from zope.app.browser.absoluteurl \
+             import AbsoluteURL, SiteAbsoluteURL
+        provideView=getService(None,"Views").provideView
+        provideView(None, 'absolute_url', IBrowserPresentation,
+                    [AbsoluteURL])
+        provideView(IRoot, 'absolute_url', IBrowserPresentation,
+                    [SiteAbsoluteURL])
+        provideAdapter = getService(None, "Adapters").provideAdapter
+        provideAdapter(IHTTPRequest, IUserPreferredCharsets, HTTPCharsets)
+
+    def testBadObject(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+        view = getView(None, 'absolute_url', request)
+        self.assertRaises(TypeError, view.__str__)
+
+    def testNoContext(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+        view = getView(Root(), 'absolute_url', request)
+        self.assertEqual(str(view), 'http://foobar.com')
+
+    def testBasicContext(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+
+        content = ContextWrapper(TrivialContent(), Root(), name='a')
+        content = ContextWrapper(TrivialContent(), content, name='b')
+        content = ContextWrapper(TrivialContent(), content, name='c')
+        view = getView(content, 'absolute_url', request)
+        self.assertEqual(str(view), 'http://foobar.com/a/b/c')
+
+        breadcrumbs = view.breadcrumbs()
+        self.assertEqual(breadcrumbs,
+                         ({'name':  '', 'url': 'http://foobar.com'},
+                          {'name': 'a', 'url': 'http://foobar.com/a'},
+                          {'name': 'b', 'url': 'http://foobar.com/a/b'},
+                          {'name': 'c', 'url': 'http://foobar.com/a/b/c'},
+                          ))
+
+    def testContextWSideEffectsInMiddle(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+
+        content = ContextWrapper(TrivialContent(), Root(), name='a')
+        content = ContextWrapper(TrivialContent(), content,
+                                 name='.',
+                                 side_effect_name="++skin++ZopeTop")
+        content = ContextWrapper(TrivialContent(), content, name='b')
+        content = ContextWrapper(TrivialContent(), content, name='c')
+        view = getView(content, 'absolute_url', request)
+        self.assertEqual(str(view), 'http://foobar.com/a/++skin++ZopeTop/b/c')
+
+        breadcrumbs = view.breadcrumbs()
+        self.assertEqual(breadcrumbs,
+         ({'name':  '', 'url': 'http://foobar.com'},
+          {'name': 'a', 'url': 'http://foobar.com/a/++skin++ZopeTop'},
+          {'name': 'b', 'url': 'http://foobar.com/a/++skin++ZopeTop/b'},
+          {'name': 'c', 'url': 'http://foobar.com/a/++skin++ZopeTop/b/c'},
+          ))
+
+    def testContextWSideEffectsInFront(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+
+        root = Root()
+        content = ContextWrapper(root, root,
+                                 name='.',
+                                 side_effect_name="++skin++ZopeTop")
+        content = ContextWrapper(TrivialContent(), content, name='a')
+        content = ContextWrapper(TrivialContent(), content, name='b')
+        content = ContextWrapper(TrivialContent(), content, name='c')
+        view = getView(content, 'absolute_url', request)
+        self.assertEqual(str(view), 'http://foobar.com/++skin++ZopeTop/a/b/c')
+
+        breadcrumbs = view.breadcrumbs()
+        self.assertEqual(breadcrumbs,
+         ({'name':  '', 'url': 'http://foobar.com/++skin++ZopeTop'},
+          {'name': 'a', 'url': 'http://foobar.com/++skin++ZopeTop/a'},
+          {'name': 'b', 'url': 'http://foobar.com/++skin++ZopeTop/a/b'},
+          {'name': 'c', 'url': 'http://foobar.com/++skin++ZopeTop/a/b/c'},
+          ))
+
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/browser/tests/test_menu.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:44 2002
+++ Zope3/src/zope/app/browser/tests/test_menu.py	Wed Dec 25 09:12:44 2002
@@ -0,0 +1,111 @@
+##############################################################################
+#
+# 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.0 (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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+from zope.interface import Interface
+
+from zope.component import getService, getServiceManager
+from zope.app.services.tests.placefulsetup \
+           import PlacefulSetup
+
+from zope.app.browser.menu import MenuAccessView
+
+from zope.publisher.interfaces.browser import IBrowserView
+from zope.publisher.interfaces.browser import IBrowserPresentation
+from zope.app.publication.traversers import TestTraverser
+from zope.security.securitymanagement import newSecurityManager
+from zope.security.checker import defineChecker, NamesChecker, CheckerPublic
+from zope.security.proxy import ProxyFactory
+from zope.app.interfaces.publisher.browser import IBrowserMenuService
+
+def d(title, action):
+    return {'action': action, 'title': title, 'description': ''}
+
+class Service:
+    __implements__ = IBrowserMenuService
+
+    def getMenu(self, name, ob, req):
+        return [d('l1', 'a1'),
+                d('l2', 'a2/a3'),
+                d('l3', '@@a3'),]
+
+class I(Interface): pass
+class C:
+    __implements__ = I
+
+    def __call__(self):
+        pass
+
+ob = C()
+ob.a1 = C()
+ob.a2 = C()
+ob.a2.a3 = C()
+ob.abad = C()
+ob.abad.bad = 1
+
+class V:
+    __implements__ = IBrowserView
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def __call__(self):
+        pass
+
+
+class Test(PlacefulSetup, unittest.TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        defineService = getServiceManager(None).defineService
+        provideService = getServiceManager(None).provideService
+
+
+        defineService('BrowserMenu', IBrowserMenuService)
+        provideService('BrowserMenu', Service())
+        getService(None,"Views").provideView(
+            I, 'a3', IBrowserPresentation, [V])
+        getService(None, "Views").provideView(None, '_traverse',
+                            IBrowserPresentation, [TestTraverser])
+        defineChecker(C, NamesChecker(['a1', 'a2', 'a3', '__call__'],
+                                      CheckerPublic,
+                                      abad='waaa'))
+
+    def test(self):
+        newSecurityManager('who')
+        v = MenuAccessView(ProxyFactory(ob), Request())
+        self.assertEqual(v['zmi_views'],
+                         [{'description': '', 'title':'l1', 'action':'a1'},
+                          {'description': '', 'title':'l2', 'action':'a2/a3'},
+                          {'description': '', 'title':'l3', 'action':'@@a3'}
+                          ])
+
+
+class Request:
+    def getPresentationType(self):
+        return IBrowserPresentation
+    def getPresentationSkin(self):
+        return ''
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/app/browser/tests/test_objectname.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:44 2002
+++ Zope3/src/zope/app/browser/tests/test_objectname.py	Wed Dec 25 09:12:44 2002
@@ -0,0 +1,84 @@
+##############################################################################
+#
+# 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.0 (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 the AbsoluteURL view
+
+Revision information:
+$Id$
+"""
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.interface import Interface
+
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component import getService, getView, getAdapter
+
+from zope.interfaces.i18n import IUserPreferredCharsets
+
+from zope.publisher.interfaces.browser import IBrowserPresentation
+from zope.publisher.tests.httprequest import TestRequest
+from zope.publisher.http import IHTTPRequest
+from zope.publisher.http import HTTPCharsets
+
+from zope.proxy.context import ContextWrapper
+
+from zope.app.browser.objectname \
+    import ObjectNameView, SiteObjectNameView
+
+class IRoot(Interface): pass
+
+class Root:
+    __implements__ = IRoot
+
+class TrivialContent(object):
+    """Trivial content object, used because instances of object are rocks."""
+
+class Test(PlacelessSetup, TestCase):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        provideView = getService(None, "Views").provideView
+        provideView(None, 'object_name', IBrowserPresentation,
+                    [ObjectNameView])
+        provideView(IRoot, 'object_name', IBrowserPresentation,
+                    [SiteObjectNameView])
+
+        provideAdapter = getService(None, "Adapters").provideAdapter
+        provideAdapter(IHTTPRequest, IUserPreferredCharsets, HTTPCharsets)
+
+    def testViewBadObject(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+        view = getView(None, 'object_name', request)
+        self.assertRaises(TypeError, view.__str__)
+
+    def testViewNoContext(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+        view = getView(Root(), 'object_name', request)
+        self.assertRaises(TypeError, str(view))
+
+    def testViewBasicContext(self):
+        request = TestRequest()
+        request.setViewType(IBrowserPresentation)
+
+        content = ContextWrapper(TrivialContent(), Root(), name='a')
+        content = ContextWrapper(TrivialContent(), content, name='b')
+        content = ContextWrapper(TrivialContent(), content, name='c')
+        view = getView(content, 'object_name', request)
+        self.assertEqual(str(view), 'c')
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/browser/tests/test_undo.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:44 2002
+++ Zope3/src/zope/app/browser/tests/test_undo.py	Wed Dec 25 09:12:44 2002
@@ -0,0 +1,93 @@
+##############################################################################
+#
+# 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.0 (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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from zope.app.interfaces.undo import IUndoManager
+from zope.app.browser.undo import Undo
+from zope.app.services.tests.placefulsetup\
+           import PlacefulSetup
+
+class TestIUndoManager:
+    __implements__ = IUndoManager
+
+    def __init__(self):
+        dict1 = {'id': '1', 'user_name': 'monkey', 'description': 'thing1',
+ 'time': 'today'}
+        dict2 = {'id': '2', 'user_name': 'monkey', 'description': 'thing2',
+ 'time': 'today'}
+        dict3 = {'id': '3', 'user_name': 'monkey', 'description': 'thing3',
+ 'time': 'today'}
+
+        self.dummy_db = [dict1, dict2, dict3]
+
+    def getUndoInfo(self):
+        return self.dummy_db
+
+    def undoTransaction(self, id_list):
+        # just remove an element for now
+        temp_dict = {}
+        for db_record in self.dummy_db:
+            if db_record['id'] not in id_list:
+                temp_dict[db_record['id']] =  db_record
+
+        self.dummy_db = []
+        for key in temp_dict.keys():
+            self.dummy_db.append(temp_dict[key])
+
+
+class Test(PlacefulSetup, TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        from zope.component import getService
+        getService(None,'Utilities').provideUtility(IUndoManager,
+              TestIUndoManager())
+
+    def testGetUndoInfo(self):
+        view = Undo(None, None)
+
+        self.assertEqual(view.getUndoInfo(), TestIUndoManager().getUndoInfo())
+
+
+    def testUndoSingleTransaction(self):
+        view = Undo(None, None)
+        id_list = ['1']
+        view.action(id_list)
+
+        testum = TestIUndoManager()
+        testum.undoTransaction(id_list)
+
+        self.assertEqual(view.getUndoInfo(), testum.getUndoInfo())
+
+    def testUndoManyTransactions(self):
+        view = Undo(None, None)
+        id_list = ['1','2','3']
+        view.action(id_list)
+
+        testum = TestIUndoManager()
+        testum.undoTransaction(id_list)
+
+        self.assertEqual(view.getUndoInfo(), testum.getUndoInfo())
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/browser/tests/test_zodbundomanager.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:45 2002
+++ Zope3/src/zope/app/browser/tests/test_zodbundomanager.py	Wed Dec 25 09:12:44 2002
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# 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.0 (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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+from time import time
+
+def dict(**kw): return kw
+
+testdata = [
+    dict(id='1', user_name='jim', time=time(), description='des 1'),
+    dict(id='2', user_name='jim', time=time(), description='des 2'),
+    dict(id='3', user_name='jim', time=time(), description='des 3'),
+    dict(id='4', user_name='jim', time=time(), description='des 4'),
+    dict(id='5', user_name='jim', time=time(), description='des 5'),
+    dict(id='6', user_name='jim', time=time(), description='des 6'),
+    dict(id='7', user_name='jim', time=time(), description='des 7'),
+    ]
+testdata.reverse()
+
+class StubDB:
+
+    def __init__(self):
+        self.data = list(testdata)
+
+    def undoInfo(self):
+        return tuple(self.data)
+
+    def undo(self, id):
+        self.data = [d for d in self.data if d['id'] != id]
+
+class Test(CleanUp, TestCase):
+
+    def test(self):
+        from zope.app.browser.undo import ZODBUndoManager
+        um = ZODBUndoManager(StubDB())
+
+        self.assertEqual(list(um.getUndoInfo()), testdata)
+
+        um.undoTransaction(('3','4','5'))
+        expected = testdata
+        expected = [d for d in expected if (d['id'] not in ('3','4','5'))]
+
+        self.assertEqual(list(um.getUndoInfo()), expected)
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')