test_daklib_dbconn.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /usr/bin/env python3
  2. #
  3. # Copyright (C) 2018, Ansgar Burchardt <ansgar@debian.org>
  4. # License: GPL-2+
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. from base_test import DakTestCase
  19. import unittest
  20. import daklib.dbconn
  21. class DummyChanges(object):
  22. def __init__(self, source, version, changesname):
  23. self.source = source
  24. self.version = version
  25. self.changesname = changesname
  26. class DummySortablePolicyQueueUpload(daklib.dbconn.PolicyQueueUpload):
  27. def __init__(self, source, version, sourceful, filename):
  28. self.changes = DummyChanges(source, version, filename)
  29. self.source = True if sourceful else None
  30. class TestSortableChanges(DakTestCase):
  31. def testEq(self):
  32. a = DummySortablePolicyQueueUpload(
  33. 'source', '1.0-1', True, 'source_1.0-1_amd64.changes')
  34. self.assertTrue(a == a)
  35. self.assertTrue(a <= a)
  36. self.assertTrue(a >= a)
  37. self.assertFalse(a < a)
  38. self.assertFalse(a > a)
  39. def testSourceDiffers1(self):
  40. a = DummySortablePolicyQueueUpload(
  41. 'a', '1.0-1', False, 'a_1.0-1_amd64.changes')
  42. b = DummySortablePolicyQueueUpload(
  43. 'b', '1.0-1', False, 'b_1.0-1_amd64.changes')
  44. self.assertTrue(a < b)
  45. self.assertFalse(a == b)
  46. def testSourceDiffers2(self):
  47. a = DummySortablePolicyQueueUpload(
  48. 'a', '2.0-1', False, 'a_2.0-1_amd64.changes')
  49. b = DummySortablePolicyQueueUpload(
  50. 'b', '1.0-1', False, 'b_1.0-1_amd64.changes')
  51. self.assertTrue(a < b)
  52. self.assertFalse(a == b)
  53. def testSourcefulSortsFirst(self):
  54. a = DummySortablePolicyQueueUpload(
  55. 'a', '1.0-1', True, 'a_1.0-1_powerpc.changes')
  56. b = DummySortablePolicyQueueUpload(
  57. 'a', '1.0-1', False, 'a_1.0-1_amd64.changes')
  58. self.assertTrue(a < b)
  59. self.assertFalse(a == b)