[Zope-CVS] CVS: Products/AdaptableStorage/tests - Zope2TestBase.py:1.10 testZope2FS.py:1.24

Shane Hathaway shane@zope.com
Tue, 4 Mar 2003 23:25:16 -0500


Update of /cvs-repository/Products/AdaptableStorage/tests
In directory cvs.zope.org:/tmp/cvs-serv27335/tests

Modified Files:
	Zope2TestBase.py testZope2FS.py 
Log Message:
Several changes to FSConnection:

- Moved pickled remainders to their own file.  This is important for
placing ZODB data under version control, since property files are
text, while remainder pickles need to be stored as binary files (even
text pickles should be stored as binary).

- Property files are now opened in text mode.  Next we need to make it
possible to read/write the data stream in text mode.

- Renamed all semi-private FSConnection methods to start with an
underscore.

- Dotted filenames are now allowed, but only if they don't look like
property or remainder files.

- Expanded the security attributes test (which revealed the SQL
gateway int/long OID bug)

- Don't write the [security] section if there are no security
declarations for an object.



=== Products/AdaptableStorage/tests/Zope2TestBase.py 1.9 => 1.10 ===
--- Products/AdaptableStorage/tests/Zope2TestBase.py:1.9	Sat Mar  1 15:43:03 2003
+++ Products/AdaptableStorage/tests/Zope2TestBase.py	Tue Mar  4 23:25:06 2003
@@ -93,6 +93,8 @@
                 self.assert_(hasattr(app, 'Holidays'))
                 self.assert_(hasattr(app.Holidays, 'Christmas'))
                 self.assert_(hasattr(app.Holidays.Christmas, 'Eve'))
+                # Verify the same OID is seen in both connections.
+                self.assertEqual(app.Holidays._p_oid, f._p_oid)
             finally:
                 conn2.close()
 
@@ -489,26 +491,39 @@
 
             conn2 = self.db.open()
             try:
+                # Verify that loading works
                 app = conn2.root()['Application']
-                f = app.Holidays
-                user = f.getOwner()
+                f2 = app.Holidays
+                user = f2.getOwner()
                 self.assertEqual(user.getUserName(), 'shane')
                 self.assert_('Elder' in user.getRoles())
 
                 roles = {}
-                for role in list(user.getRolesInContext(f)):
+                for role in list(user.getRolesInContext(f2)):
                     if role != 'Authenticated' and role != 'Anonymous':
                         roles[role] = 1
                 self.assertEqual(roles, {'Elder':1, 'Missionary':1})
-                self.assertEqual(tuple(f._proxy_roles), ('Manager',))
+                self.assertEqual(tuple(f2._proxy_roles), ('Manager',))
 
                 roles = {}
-                for role in list(f._View_Permission):
+                for role in list(f2._View_Permission):
                     roles[role] = 1
                 self.assertEqual(roles, {'Elder':1, 'Owner':1})
+
+                # Write some changes to verify that changes work
+                f2._owner = None
+                del f2._proxy_roles
+                f2.__ac_roles__ += ['Teacher']
+                get_transaction().commit()
             finally:
                 conn2.close()
 
+            # Make sure the changes are seen
+            conn.sync()
+            self.assert_(f.getOwner() is None, f.getOwner())
+            self.assert_(not hasattr(f, '_proxy_roles'))
+            self.assertEqual(len(f.__ac_roles__), 3)
+            self.assert_('Teacher' in f.__ac_roles__)
         finally:
             conn.close()
 


=== Products/AdaptableStorage/tests/testZope2FS.py 1.23 => 1.24 ===
--- Products/AdaptableStorage/tests/testZope2FS.py:1.23	Mon Mar  3 17:55:23 2003
+++ Products/AdaptableStorage/tests/testZope2FS.py	Tue Mar  4 23:25:06 2003
@@ -148,7 +148,7 @@
             app._setObject(template.id, template, set_owner=0)
             get_transaction().commit()
 
-            dir = self.conn.expandPath('/')
+            dir = self.conn._expandPath('/')
             names = os.listdir(dir)
             self.assert_('template.html' in names, names)
             self.assert_('template' not in names, names)
@@ -180,7 +180,7 @@
                     self.assert_(not hasattr(f, 'script%d.py' % n))
                 # white box test: verify the scripts were actually stored
                 # with .py extensions.
-                dir = self.conn.expandPath('/folder')
+                dir = self.conn._expandPath('/folder')
                 names = os.listdir(dir)
                 for n in range(3):
                     self.assert_(('script%d.py' % n) in names, names)
@@ -214,7 +214,7 @@
                     self.assert_(not hasattr(f, 'script%d' % n))
                 # white box test: verify the scripts were actually stored
                 # with .py extensions.
