test_debbugs.py 13 KB

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