PageRenderTime 112ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/WebKitTools/Scripts/modules/bugzilla_unittest.py

https://github.com/weissms/owb-mirror
Python | 296 lines | 258 code | 11 blank | 27 comment | 3 complexity | ba874620f2f45a2bd745fd063e510220 MD5 | raw file
  1. # Copyright (C) 2009 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import unittest
  29. from modules.committers import CommitterList, Reviewer, Committer
  30. from modules.bugzilla import Bugzilla, BugzillaQueries, parse_bug_id
  31. from modules.outputcapture import OutputCapture
  32. from modules.BeautifulSoup import BeautifulSoup
  33. class MockBrowser(object):
  34. def open(self, url):
  35. pass
  36. def select_form(self, name):
  37. pass
  38. def __setitem__(self, key, value):
  39. pass
  40. def submit(self):
  41. pass
  42. class BugzillaTest(unittest.TestCase):
  43. _example_attachment = '''
  44. <attachment
  45. isobsolete="1"
  46. ispatch="1"
  47. isprivate="0"
  48. >
  49. <attachid>33721</attachid>
  50. <date>2009-07-29 10:23 PDT</date>
  51. <desc>Fixed whitespace issue</desc>
  52. <filename>patch</filename>
  53. <type>text/plain</type>
  54. <size>9719</size>
  55. <attacher>christian.plesner.hansen@gmail.com</attacher>
  56. <flag name="review"
  57. id="17931"
  58. status="+"
  59. setter="one@test.com"
  60. />
  61. <flag name="commit-queue"
  62. id="17932"
  63. status="+"
  64. setter="two@test.com"
  65. />
  66. </attachment>
  67. '''
  68. _expected_example_attachment_parsing = {
  69. 'bug_id' : 100,
  70. 'is_obsolete' : True,
  71. 'is_patch' : True,
  72. 'id' : 33721,
  73. 'url' : "https://bugs.webkit.org/attachment.cgi?id=33721",
  74. 'name' : "Fixed whitespace issue",
  75. 'type' : "text/plain",
  76. 'review' : '+',
  77. 'reviewer_email' : 'one@test.com',
  78. 'commit-queue' : '+',
  79. 'committer_email' : 'two@test.com',
  80. 'attacher_email' : 'christian.plesner.hansen@gmail.com',
  81. }
  82. def test_parse_bug_id(self):
  83. # FIXME: These would be all better as doctests
  84. bugs = Bugzilla()
  85. self.assertEquals(12345, parse_bug_id("http://webkit.org/b/12345"))
  86. self.assertEquals(12345, parse_bug_id("http://bugs.webkit.org/show_bug.cgi?id=12345"))
  87. self.assertEquals(12345, parse_bug_id(bugs.short_bug_url_for_bug_id(12345)))
  88. self.assertEquals(12345, parse_bug_id(bugs.bug_url_for_bug_id(12345)))
  89. self.assertEquals(12345, parse_bug_id(bugs.bug_url_for_bug_id(12345, xml=True)))
  90. # Our bug parser is super-fragile, but at least we're testing it.
  91. self.assertEquals(None, parse_bug_id("http://www.webkit.org/b/12345"))
  92. self.assertEquals(None, parse_bug_id("http://bugs.webkit.org/show_bug.cgi?ctype=xml&id=12345"))
  93. _example_bug = """
  94. <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
  95. <!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/bugzilla.dtd">
  96. <bugzilla version="3.2.3"
  97. urlbase="https://bugs.webkit.org/"
  98. maintainer="admin@webkit.org"
  99. exporter="eric@webkit.org"
  100. >
  101. <bug>
  102. <bug_id>32585</bug_id>
  103. <creation_ts>2009-12-15 15:17 PST</creation_ts>
  104. <short_desc>bug to test bugzilla-tool and commit-queue failures</short_desc>
  105. <delta_ts>2009-12-27 21:04:50 PST</delta_ts>
  106. <reporter_accessible>1</reporter_accessible>
  107. <cclist_accessible>1</cclist_accessible>
  108. <classification_id>1</classification_id>
  109. <classification>Unclassified</classification>
  110. <product>WebKit</product>
  111. <component>Tools / Tests</component>
  112. <version>528+ (Nightly build)</version>
  113. <rep_platform>PC</rep_platform>
  114. <op_sys>Mac OS X 10.5</op_sys>
  115. <bug_status>NEW</bug_status>
  116. <priority>P2</priority>
  117. <bug_severity>Normal</bug_severity>
  118. <target_milestone>---</target_milestone>
  119. <everconfirmed>1</everconfirmed>
  120. <reporter name="Eric Seidel">eric@webkit.org</reporter>
  121. <assigned_to name="Nobody">webkit-unassigned@lists.webkit.org</assigned_to>
  122. <cc>foo@bar.com</cc>
  123. <cc>example@example.com</cc>
  124. <long_desc isprivate="0">
  125. <who name="Eric Seidel">eric@webkit.org</who>
  126. <bug_when>2009-12-15 15:17:28 PST</bug_when>
  127. <thetext>bug to test bugzilla-tool and commit-queue failures
  128. Ignore this bug. Just for testing failure modes of bugzilla-tool and the commit-queue.</thetext>
  129. </long_desc>
  130. <attachment
  131. isobsolete="0"
  132. ispatch="1"
  133. isprivate="0"
  134. >
  135. <attachid>45548</attachid>
  136. <date>2009-12-27 23:51 PST</date>
  137. <desc>Patch</desc>
  138. <filename>bug-32585-20091228005112.patch</filename>
  139. <type>text/plain</type>
  140. <size>10882</size>
  141. <attacher>mjs@apple.com</attacher>
  142. <token>1261988248-dc51409e9c421a4358f365fa8bec8357</token>
  143. <data encoding="base64">SW5kZXg6IFdlYktpdC9tYWMvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09
  144. removed-because-it-was-really-long
  145. ZEZpbmlzaExvYWRXaXRoUmVhc29uOnJlYXNvbl07Cit9CisKIEBlbmQKIAogI2VuZGlmCg==
  146. </data>
  147. <flag name="review"
  148. id="27602"
  149. status="?"
  150. setter="mjs@apple.com"
  151. />
  152. </attachment>
  153. </bug>
  154. </bugzilla>
  155. """
  156. _expected_example_bug_parsing = {
  157. "id" : 32585,
  158. "title" : u"bug to test bugzilla-tool and commit-queue failures",
  159. "cc_emails" : ["foo@bar.com", "example@example.com"],
  160. "reporter_email" : "eric@webkit.org",
  161. "assigned_to_email" : "webkit-unassigned@lists.webkit.org",
  162. "attachments" : [{
  163. 'name': u'Patch',
  164. 'url': 'https://bugs.webkit.org/attachment.cgi?id=45548',
  165. 'is_obsolete': False,
  166. 'review': '?',
  167. 'is_patch': True,
  168. 'attacher_email': 'mjs@apple.com',
  169. 'bug_id': 32585,
  170. 'type': 'text/plain',
  171. 'id': 45548
  172. }],
  173. }
  174. def _assert_dictionaries_equal(self, actual, expected):
  175. # Make sure we aren't parsing more or less than we expect
  176. self.assertEquals(sorted(actual.keys()), sorted(expected.keys()))
  177. for key, expected_value in expected.items():
  178. self.assertEquals(actual[key], expected_value, ("Failure for key: %s: Actual='%s' Expected='%s'" % (key, actual[key], expected_value)))
  179. def test_bug_parsing(self):
  180. bug = Bugzilla()._parse_bug_page(self._example_bug)
  181. self._assert_dictionaries_equal(bug, self._expected_example_bug_parsing)
  182. # This could be combined into test_bug_parsing later if desired.
  183. def test_attachment_parsing(self):
  184. bugzilla = Bugzilla()
  185. soup = BeautifulSoup(self._example_attachment)
  186. attachment_element = soup.find("attachment")
  187. attachment = bugzilla._parse_attachment_element(attachment_element, self._expected_example_attachment_parsing['bug_id'])
  188. self.assertTrue(attachment)
  189. self._assert_dictionaries_equal(attachment, self._expected_example_attachment_parsing)
  190. _sample_attachment_detail_page = """
  191. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  192. "http://www.w3.org/TR/html4/loose.dtd">
  193. <html>
  194. <head>
  195. <title>
  196. Attachment 41073 Details for Bug 27314</title>
  197. <link rel="Top" href="https://bugs.webkit.org/">
  198. <link rel="Up" href="show_bug.cgi?id=27314">
  199. """
  200. def test_attachment_detail_bug_parsing(self):
  201. bugzilla = Bugzilla()
  202. self.assertEquals(27314, bugzilla._parse_bug_id_from_attachment_page(self._sample_attachment_detail_page))
  203. def test_add_cc_to_bug(self):
  204. bugzilla = Bugzilla()
  205. bugzilla.browser = MockBrowser()
  206. bugzilla.authenticate = lambda: None
  207. expected_stderr = "Adding ['adam@example.com'] to the CC list for bug 42\n"
  208. OutputCapture().assert_outputs(self, bugzilla.add_cc_to_bug, [42, ["adam@example.com"]], expected_stderr=expected_stderr)
  209. def test_flag_permission_rejection_message(self):
  210. bugzilla = Bugzilla()
  211. expected_messsage="""foo@foo.com does not have review permissions according to http://trac.webkit.org/browser/trunk/WebKitTools/Scripts/modules/committers.py.
  212. - If you do not have review rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags.
  213. - If you have review rights please correct the error in WebKitTools/Scripts/modules/committers.py by adding yourself to the file (no review needed). Due to bug 30084 the commit-queue will require a restart after your change. Please contact eseidel@chromium.org to request a commit-queue restart. After restart the commit-queue will correctly respect your review rights."""
  214. self.assertEqual(bugzilla._flag_permission_rejection_message("foo@foo.com", "review"), expected_messsage)
  215. class BugzillaQueriesTest(unittest.TestCase):
  216. _sample_request_page = """
  217. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  218. "http://www.w3.org/TR/html4/loose.dtd">
  219. <html>
  220. <head>
  221. <title>Request Queue</title>
  222. </head>
  223. <body>
  224. <h3>Flag: review</h3>
  225. <table class="requests" cellspacing="0" cellpadding="4" border="1">
  226. <tr>
  227. <th>Requester</th>
  228. <th>Requestee</th>
  229. <th>Bug</th>
  230. <th>Attachment</th>
  231. <th>Created</th>
  232. </tr>
  233. <tr>
  234. <td>Shinichiro Hamaji &lt;hamaji&#64;chromium.org&gt;</td>
  235. <td></td>
  236. <td><a href="show_bug.cgi?id=30015">30015: text-transform:capitalize is failing in CSS2.1 test suite</a></td>
  237. <td><a href="attachment.cgi?id=40511&amp;action=review">
  238. 40511: Patch v0</a></td>
  239. <td>2009-10-02 04:58 PST</td>
  240. </tr>
  241. <tr>
  242. <td>Zan Dobersek &lt;zandobersek&#64;gmail.com&gt;</td>
  243. <td></td>
  244. <td><a href="show_bug.cgi?id=26304">26304: [GTK] Add controls for playing html5 video.</a></td>
  245. <td><a href="attachment.cgi?id=40722&amp;action=review">
  246. 40722: Media controls, the simple approach</a></td>
  247. <td>2009-10-06 09:13 PST</td>
  248. </tr>
  249. <tr>
  250. <td>Zan Dobersek &lt;zandobersek&#64;gmail.com&gt;</td>
  251. <td></td>
  252. <td><a href="show_bug.cgi?id=26304">26304: [GTK] Add controls for playing html5 video.</a></td>
  253. <td><a href="attachment.cgi?id=40723&amp;action=review">
  254. 40723: Adjust the media slider thumb size</a></td>
  255. <td>2009-10-06 09:15 PST</td>
  256. </tr>
  257. </table>
  258. </body>
  259. </html>
  260. """
  261. def test_request_page_parsing(self):
  262. queries = BugzillaQueries(None)
  263. self.assertEquals([40511, 40722, 40723], queries._parse_attachment_ids_request_query(self._sample_request_page))
  264. if __name__ == '__main__':
  265. unittest.main()