dbtest_timestamps.py 1.4 KB

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