dbtest_validation.py 920 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. from db_test import DBDakTestCase
  3. from daklib.dbconn import Architecture
  4. from daklib.dak_exceptions import DBUpdateError
  5. import unittest
  6. class ValidatorTestCase(DBDakTestCase):
  7. """
  8. The ValidatorTestCase tests the validation mechanism.
  9. """
  10. def test_validation(self):
  11. 'tests validate()'
  12. # before_insert validation should fail
  13. architecture = Architecture()
  14. self.session.add(architecture)
  15. self.assertRaises(DBUpdateError, self.session.flush)
  16. self.session.rollback()
  17. # should not fail
  18. architecture = Architecture('i386')
  19. self.session.add(architecture)
  20. self.session.flush()
  21. # before_update validation should fail
  22. architecture.arch_string = None
  23. self.assertRaises(DBUpdateError, self.session.flush)
  24. self.session.rollback()
  25. if __name__ == '__main__':
  26. unittest.main()