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.
 
 
 
 
 

228 lines
13 KiB

  1. import unittest
  2. from nose.plugins.attrib import attr
  3. import mock
  4. from reportbug import utils
  5. from reportbug import debbugs
  6. from reportbug import urlutils
  7. import urllib.request, urllib.parse, urllib.error
  8. import re
  9. class TestDebianbts(unittest.TestCase):
  10. def test_get_tags(self):
  11. # for each severity, for each mode
  12. self.assertCountEqual(list(debbugs.get_tags('critical', utils.MODE_NOVICE).keys()),
  13. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch', 'newcomer'])
  14. self.assertCountEqual(list(debbugs.get_tags('grave', utils.MODE_NOVICE).keys()),
  15. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch', 'newcomer'])
  16. self.assertCountEqual(list(debbugs.get_tags('serious', utils.MODE_NOVICE).keys()),
  17. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch', 'newcomer'])
  18. self.assertCountEqual(list(debbugs.get_tags('important', utils.MODE_NOVICE).keys()),
  19. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  20. self.assertCountEqual(list(debbugs.get_tags('does-not-build', utils.MODE_NOVICE).keys()),
  21. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  22. self.assertCountEqual(list(debbugs.get_tags('normal', utils.MODE_NOVICE).keys()),
  23. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  24. self.assertCountEqual(list(debbugs.get_tags('non-critical', utils.MODE_NOVICE).keys()),
  25. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  26. self.assertCountEqual(list(debbugs.get_tags('minor', utils.MODE_NOVICE).keys()),
  27. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  28. self.assertCountEqual(list(debbugs.get_tags('wishlist', utils.MODE_NOVICE).keys()),
  29. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  30. self.assertCountEqual(list(debbugs.get_tags('critical', utils.MODE_STANDARD).keys()),
  31. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch', 'newcomer'])
  32. self.assertCountEqual(list(debbugs.get_tags('grave', utils.MODE_STANDARD).keys()),
  33. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch', 'newcomer'])
  34. self.assertCountEqual(list(debbugs.get_tags('serious', utils.MODE_STANDARD).keys()),
  35. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch', 'newcomer'])
  36. self.assertCountEqual(list(debbugs.get_tags('important', utils.MODE_STANDARD).keys()),
  37. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  38. self.assertCountEqual(list(debbugs.get_tags('does-not-build', utils.MODE_STANDARD).keys()),
  39. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  40. self.assertCountEqual(list(debbugs.get_tags('normal', utils.MODE_STANDARD).keys()),
  41. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  42. self.assertCountEqual(list(debbugs.get_tags('non-critical', utils.MODE_STANDARD).keys()),
  43. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  44. self.assertCountEqual(list(debbugs.get_tags('minor', utils.MODE_STANDARD).keys()),
  45. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  46. self.assertCountEqual(list(debbugs.get_tags('wishlist', utils.MODE_STANDARD).keys()),
  47. ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch', 'newcomer'])
  48. self.assertCountEqual(list(debbugs.get_tags('critical', utils.MODE_ADVANCED).keys()),
  49. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  50. self.assertCountEqual(list(debbugs.get_tags('grave', utils.MODE_ADVANCED).keys()),
  51. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  52. self.assertCountEqual(list(debbugs.get_tags('serious', utils.MODE_ADVANCED).keys()),
  53. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  54. self.assertCountEqual(list(debbugs.get_tags('important', utils.MODE_ADVANCED).keys()),
  55. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  56. self.assertCountEqual(list(debbugs.get_tags('does-not-build', utils.MODE_ADVANCED).keys()),
  57. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  58. self.assertCountEqual(list(debbugs.get_tags('normal', utils.MODE_ADVANCED).keys()),
  59. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  60. self.assertCountEqual(list(debbugs.get_tags('non-critical', utils.MODE_ADVANCED).keys()),
  61. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  62. self.assertCountEqual(list(debbugs.get_tags('minor', utils.MODE_ADVANCED).keys()),
  63. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  64. self.assertCountEqual(list(debbugs.get_tags('wishlist', utils.MODE_ADVANCED).keys()),
  65. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  66. self.assertCountEqual(list(debbugs.get_tags('critical', utils.MODE_EXPERT).keys()),
  67. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  68. self.assertCountEqual(list(debbugs.get_tags('grave', utils.MODE_EXPERT).keys()),
  69. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  70. self.assertCountEqual(list(debbugs.get_tags('serious', utils.MODE_EXPERT).keys()),
  71. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  72. self.assertCountEqual(list(debbugs.get_tags('important', utils.MODE_EXPERT).keys()),
  73. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  74. self.assertCountEqual(list(debbugs.get_tags('does-not-build', utils.MODE_EXPERT).keys()),
  75. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  76. self.assertCountEqual(list(debbugs.get_tags('normal', utils.MODE_EXPERT).keys()),
  77. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  78. self.assertCountEqual(list(debbugs.get_tags('non-critical', utils.MODE_EXPERT).keys()),
  79. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  80. self.assertCountEqual(list(debbugs.get_tags('minor', utils.MODE_EXPERT).keys()),
  81. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  82. self.assertCountEqual(list(debbugs.get_tags('wishlist', utils.MODE_EXPERT).keys()),
  83. ['l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'newcomer'])
  84. class TestInfofunc(unittest.TestCase):
  85. def test_dpkg_infofunc(self):
  86. info = debbugs.dpkg_infofunc()
  87. arch = utils.get_arch()
  88. self.assertIn('Architecture:', info)
  89. self.assertIn(arch, info)
  90. self.assertIn('Architecture: ' + arch, info)
  91. self.assertTrue(info.endswith('\n\n'))
  92. # save original method
  93. __save1 = utils.get_arch
  94. __save2 = utils.get_multiarch
  95. utils.get_arch = mock.MagicMock(return_value='non-existing-arch')
  96. info = debbugs.dpkg_infofunc()
  97. self.assertIn('non-existing-arch', info)
  98. self.assertTrue(info.endswith('\n\n'))
  99. # test with get_arch() returning None
  100. utils.get_arch = mock.MagicMock(return_value=None)
  101. info = debbugs.dpkg_infofunc()
  102. self.assertIn('Architecture: ?', info)
  103. self.assertTrue(info.endswith('\n\n'))
  104. # test with a dummy m-a setup
  105. utils.get_multiarch = mock.MagicMock(return_value='multi-arch-ified')
  106. info = debbugs.dpkg_infofunc()
  107. self.assertIn('Foreign Architectures:', info)
  108. self.assertIn('multi-arch-ified', info)
  109. self.assertIn('Foreign Architectures: multi-arch-ified', info)
  110. utils.get_arch = __save1
  111. utils.get_multiarch = __save2
  112. del __save1
  113. del __save2
  114. def test_debian_infofunc(self):
  115. info = debbugs.debian_infofunc()
  116. self.assertIn('Architecture:', info)
  117. def test_ubuntu_infofunc(self):
  118. info = debbugs.ubuntu_infofunc()
  119. self.assertIn('Architecture:', info)
  120. def test_generic_infofunc(self):
  121. info = debbugs.generic_infofunc()
  122. self.assertIn('Architecture:', info)
  123. class TestMiscFunctions(unittest.TestCase):
  124. def test_yn_bool(self):
  125. self.assertEqual(debbugs.yn_bool(None), 'no')
  126. self.assertEqual(debbugs.yn_bool('no'), 'no')
  127. self.assertEqual(debbugs.yn_bool('yes'), 'yes')
  128. self.assertEqual(debbugs.yn_bool('dummy string'), 'yes')
  129. def test_convert_severity(self):
  130. # lists of bts systems, severity and the expected value in return
  131. sevs = [('debbugs', 'critical', 'critical'),
  132. ('debbugs', 'non-critical', 'normal'),
  133. (None, 'dummy', 'dummy'),
  134. ('gnats', 'important', 'serious'),
  135. ('gnats', 'dummy', 'dummy')]
  136. for type, severity, value in sevs:
  137. self.assertEqual(debbugs.convert_severity(severity, type), value)
  138. @attr('network') # marking the test as using network
  139. def test_pseudopackages_in_sync(self):
  140. dictparse = re.compile(r'([^\s]+)\s+(.+)', re.IGNORECASE)
  141. bdo_list = {}
  142. pseudo = urlutils.urlopen('https://bugs.debian.org/pseudopackages/pseudo-packages.description')
  143. for l in pseudo.splitlines():
  144. m = dictparse.search(l)
  145. bdo_list[m.group(1)] = m.group(2)
  146. # we removed base from reportbug
  147. del bdo_list['base']
  148. # uniform reportbug customized descriptions
  149. for customized in ['ftp.debian.org', ]:
  150. bdo_list[customized] = debbugs.debother[customized]
  151. self.maxDiff = None
  152. self.assertEqual(debbugs.debother, bdo_list)
  153. class TestGetReports(unittest.TestCase):
  154. @attr('network') # marking the test as using network
  155. def test_get_reports(self):
  156. data = debbugs.get_reports('reportbug', timeout=60)
  157. self.assertGreater(data[0], 0)
  158. @attr('network') # marking the test as using network
  159. def test_get_report(self):
  160. buginfo, bodies = debbugs.get_report(415801, 120)
  161. self.assertEqual(buginfo.bug_num, 415801)
  162. self.assertEqual(buginfo.subject,
  163. 'reportbug: add support for SOAP interface to BTS')
  164. # relative to bts#637994, report with messages without a header
  165. buginfo, bodies = debbugs.get_report(503300, 120)
  166. self.assertGreater(len(bodies), 0)
  167. @attr('network') # marking the test as using network
  168. def test_bts796759(self):
  169. # verify accessing WNPP happens correctly, now that BTS
  170. # access has to be done in batches
  171. data = debbugs.get_reports('wnpp', 120, source=True)
  172. self.assertGreater(data[0], 0)
  173. class TestUrlFunctions(unittest.TestCase):
  174. def test_cgi_report_url(self):
  175. self.assertCountEqual(debbugs.cgi_report_url('debian', 123).split('?')[1].split('&'),
  176. 'bug=123&archived=False&mbox=no'.split('&'))
  177. self.assertIsNone(debbugs.cgi_report_url('default', 123))
  178. def test_cgi_package_url(self):
  179. self.assertCountEqual(debbugs.cgi_package_url('debian', 'reportbug').split('?')[1].split('&'),
  180. 'repeatmerged=yes&archived=no&pkg=reportbug'.split('&'))
  181. self.assertCountEqual(debbugs.cgi_package_url('debian', 'reportbug', source=True).split('?')[1].split('&'),
  182. 'src=reportbug&archived=no&repeatmerged=yes'.split('&'))
  183. self.assertCountEqual(debbugs.cgi_package_url('debian', 'reportbug', version='5.0').split('?')[1].split('&'),
  184. 'pkg=reportbug&version=5.0&repeatmerged=yes&archived=no'.split('&'))
  185. def test_get_package_url(self):
  186. self.assertCountEqual(debbugs.get_package_url('debian', 'reportbug').split('?')[1].split('&'),
  187. 'archived=no&pkg=reportbug&repeatmerged=yes'.split('&'))
  188. def test_get_report_url(self):
  189. self.assertCountEqual(debbugs.get_report_url('debian', 123).split('?')[1].split('&'),
  190. 'bug=123&archived=False&mbox=no'.split('&'))