add simple tests for standard metadata hooks
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 23 Jul 2009 15:15:29 +0200
changeset 2454 3648b718a0d3
parent 2453 0faf7b5cdc71
child 2455 5346d9f3d5ec
add simple tests for standard metadata hooks
server/test/unittest_hooks.py
--- a/server/test/unittest_hooks.py	Thu Jul 23 15:15:05 2009 +0200
+++ b/server/test/unittest_hooks.py	Thu Jul 23 15:15:29 2009 +0200
@@ -6,9 +6,13 @@
 """
 
 from logilab.common.testlib import TestCase, unittest_main
+
+from datetime import datetime
+
+from cubicweb import (ConnectionError, RepositoryError, ValidationError,
+                      AuthenticationError, BadConnectionId)
 from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
 
-from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.repository import Repository
 
@@ -614,5 +618,34 @@
         self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'"))
         cnx.commit()
 
+    def test_metadata_creation_modification_date(self):
+        _now = datetime.now()
+        eid = self.execute('INSERT Note X')[0][0]
+        creation_date, modification_date = self.execute('Any CD, MD WHERE X eid %s, '
+                                                        'X creation_date CD, '
+                                                        'X modification_date MD' % eid)[0]
+        self.assertEquals((creation_date - _now).seconds, 0)
+        self.assertEquals((modification_date - _now).seconds, 0)
+
+    def test_metadata__date(self):
+        _now = datetime.now()
+        eid = self.execute('INSERT Note X')[0][0]
+        creation_date = self.execute('Any D WHERE X eid %s, X creation_date D' % eid)[0][0]
+        self.assertEquals((creation_date - _now).seconds, 0)
+
+    def test_metadata_created_by(self):
+        eid = self.execute('INSERT Note X')[0][0]
+        self.commit() # fire operations
+        rset = self.execute('Any U WHERE X eid %s, X created_by U' % eid)
+        self.assertEquals(len(rset), 1) # make sure we have only one creator
+        self.assertEquals(rset[0][0], self.session.user.eid)
+
+    def test_metadata_owned_by(self):
+        eid = self.execute('INSERT Note X')[0][0]
+        self.commit() # fire operations
+        rset = self.execute('Any U WHERE X eid %s, X owned_by U' % eid)
+        self.assertEquals(len(rset), 1) # make sure we have only one owner
+        self.assertEquals(rset[0][0], self.session.user.eid)
+
 if __name__ == '__main__':
     unittest_main()