[Zope-CVS] CVS: Packages/pypes/pypes/tests - common.py:1.6 runtests.py:1.5 test_extent.py:1.12 test_services.py:1.8

Casey Duncan casey at zope.com
Sun Mar 7 05:09:14 EST 2004


Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv26459/pypes/tests

Modified Files:
	common.py runtests.py test_extent.py test_services.py 
Log Message:
* Create util module and tests for shared functions, refactor other modules to use new functions
* Add attach() function to services to replace connection.add() for cases where we want service access without adding to the database.
* Add accesspointFrom() function to abstract service access better, refactor other code to use it


=== Packages/pypes/pypes/tests/common.py 1.5 => 1.6 ===
--- Packages/pypes/pypes/tests/common.py:1.5	Sun Feb 29 00:44:48 2004
+++ Packages/pypes/pypes/tests/common.py	Sun Mar  7 05:09:13 2004
@@ -17,13 +17,14 @@
 
 import os
 import ZODB
+from ZODB.Connection import Connection
 from persistent import Persistent
 from unittest import TestCase
 
 class TestClass(Persistent):
     pass
     
-class TestConnection:
+class TestConnection(Connection):
     """Dummy ZODB connection for testing"""
     
     def __init__(self):
@@ -43,6 +44,9 @@
     
     def add(self, obj):
         obj._p_jar = self
+    
+    def __repr__(self):
+        return '<%s at 0x%x>' % (self.__class__.__name__, id(self))
         
 class PypesTestCase(TestCase):
     """TestCase with a test zodb connection and standard pypes services 
@@ -54,9 +58,6 @@
         self.conn = TestConnection()
         self.root = self.conn.root()
         pypes.initialize(self.conn)
-        # Simulate that the services are committed to the database
-        for service in pypes.services.all(self.conn).values():
-            self.conn.add(service)
         self.identity = pypes.services.identity(self.conn)
         
     def _newObj(self):


=== Packages/pypes/pypes/tests/runtests.py 1.4 => 1.5 ===
--- Packages/pypes/pypes/tests/runtests.py:1.4	Mon Feb  9 00:24:51 2004
+++ Packages/pypes/pypes/tests/runtests.py	Sun Mar  7 05:09:13 2004
@@ -11,6 +11,7 @@
 from test_graph import *
 from test_expression import *
 from test_extent import *
+from test_util import *
 
 if __name__ == '__main__':
     unittest.main()


=== Packages/pypes/pypes/tests/test_extent.py 1.11 => 1.12 ===
--- Packages/pypes/pypes/tests/test_extent.py:1.11	Sun Feb 29 00:44:48 2004
+++ Packages/pypes/pypes/tests/test_extent.py	Sun Mar  7 05:09:13 2004
@@ -153,7 +153,7 @@
         from pypes.extent import ExtentService
         self.assertRaises(AssertionError, ExtentService)
 
-class DummyEventService:
+class DummyEventService(Persistent):
     """Test Event Service Scaffold"""
     
     def __init__(self):
@@ -173,7 +173,7 @@
     def hasReg(self, obj, method_name, message_type):
         return (obj, method_name, message_type) in self._listeners
 
-class DummyIdentityService:
+class DummyIdentityService(Persistent):
     
     def __init__(self, conn):
         self._nextid = 1


=== Packages/pypes/pypes/tests/test_services.py 1.7 => 1.8 ===
--- Packages/pypes/pypes/tests/test_services.py:1.7	Sun Feb 29 00:44:49 2004
+++ Packages/pypes/pypes/tests/test_services.py	Sun Mar  7 05:09:13 2004
@@ -15,13 +15,15 @@
 
 import unittest
 import ZODB
-from common import TestConnection, PypesTestCase, PersistenceTest
+from common import TestConnection, PypesTestCase, PersistenceTest, TestClass
 from zope.interface.verify import verifyObject
 from persistent import Persistent
 
 class TestService(Persistent):
     pass
-
+    
+class NotPersistent:
+    pass
 
 class TestInitServices(unittest.TestCase):
     
@@ -145,6 +147,28 @@
         from pypes.serviceconfig import registry_name
         PypesTestCase.setUp(self)
         self.identity = self.root[registry_name]['identity']
+    
+    def testAccesspointFromConnection(self):
+        from pypes.services import accesspointFrom
+        self.failUnless(accesspointFrom(self.conn) is self.conn)
+    
+    def testAccesspointFromObjectInDB(self):
+        from pypes.services import accesspointFrom
+        ob = TestClass()
+        self.conn.add(ob)
+        self.failUnless(accesspointFrom(ob) is self.conn)
+    
+    def testAccesspointFromAttached(self):
+        from pypes.services import accesspointFrom, attach
+        ob = TestClass()
+        attach(ob, self.conn)
+        self.failUnless(accesspointFrom(ob) is self.conn)
+    
+    def testAccessPointFromBogus(self):
+        from pypes.services import accesspointFrom
+        from pypes.exceptions import PypesLookupError
+        self.assertEqual(accesspointFrom('whatever'), None)
+        self.assertEqual(accesspointFrom(TestClass()), None)
         
     def testGetFromConnection(self):
         from pypes import services
@@ -170,6 +194,43 @@
         ob = Persistent()
         self.conn.add(ob)
         self.failUnless(services.all(ob)['identity'] is self.identity)
+    
+    def testAttachServices(self):
+        from pypes import services
+        ob = TestClass()
+        services.attach(ob, self.conn)
+        self.failUnless(services.all(ob)['identity'] is self.identity)
+        self.failUnless(services.get(ob, 'identity') is self.identity)
+        return ob
+    
+    def testAttachServicesNonPersistent(self):
+        from pypes import services
+        ob = NotPersistent()
+        self.assertRaises(TypeError, services.attach, ob, self.conn)
+    
+    def testAttachServicesAlreadyAttached(self):
+        # Make sure attaching an object to services twice does no harm
+        from pypes import services
+        ob = self.testAttachServices()
+        services.attach(ob, self.conn)
+        self.failUnless(services.all(ob)['identity'] is self.identity)
+    
+    def testAttachServicesAlreadyAttached(self):
+        # Make sure attaching an added object to services does no harm
+        from pypes import services
+        ob = TestClass()
+        self.conn.add(ob)
+        services.attach(ob, self.conn)
+        self.failUnless(services.all(ob)['identity'] is self.identity)
+    
+    def testCantAttachToDifferentDB(self):
+        # Make sure we can't attach an object to a different database
+        from pypes import services
+        from pypes.exceptions import PypesError
+        ob = TestClass()
+        self.conn.add(ob)
+        otherdb = TestConnection()
+        self.assertRaises(PypesError, services.attach, ob, otherdb)        
     
     def testIdentity(self):
         from pypes import services




More information about the Zope-CVS mailing list