dbtest_cruft.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python
  2. from db_test import DBDakTestCase
  3. from daklib.dbconn import *
  4. from daklib.cruft import *
  5. import unittest
  6. class CruftTestCase(DBDakTestCase):
  7. """
  8. This class checks various functions of cruft-report.
  9. """
  10. def setUp(self):
  11. super(CruftTestCase, self).setUp()
  12. self.install_date = self.now()
  13. self.setup_binaries()
  14. # flush to make sure that the setup is correct
  15. self.session.flush()
  16. def test_newer_version(self):
  17. 'tests newer_version()'
  18. list = newer_version('squeeze', 'sid', self.session)
  19. self.assertEqual([], list)
  20. self.file['sl_3.03-17.dsc'] = PoolFile(filename = 'main/s/sl/sl_3.03-17.dsc', \
  21. location = self.loc['main'], filesize = 0, md5sum = '')
  22. self.source['sl_3.03-17'] = DBSource(source = 'sl', version = '3.03-17', \
  23. maintainer = self.maintainer['maintainer'], \
  24. changedby = self.maintainer['uploader'], \
  25. poolfile = self.file['sl_3.03-17.dsc'], install_date = self.install_date)
  26. self.source['sl_3.03-17'].suites.append(self.suite['squeeze'])
  27. list = newer_version('squeeze', 'sid', self.session)
  28. self.assertEqual([('sl', '3.03-16', '3.03-17')], list)
  29. def test_multiple_source(self):
  30. 'tests functions related to report_multiple_source()'
  31. # test get_package_names()
  32. suite = get_suite('sid', self.session)
  33. self.assertEqual([('gnome-hello', ), ('hello', )], \
  34. get_package_names(suite).all())
  35. # test class NamedSource
  36. src = NamedSource(suite, 'hello')
  37. self.assertEqual('hello', src.source)
  38. self.assertEqual(['2.2-1', '2.2-2'], src.versions)
  39. self.assertEqual('hello(2.2-1, 2.2-2)', str(src))
  40. # test class DejavuBinary
  41. bin = DejavuBinary(suite, 'hello')
  42. self.assertEqual(False, bin.has_multiple_sources())
  43. # add another binary
  44. self.file['hello_2.2-3'] = PoolFile(filename = 'main/s/sl/hello_2.2-3_i386.deb', \
  45. location = self.loc['main'], filesize = 0, md5sum = '')
  46. self.binary['hello_2.2-3_i386'] = DBBinary(package = 'hello', \
  47. source = self.source['sl_3.03-16'], version = '2.2-3', \
  48. maintainer = self.maintainer['maintainer'], \
  49. architecture = self.arch['i386'], \
  50. poolfile = self.file['hello_2.2-3'])
  51. self.session.add(self.binary['hello_2.2-3_i386'])
  52. bin = DejavuBinary(suite, 'hello')
  53. self.assertEqual(False, bin.has_multiple_sources())
  54. # add it to suite sid
  55. self.binary['hello_2.2-3_i386'].suites.append(self.suite['sid'])
  56. bin = DejavuBinary(suite, 'hello')
  57. self.assertEqual(True, bin.has_multiple_sources())
  58. self.assertEqual('hello built by: hello(2.2-1, 2.2-2), sl(3.03-16)', \
  59. str(bin))
  60. if __name__ == '__main__':
  61. unittest.main()