-                dir = self.conn.expandPath('/folder')
+                dir = self.conn._expandPath('/folder')
                 names = os.listdir(dir)
                 for n in range(3):
                     self.assert_(('script%d.py' % n) in names, names)
@@ -240,7 +240,7 @@
             f._setObject(script.id, script, set_owner=0)
             get_transaction().commit()
 
-            dir = self.conn.expandPath('/folder')
+            dir = self.conn._expandPath('/folder')
             names = os.listdir(dir)
             self.assert_(('script0.py') in names, names)
             self.assert_(('script0') not in names, names)
@@ -274,7 +274,7 @@
             f._setObject(script.id, script, set_owner=0)
             get_transaction().commit()
 
-            dir = self.conn.expandPath('/folder')
+            dir = self.conn._expandPath('/folder')
             names = os.listdir(dir)
             self.assert_(('script0.py') in names, names)
             self.assert_(('script0') in names, names)
@@ -348,7 +348,7 @@
             f._setObject(script.id, script, set_owner=0)
             get_transaction().commit()
 
-            dir = self.conn.expandPath('/folder')
+            dir = self.conn._expandPath('/folder')
             names = os.listdir(dir)
             self.assert_(('script0.py') in names, names)
             self.assert_(('script0.dtml') in names, names)
@@ -419,7 +419,7 @@
             finally:
                 conn2.close()
 
-            dir = self.conn.expandPath('/')
+            dir = self.conn._expandPath('/')
             names = os.listdir(dir)
             self.assert_(('image.png') in names, names)
             self.assert_(('image') not in names, names)
@@ -436,13 +436,16 @@
             app = conn.root()['Application']
             manage_addFile(app, 'hello', StringIO(data),
                            content_type='text/plain')
+            manage_addFile(app, 'world.dat', StringIO(data),
+                           content_type='text/plain')
             manage_addFile(app, 'binary_file', StringIO(data),
                            content_type='application/octet-stream')
             get_transaction().commit()
 
-            dir = self.conn.expandPath('/')
+            dir = self.conn._expandPath('/')
             names = os.listdir(dir)
             self.assert_(('hello.txt') in names, names)
+            self.assert_(('world.dat') in names, names)
             self.assert_(('hello') not in names, names)
             self.assert_(('binary_file') in names, names)
         finally:
@@ -453,7 +456,7 @@
         # Verify Zope chooses the right object type for
         # a new object.
         # White box test.
-        dir = self.conn.expandPath('/')
+        dir = self.conn._expandPath('/')
         f = open(os.path.join(dir, 'test.py'), 'wt')
         f.write('return "Ok!"')
         f.close()
@@ -471,10 +474,11 @@
         # Verify that even though the extension gets stripped off
         # in Zope, Zope still sees the object as it should.
         # White box test.
-        dir = self.conn.expandPath('/')
+        dir = self.conn._expandPath('/')
         f = open(os.path.join(dir, 'test.py'), 'wt')
         f.write('return "Ok!"')
         f.close()
+        
         f = open(os.path.join(dir, self.conn.metadata_prefix
                               + 'properties'), 'wt')
         f.write('[object_names]\ntest\n')
@@ -490,10 +494,10 @@
 
 
     def testFallbackToFile(self):
-        # Verify Zope uses a File object for unrecognized stuff.
-        # White box test.
+        # Verify Zope uses a File object for unrecognized files on
+        # the filesystem.  White box test.
         data = 'data goes here'
-        dir = self.conn.expandPath('/')
+        dir = self.conn._expandPath('/')
         f = open(os.path.join(dir, 'test'), 'wt')
         f.write(data)
         f.close()
@@ -510,7 +514,7 @@
     def testDefaultPropertySchema(self):
         # Verify Zope uses the default property schema when no properties
         # are set.
-        dir = self.conn.expandPath('/')
+        dir = self.conn._expandPath('/')
         os.mkdir(os.path.join(dir, 'test'))
         conn = self.db.open()
         try:
@@ -524,6 +528,34 @@
                     break
             else:
                 self.fail('No title property found')
+        finally:
+            conn.close()
+
+
+    def testRemainderStorage(self):
+        # Verify that FSConnection puts the remainder in a separate file
+        conn = self.db.open()
+        try:
+            content = 'tacked_on_data'
+            app = conn.root()['Application']
+            app._stowaway = content
+            get_transaction().commit()
+
+            # Verify the ability to load it
+            conn2 = self.db.open()
+            try:
+                app2 = conn2.root()['Application']
+                self.assertEqual(app2._stowaway, content)
+            finally:
+                conn2.close()
+
+            # Verify the stowaway is in the remainder file.
+            dir = self.conn._expandPath('/')
+            f = open(os.path.join(dir, self.conn.metadata_prefix
+                                  + 'remainder'), 'rb')
+            data = f.read()
+            f.close()
+            self.assert_(data.find(content) >= 0)
         finally:
             conn.close()