dbtest_cruft.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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[
  21. 'sl_3.03-17.dsc'] = PoolFile(filename='main/s/sl/sl_3.03-17.dsc',
  22. filesize=0, md5sum='')
  23. self.file['sl_3.03-17.dsc'].sha1sum = 'sha1sum'
  24. self.file['sl_3.03-17.dsc'].sha256sum = 'sha256sum'
  25. self.source['sl_3.03-17'] = DBSource(source='sl', version='3.03-17',
  26. maintainer=self.maintainer[
  27. 'maintainer'],
  28. changedby=self.maintainer[
  29. 'uploader'],
  30. poolfile=self.file['sl_3.03-17.dsc'], install_date=self.install_date)
  31. self.source['sl_3.03-17'].suites.append(self.suite['squeeze'])
  32. list = newer_version('squeeze', 'sid', self.session)
  33. self.assertEqual([('sl', '3.03-16', '3.03-17')], list)
  34. def test_multiple_source(self):
  35. 'tests functions related to report_multiple_source()'
  36. # test get_package_names()
  37. suite = get_suite('sid', self.session)
  38. self.assertEqual([('gnome-hello', ), ('hello', )],
  39. get_package_names(suite).all())
  40. # test class NamedSource
  41. src = NamedSource(suite, 'hello')
  42. self.assertEqual('hello', src.source)
  43. self.assertEqual(['2.2-1', '2.2-2'], src.versions)
  44. self.assertEqual('hello(2.2-1, 2.2-2)', str(src))
  45. # test class DejavuBinary
  46. bin = DejavuBinary(suite, 'hello')
  47. self.assertEqual(False, bin.has_multiple_sources())
  48. # add another binary
  49. self.file[
  50. 'hello_2.2-3'] = PoolFile(filename='main/s/sl/hello_2.2-3_i386.deb',
  51. filesize=0, md5sum='')
  52. self.file['hello_2.2-3'].sha1sum = 'sha1sum'
  53. self.file['hello_2.2-3'].sha256sum = 'sha256sum'
  54. self.binary['hello_2.2-3_i386'] = DBBinary(package='hello',
  55. source=self.source[
  56. 'sl_3.03-16'], version='2.2-3',
  57. maintainer=self.maintainer[
  58. 'maintainer'],
  59. architecture=self.arch[
  60. 'i386'],
  61. poolfile=self.file['hello_2.2-3'])
  62. self.session.add(self.binary['hello_2.2-3_i386'])
  63. bin = DejavuBinary(suite, 'hello')
  64. self.assertEqual(False, bin.has_multiple_sources())
  65. # add it to suite sid
  66. self.binary['hello_2.2-3_i386'].suites.append(self.suite['sid'])
  67. bin = DejavuBinary(suite, 'hello')
  68. self.assertEqual(True, bin.has_multiple_sources())
  69. self.assertEqual('hello built by: hello(2.2-1, 2.2-2), sl(3.03-16)',
  70. str(bin))
  71. if __name__ == '__main__':
  72. unittest.main()