def test_commit_queue_flag(self): bugzilla = Bugzilla() bugzilla.committers = CommitterList(reviewers=[Reviewer("WebKit Reviewer", "*****@*****.**")], committers=[Committer("WebKit Committer", "*****@*****.**")], contributors=[Contributor("WebKit Contributor", "*****@*****.**")]) def assert_commit_queue_flag(commit_flag, expected, username=None): bugzilla.username = username capture = OutputCapture() capture.capture_output() try: self.assertEqual(bugzilla._commit_queue_flag(commit_flag), expected) finally: capture.restore_output() assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_nothing, expected='X', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_commit_queue, expected='?', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_landing, expected='?', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_nothing, expected='X', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_commit_queue, expected='?', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_landing, expected='?', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_nothing, expected='X', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_commit_queue, expected='?', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_landing, expected='+', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_nothing, expected='X', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_commit_queue, expected='?', username='******') assert_commit_queue_flag(commit_flag=CommitQueueFlag.mark_for_landing, expected='+', username='******')
def test_attachment_parsing(self): bugzilla = Bugzilla() soup = BeautifulSoup(self._example_attachment) attachment_element = soup.find("attachment") attachment = bugzilla._parse_attachment_element(attachment_element, self._expected_example_attachment_parsing['bug_id']) self.assertTrue(attachment) self._assert_dictionaries_equal(attachment, self._expected_example_attachment_parsing)
def test_parse_bugs_from_xml(self): bugzilla = Bugzilla() bugs = bugzilla._parse_bugs_from_xml(self._sample_multi_bug_xml) self.assertEqual(len(bugs), 2) self.assertEqual(bugs[0].id(), self._expected_example_bug_parsing['id']) bugs = bugzilla._parse_bugs_from_xml("") self.assertEqual(len(bugs), 0)
def test__check_create_bug_response(self): bugzilla = Bugzilla() title_html_bugzilla_323 = "<title>Bug 101640 Submitted</title>" self.assertEqual(bugzilla._check_create_bug_response(title_html_bugzilla_323), '101640') title_html_bugzilla_425 = "<title>Bug 101640 Submitted – Testing webkit-patch again</title>" self.assertEqual(bugzilla._check_create_bug_response(title_html_bugzilla_425), '101640')
def test_filename_for_upload(self): bugzilla = Bugzilla() mock_file = Mock() mock_file.name = "foo" self.assertEqual(bugzilla._filename_for_upload(mock_file, 1234), 'foo') mock_timestamp = lambda: "now" filename = bugzilla._filename_for_upload(StringIO(), 1234, extension="patch", timestamp=mock_timestamp) self.assertEqual(filename, "bug-1234-now.patch")
def test_file_object_for_upload(self): bugzilla = Bugzilla() file_object = StringIO() unicode_tor = u"WebKit \u2661 Tor Arne Vestb\u00F8!" utf8_tor = unicode_tor.encode("utf-8") self.assertEqual(bugzilla._file_object_for_upload(file_object), file_object) self.assertEqual(bugzilla._file_object_for_upload(utf8_tor).read(), utf8_tor) self.assertEqual(bugzilla._file_object_for_upload(unicode_tor).read(), utf8_tor)
def test_parse_bug_id(self): # Test that we can parse the urls we produce. bugs = Bugzilla() self.assertEqual( 12345, urls.parse_bug_id(bugs.short_bug_url_for_bug_id(12345))) self.assertEqual(12345, urls.parse_bug_id(bugs.bug_url_for_bug_id(12345))) self.assertEqual( 12345, urls.parse_bug_id(bugs.bug_url_for_bug_id(12345, xml=True)))
def test_add_cc_to_bug(self): bugzilla = Bugzilla() bugzilla.browser = MockBrowser() bugzilla.authenticate = lambda: None with OutputCapture(level=logging.INFO) as captured: bugzilla.add_cc_to_bug(42, ['*****@*****.**']) self.assertEqual( captured.root.log.getvalue(), "Adding ['*****@*****.**'] to the CC list for bug 42\n")
def test_add_cc_to_bug(self): bugzilla = Bugzilla() bugzilla.browser = MockBrowser() bugzilla.authenticate = lambda: None expected_logs = "Adding ['*****@*****.**'] to the CC list for bug 42\n" OutputCapture().assert_outputs(self, bugzilla.add_cc_to_bug, [42, ["*****@*****.**"]], expected_logs=expected_logs)
def test__parse_attachment_id_from_add_patch_to_bug_response(self): bugzilla = Bugzilla() title_html = b'<title>Attachment 317591 added to Bug 175247</title>' self.assertEqual(bugzilla._parse_attachment_id_from_add_patch_to_bug_response(title_html), b'317591') title_html = b'<title>Attachment 317591; malformed</title>' self.assertEqual(bugzilla._parse_attachment_id_from_add_patch_to_bug_response(title_html), None) title_html = b'<title>Attachment A added to Bug 175247</title>' self.assertEqual(bugzilla._parse_attachment_id_from_add_patch_to_bug_response(title_html), None)
def _assert_reopen(self, item_names=None, selected_index=None, extra_logs=None): bugzilla = Bugzilla() bugzilla.browser = MockBrowser() bugzilla.authenticate = lambda: None mock_find_control = self._mock_find_control(item_names, selected_index) bugzilla.browser.find_control = mock_find_control expected_logs = "Re-opening bug 42\n['comment']\n" if extra_logs: expected_logs += extra_logs OutputCapture().assert_outputs(self, bugzilla.reopen_bug, [42, ["comment"]], expected_logs=expected_logs)
def _assert_reopen(self, item_names=None, selected_index=None, extra_logs=None): bugzilla = Bugzilla() bugzilla.browser = MockBrowser() bugzilla.authenticate = lambda: None mock_find_control = self._mock_find_control(item_names, selected_index) bugzilla.browser.find_control = mock_find_control with OutputCapture(level=logging.INFO) as captured: bugzilla.reopen_bug(42, ['comment']) self.assertEqual( captured.root.log.getvalue(), "Re-opening bug 42\n['comment']\n" + (extra_logs or ''))
def test_url_creation(self): # FIXME: These would be all better as doctests bugs = Bugzilla() self.assertIsNone(bugs.bug_url_for_bug_id(None)) self.assertIsNone(bugs.short_bug_url_for_bug_id(None)) self.assertIsNone(bugs.attachment_url_for_id(None))
def test_attachment_detail_bug_parsing(self): bugzilla = Bugzilla() self.assertEqual( 27314, bugzilla._parse_bug_id_from_attachment_page( self._sample_attachment_detail_page))
def test_parse_bug_dictionary_from_xml(self): bug = Bugzilla()._parse_bug_dictionary_from_xml(self._single_bug_xml) self._assert_dictionaries_equal(bug, self._expected_example_bug_parsing)
def test_parse_bug_dictionary_from_xml_for_not_permitted_bug(self): bug = Bugzilla()._parse_bug_dictionary_from_xml( self._single_not_permitted_bug_xml) self.assertEqual(bug, {})