dbtest_ormobject.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. from db_test import DBDakTestCase
  3. from daklib.dbconn import Architecture, Suite
  4. from daklib.dak_exceptions import DBUpdateError
  5. try:
  6. # python >= 2.6
  7. import json
  8. except:
  9. # python <= 2.5
  10. import simplejson as json
  11. import re
  12. import unittest
  13. class ORMObjectTestCase(DBDakTestCase):
  14. """
  15. The ORMObjectTestCase tests the behaviour of the ORMObject.
  16. """
  17. def test_strings(self):
  18. 'tests json(), __repr__(), and __str__()'
  19. architecture = Architecture(arch_string = 'i386')
  20. # test json()
  21. data = json.loads(architecture.json())
  22. self.assertEqual('i386', data['arch_string'])
  23. # test repr()
  24. self.assertEqual('<Architecture i386>', repr(architecture))
  25. # test str()
  26. self.assertTrue(re.match('<Architecture {.*}>', str(architecture)))
  27. self.assertTrue(re.search('"arch_string": "i386"', str(architecture)))
  28. sid = Suite(suite_name = 'sid')
  29. squeeze = Suite(suite_name = 'squeeze')
  30. architecture.suites = [sid, squeeze]
  31. self.assertTrue(re.search('"suites_count": 2', str(architecture)))
  32. def test_validation(self):
  33. suite = Suite()
  34. self.session.add(suite)
  35. self.assertRaises(DBUpdateError, self.session.flush)
  36. if __name__ == '__main__':
  37. unittest.main()