4 note: most schemahooks.py hooks are actually tested in unittest_migrations.py |
4 note: most schemahooks.py hooks are actually tested in unittest_migrations.py |
5 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
5 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 """ |
6 """ |
7 |
7 |
8 from logilab.common.testlib import TestCase, unittest_main |
8 from logilab.common.testlib import TestCase, unittest_main |
|
9 |
|
10 from datetime import datetime |
|
11 |
|
12 from cubicweb import (ConnectionError, RepositoryError, ValidationError, |
|
13 AuthenticationError, BadConnectionId) |
9 from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions |
14 from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions |
10 |
15 |
11 from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId |
|
12 from cubicweb.server.sqlutils import SQL_PREFIX |
16 from cubicweb.server.sqlutils import SQL_PREFIX |
13 from cubicweb.server.repository import Repository |
17 from cubicweb.server.repository import Repository |
14 |
18 |
15 orig_get_versions = Repository.get_versions |
19 orig_get_versions = Repository.get_versions |
16 |
20 |
612 cnx = self.login('toto') |
616 cnx = self.login('toto') |
613 cu = cnx.cursor() |
617 cu = cnx.cursor() |
614 self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'")) |
618 self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'")) |
615 cnx.commit() |
619 cnx.commit() |
616 |
620 |
|
621 def test_metadata_creation_modification_date(self): |
|
622 _now = datetime.now() |
|
623 eid = self.execute('INSERT Note X')[0][0] |
|
624 creation_date, modification_date = self.execute('Any CD, MD WHERE X eid %s, ' |
|
625 'X creation_date CD, ' |
|
626 'X modification_date MD' % eid)[0] |
|
627 self.assertEquals((creation_date - _now).seconds, 0) |
|
628 self.assertEquals((modification_date - _now).seconds, 0) |
|
629 |
|
630 def test_metadata__date(self): |
|
631 _now = datetime.now() |
|
632 eid = self.execute('INSERT Note X')[0][0] |
|
633 creation_date = self.execute('Any D WHERE X eid %s, X creation_date D' % eid)[0][0] |
|
634 self.assertEquals((creation_date - _now).seconds, 0) |
|
635 |
|
636 def test_metadata_created_by(self): |
|
637 eid = self.execute('INSERT Note X')[0][0] |
|
638 self.commit() # fire operations |
|
639 rset = self.execute('Any U WHERE X eid %s, X created_by U' % eid) |
|
640 self.assertEquals(len(rset), 1) # make sure we have only one creator |
|
641 self.assertEquals(rset[0][0], self.session.user.eid) |
|
642 |
|
643 def test_metadata_owned_by(self): |
|
644 eid = self.execute('INSERT Note X')[0][0] |
|
645 self.commit() # fire operations |
|
646 rset = self.execute('Any U WHERE X eid %s, X owned_by U' % eid) |
|
647 self.assertEquals(len(rset), 1) # make sure we have only one owner |
|
648 self.assertEquals(rset[0][0], self.session.user.eid) |
|
649 |
617 if __name__ == '__main__': |
650 if __name__ == '__main__': |
618 unittest_main() |
651 unittest_main() |