[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_principalannotation.py:1.4

Jim Fulton jim@zope.com
Thu, 29 May 2003 14:16:55 -0400


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

Modified Files:
	test_principalannotation.py 
Log Message:
Renamed the getAnnotation and hasAnnotation methods of principal
annotation services to getAnnotations and hasAnnotations.

The implementation assumed it was getting principal ids even though
the interface said principals were passed and non testing clients
passed principals. Fixed the implementation to expect principals for
getAnnotations and hasAnnotations.

Added a getAnnotationsById, which is needed to do service delegation
in certain situations.

Now new annotations aren't stored unless they are modified. This is to
prevent database writes on "read" requests.


=== Zope3/src/zope/app/services/tests/test_principalannotation.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/services/tests/test_principalannotation.py:1.3	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_principalannotation.py	Thu May 29 14:16:55 2003
@@ -63,13 +63,18 @@
 
     def testGetSimple(self):
         prince = Principal('somebody')
-        self.assert_(not self.svc.hasAnnotation(prince.getId()))
+        self.assert_(not self.svc.hasAnnotations(prince))
 
-        princeAnnotation = self.svc.getAnnotation(prince.getId())
-        self.assert_(self.svc.hasAnnotation(prince.getId()))
+        princeAnnotation = self.svc.getAnnotations(prince)
+        # Just getting doesn't actualy store. We don't want to store unless
+        # we make a change.
+        self.assert_(not self.svc.hasAnnotations(prince))
 
         princeAnnotation['something'] = 'whatever'
 
+        # But now we should have the annotation:
+        self.assert_(self.svc.hasAnnotations(prince))
+
     def testGetFromLayered(self):
         princeSomebody = Principal('somebody')
         self.createServiceManager(self.folder1)
@@ -77,13 +82,18 @@
         sm1.PrincipalAnnotation = PrincipalAnnotationService()
         subService = getService(self.folder1, "PrincipalAnnotation")
 
-        parentAnnotation = self.svc.getAnnotation(princeSomebody.getId())
-        self.assert_(self.svc.hasAnnotation(princeSomebody.getId()))
-        self.assert_(not subService.hasAnnotation(princeSomebody.getId()))
+        parentAnnotation = self.svc.getAnnotations(princeSomebody)
+
+        # Just getting doesn't actualy store. We don't want to store unless
+        # we make a change.
+        self.assert_(not subService.hasAnnotations(princeSomebody))
 
         parentAnnotation['hair_color'] = 'blue'
 
-        subAnnotation = subService.getAnnotation(princeSomebody.getId())
+        # But now we should have the annotation:
+        self.assert_(self.svc.hasAnnotations(princeSomebody))
+
+        subAnnotation = subService.getAnnotations(princeSomebody)
         self.assertEquals(subAnnotation['hair_color'], 'blue')
 
         subAnnotation['foo'] = 'bar'
@@ -93,7 +103,8 @@
 
     def testAdapter(self):
         p = Principal('somebody')
-        provideAdapter(IPrincipal, IAnnotations, AnnotationsForPrincipal(self.svc))
+        provideAdapter(IPrincipal, IAnnotations,
+                       AnnotationsForPrincipal(self.svc))
         annotations = getAdapter(p, IAnnotations)
         annotations["test"] = "bar"
         annotations = getAdapter(p, IAnnotations)