You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

98 lines
3.6 KiB

  1. import unittest
  2. from reportbug import checkversions
  3. from nose.plugins.attrib import attr
  4. import mock
  5. class TestCheckversions(unittest.TestCase):
  6. def test_compare_versions(self):
  7. # <current, upstream>
  8. # 1 upstream newer than current
  9. # 0 same version or upsteam none
  10. # -1 current newer than upstream
  11. self.assertEqual(checkversions.compare_versions('1.2.3', '1.2.4'), 1)
  12. self.assertEqual(checkversions.compare_versions('123', None), 0)
  13. self.assertEqual(checkversions.compare_versions('1.2.3', '1.2.3'), 0)
  14. self.assertEqual(checkversions.compare_versions(None, None), 0)
  15. self.assertEqual(checkversions.compare_versions('', '1.2.3'), 0)
  16. self.assertEqual(checkversions.compare_versions('1.2.4', '1.2.3'), -1)
  17. def test_later_version(self):
  18. # mock the test_compare_Versions() test
  19. self.assertEqual(checkversions.later_version('1.2.3', '1.2.4'), '1.2.4')
  20. self.assertEqual(checkversions.later_version('123', None), '123')
  21. self.assertEqual(checkversions.later_version('1.2.3', '1.2.3'), '1.2.3')
  22. self.assertIsNone(checkversions.later_version(None, None))
  23. self.assertEqual(checkversions.later_version('', '1.2.3'), '')
  24. self.assertEqual(checkversions.later_version('1.2.4', '1.2.3'), '1.2.4')
  25. class TestNewQueue(unittest.TestCase):
  26. def test_bts704040(self):
  27. # return an iterable object, so that Deb822 (what parses the result)
  28. # will work
  29. pkg_in_new = """Source: procps
  30. Binary: libprocps1-dev, procps, libprocps1
  31. Version: 1:3.3.6-2 1:3.3.6-1 1:3.3.7-1 1:3.3.5-1
  32. Architectures: source, amd64
  33. Age: 4 months
  34. Last-Modified: 1353190660
  35. Queue: new
  36. Maintainer: Craig Small <csmall@debian.org>
  37. Changed-By: Craig Small <csmall@debian.org>
  38. Distribution: experimental
  39. Fingerprint: 5D2FB320B825D93904D205193938F96BDF50FEA5
  40. Closes: #682082, #682083, #682086, #698482, #699716
  41. Changes-File: procps_3.3.6-1_amd64.changes
  42. Source: aaa
  43. """.split('\n')
  44. # save the original checkversions.open_url() method
  45. save_open_url = checkversions.open_url
  46. checkversions.open_url = mock.MagicMock(return_value=pkg_in_new)
  47. res = checkversions.get_newqueue_available('procps', 60)
  48. self.assertEqual(list(res.keys())[0], 'experimental (new)')
  49. self.assertEqual(res['experimental (new)'], '1:3.3.7-1')
  50. # restore the original checkversions.open_url() method
  51. checkversions.open_url = save_open_url
  52. class TestVersionAvailable(unittest.TestCase):
  53. @attr('network') # marking the test as using network
  54. def test_bts642032(self):
  55. vers = checkversions.get_versions_available('reportbug', 60)
  56. # check stable version is lower than unstable
  57. chk = checkversions.compare_versions(vers['stable'], vers['unstable'])
  58. self.assertGreaterEqual(chk, 0)
  59. @attr('network') # marking the test as using network
  60. def test_bts649649(self):
  61. # checking for non-existing package should not generate a traceback
  62. vers = checkversions.get_versions_available('blablabla', 60)
  63. self.assertEqual(vers, {})
  64. @attr('network') # marking the test as using network
  65. def test_bts673204(self):
  66. vers = checkversions.get_versions_available('texlive-xetex', 60)
  67. # squeeze (stable at this time) is the first suite where texlive-xetex
  68. # is arch:all
  69. self.assertIn('stable', vers)
  70. @attr('network')
  71. def test_codenames(self):
  72. vers = checkversions.get_versions_available('reportbug', 60, ['sid'])
  73. self.assertEqual(1, len(vers))
  74. self.assertEqual(list(vers.keys())[0], 'unstable')