dbtest_cruft.py 3.1 KB

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