]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_timestamps.py
debianqueued: No early notifications
[dak.git] / tests / dbtest_timestamps.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import DBConn, Uid
6
7 import time
8 import unittest
9
10 class TimestampTestCase(DBDakTestCase):
11     """
12     TimestampTestCase checks that the timestamps created and modified are
13     working correctly.
14
15     TODO: Should we check all tables?
16     """
17
18     def sleep(self):
19         time.sleep(0.001)
20
21     def test_timestamps(self):
22         timestamp01 = self.now()
23         self.session.rollback()
24         self.sleep()
25         uid = Uid(uid = 'ftp-master@debian.org')
26         self.session.add(uid)
27         self.session.commit()
28         created01 = uid.created
29         modified01 = uid.modified
30         self.sleep()
31         timestamp02 = self.now()
32         self.session.rollback()
33         self.assertTrue(timestamp01 < created01)
34         self.assertTrue(timestamp01 < modified01)
35         self.assertTrue(created01 < timestamp02)
36         self.assertTrue(modified01 < timestamp02)
37         self.sleep()
38         uid.name = 'ftp team'
39         self.session.commit()
40         created02 = uid.created
41         modified02 = uid.modified
42         self.assertEqual(created01, created02)
43         self.assertTrue(modified01 < modified02)
44         self.sleep()
45         self.session.rollback()
46         timestamp03 = self.now()
47         self.assertTrue(modified02 < timestamp03)
48
49     def classes_to_clean(self):
50         return (Uid,)
51
52 if __name__ == '__main__':
53     unittest.main()