Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Attributes
Archetypes.tests.test_athistoryaware.ATHistoryAwareTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_historyMetadata
def test_objectContext
def test_simpleAttributes
def test_annotation
def test_annotationlifetime
def test_maxReturned

Public Attributes

 app
 object

Private Attributes

 _dir
 _storage
 _connection

Detailed Description

Definition at line 34 of file test_athistoryaware.py.


Member Function Documentation

Definition at line 35 of file test_athistoryaware.py.

00035 
00036     def setUp(self):
00037         # Set up a ZODB and Application object. We can't use DemoStorage 
00038         # as it doesn't support the history() API.
00039         self._dir = tempfile.mkdtemp()
00040         self._storage = FileStorage(
00041             os.path.join(self._dir,'test_athistoryaware.fs'),
00042             create=True)
00043         self._connection = ZODB.DB(self._storage).open()
00044         root = self._connection.root()
00045         root['Application'] = OFS.Application.Application()
00046         self.app = root['Application']
00047         
00048         # Our basic testing object
00049         self.app.object = DummyObject()
00050         self.object = self.app.object
00051         t = transaction.get()
00052         t.description = None # clear initial transaction note
00053         t.note('Transaction 1')
00054         t.setUser('User 1')
00055         t.commit()
00056         
00057         # Alter object and annotations over several transactions
00058         annotations = self.object.__annotations__
00059         self.object.foo = 'baz'
00060         annotations[KEY1].spam = 'python'
00061         t = transaction.get()
00062         t.note('Transaction 2')
00063         t.setUser('User 2')
00064         t.commit()
00065         
00066         annotations[KEY3] = DummyAnnotation()
00067         t = transaction.get()
00068         t.note('Transaction 3')
00069         t.setUser('User 3')
00070         t.commit()
00071         
00072         del annotations[KEY3]
00073         annotations[KEY2].spam = 'lumberjack'
00074         t = transaction.get()
00075         t.note('Transaction 4')
00076         t.setUser('User 4')
00077         t.commit()
00078         
00079         self.object.foo = 'mit'
00080         annotations[KEY1].spam = 'trout'
00081         t = transaction.get()
00082         t.note('Transaction 5')
00083         t.setUser('User 5')
00084         t.commit()
        

Definition at line 85 of file test_athistoryaware.py.

00085 
00086     def tearDown(self):
00087         transaction.abort()
00088         del self.app
00089         self._connection.close()
00090         del self._connection
00091         self._storage.close()
00092         del self._storage
00093         shutil.rmtree(self._dir)
        
Persistent subkeys of the __annotations__ object

Definition at line 112 of file test_athistoryaware.py.

00112 
00113     def test_annotation(self):
00114         """Persistent subkeys of the __annotations__ object"""
00115         key1_history = (e[0].__annotations__[KEY1].spam
00116                         for e in self.object.getHistories())
00117         expected = ('trout', 'python', 'python', 'python', 'eggs')
00118         self.assertEqual(tuple(key1_history), expected)
00119         
00120         key2_history = (e[0].__annotations__[KEY2].spam
00121                         for e in self.object.getHistories())
00122         expected = ('lumberjack', 'lumberjack', 'eggs', 'eggs', 'eggs')
00123         self.assertEqual(tuple(key2_history), expected)
        
Addition and deletion of subkeys is tracked

Definition at line 124 of file test_athistoryaware.py.

00124 
00125     def test_annotationlifetime(self):
00126         """Addition and deletion of subkeys is tracked"""
00127         key3_history = (bool(e[0].__annotations__.has_key(KEY3))
00128                         for e in self.object.getHistories())
00129         expected = (False, False, True, False, False)
00130         self.assertEqual(tuple(key3_history), expected)
        
Each revision entry has unique metadata

Definition at line 94 of file test_athistoryaware.py.

00094 
00095     def test_historyMetadata(self):
00096         """Each revision entry has unique metadata"""
00097         for i, entry in enumerate(self.object.getHistories()):
00098             # History is returned in reverse order, so Transaction 5 is first
00099             self.assertEqual(entry[2], 'Transaction %d' % (5 - i))
00100             self.assertEqual(entry[3], '/ User %d' % (5 - i))
            

Definition at line 131 of file test_athistoryaware.py.

00131 
00132     def test_maxReturned(self):
00133         history = list(self.object.getHistories(max=2))
00134         self.assertEqual(len(history), 2)
        
Objects are returned with an acquisition context

Definition at line 101 of file test_athistoryaware.py.

00101 
00102     def test_objectContext(self):
00103         """Objects are returned with an acquisition context"""
00104         for entry in self.object.getHistories():
00105             self.assertEqual(entry[0].aq_parent, self.app)
        
Simple, non-persistent attributes are tracked

Definition at line 106 of file test_athistoryaware.py.

00106 
00107     def test_simpleAttributes(self):
00108         """Simple, non-persistent attributes are tracked"""
00109         foo_history = (e[0].foo for e in self.object.getHistories())
00110         expected = ('mit', 'baz', 'baz', 'baz', 'bar')
00111         self.assertEqual(tuple(foo_history), expected)
        

Member Data Documentation

Definition at line 42 of file test_athistoryaware.py.

Definition at line 38 of file test_athistoryaware.py.

Definition at line 39 of file test_athistoryaware.py.

Definition at line 45 of file test_athistoryaware.py.

Definition at line 49 of file test_athistoryaware.py.


The documentation for this class was generated from the following file: