def test_process_log_entry_specified_project(self): handler = self._make_handler() issue = monorail_client.Issue(1234, []) self.monorail_client.get_issue.return_value = issue handler.ProcessLogEntry(self._make_commit('Message\nBug: bar:1234')) self.logger.info.assert_called_once_with( 'Processing commit %s : bugs %s', 'abcdef', "{'bar': [1234]}") self.monorail_client.get_issue.assert_called_once_with('bar', 1234) self.monorail_client.update_issue.assert_called_once_with( 'bar', issue, True) self.assertEqual( 'The following revision refers to this bug:\n' ' https://example.googlesource.com/foo/+/abcdef\n\n' 'commit abcdef\n' 'Author: Author <*****@*****.**>\n' 'Date: Sun Oct 10 10:10:10 2010\n\n' 'Message\n' 'Bug: bar:1234\n' '[modify] https://example.googlesource.com/foo/+/abcdef/modified/file\n' '[add] https://example.googlesource.com/foo/+/abcdef/added/file\n' '[delete] https://example.googlesource.com/foo/+/123456/deleted/file\n', issue.comment)
def test_process_log_entry_shorten_links(self): handler = self._make_handler(shorten_links=True) issue = monorail_client.Issue(1234, []) self.monorail_client.get_issue.return_value = issue handler.ProcessLogEntry(self._make_commit('Message\nBug: 1234')) self.logger.info.assert_called_once_with( 'Processing commit %s : bugs %s', 'abcdef', "{'foo': [1234]}") self.monorail_client.get_issue.assert_called_once_with('foo', 1234) self.monorail_client.update_issue.assert_called_once_with( 'foo', issue, True) self.assertEqual( 'The following revision refers to this bug:\n' ' https://example.googlesource.com/foo/+/abcdef\n\n' 'commit abcdef\n' 'Author: Author <*****@*****.**>\n' 'Date: Sun Oct 10 10:10:10 2010\n\n' 'Message\n' 'Bug: 1234\n' '[modify] https://crrev.com/abcdef/modified/file\n' '[add] https://crrev.com/abcdef/added/file\n' '[delete] https://crrev.com/123456/deleted/file\n', issue.comment) self.assertEqual( 1, bugdroid.BugdroidGitPollerHandler.bug_comments_metric.get({ 'project': 'foo', 'status': 'success' }))
def test_process_log_entry_no_mstone(self, mock_get_mstone): handler = self._make_handler() mock_get_mstone.return_value = None issue = monorail_client.Issue(1234, ['merge-approved-baz']) self.monorail_client.get_issue.return_value = issue handler.ProcessLogEntry(self._make_commit('Message\nBug: 1234')) self.assertTrue(issue.has_label('merge-approved-baz'))
def test_process_log_entry_approved_label(self): handler = self._make_handler(issues_labels=[ repo_config_pb2.Pair(key='approved', value='My-Label'), ]) issue = monorail_client.Issue(1234, ['My-Label']) self.monorail_client.get_issue.return_value = issue handler.ProcessLogEntry(self._make_commit('Message\nBug: 1234')) self.assertTrue(issue.has_label('-My-Label'))
def test_update_issue_add_label(self): issue = monorail_client.Issue(123, []) issue.add_label('one') self.client.update_issue('foo', issue) self.insert.assert_called_once_with( projectId='foo', issueId=123, sendEmail=True, body={ 'id': 123, 'updates': {'labels': ['one']}, })
def test_update_issue_remove_label(self): issue = monorail_client.Issue(123, ['one', 'two']) issue.remove_label('two') self.assertFalse(issue.has_label('two')) self.client.update_issue('foo', issue) self.insert.assert_called_once_with( projectId='foo', issueId=123, sendEmail=True, body={ 'id': 123, 'updates': {'labels': ['-two']}, })
def test_update_issue_comment(self): issue = monorail_client.Issue(123, []) issue.set_comment('hello') self.client.update_issue('foo', issue) self.insert.assert_called_once_with( projectId='foo', issueId=123, sendEmail=True, body={ 'id': 123, 'updates': {}, 'content': 'hello', })
def test_process_log_entry_private_bugs(self): handler = self._make_handler(public_bugs=False) issue = monorail_client.Issue(1234, []) self.monorail_client.get_issue.return_value = issue handler.ProcessLogEntry(self._make_commit('Message\nBug: 1234')) self.logger.info.assert_called_once_with( 'Processing commit %s : bugs %s', 'abcdef', "{'foo': [1234]}") self.monorail_client.get_issue.assert_called_once_with('foo', 1234) self.monorail_client.update_issue.assert_called_once_with( 'foo', issue, True) self.assertEqual( 'The following revision refers to this bug:\n' ' https://example.googlesource.com/foo/+/abcdef\n\n' 'commit abcdef\n' 'Author: Author <*****@*****.**>\n' 'Date: Sun Oct 10 10:10:10 2010\n', issue.comment)
def test_process_log_entry_test_mode(self): handler = self._make_handler(test_mode=True) issue = monorail_client.Issue(1234, []) self.monorail_client.get_issue.return_value = issue handler.ProcessLogEntry(self._make_commit('Message\nBug: 1234')) self.logger.info.assert_called_once_with( 'Processing commit %s : bugs %s', 'abcdef', "{'foo': [1234]}") self.monorail_client.get_issue.assert_called_once_with('foo', 1234) self.assertFalse(self.monorail_client.update_issue.called) self.assertEqual( 1, bugdroid.BugdroidGitPollerHandler.bug_comments_metric.get({ 'project': 'foo', 'status': 'success' }))
def test_process_log_entry_update_failure(self): handler = self._make_handler() class MyException(Exception): pass issue = monorail_client.Issue(1234, []) self.monorail_client.get_issue.return_value = issue self.monorail_client.update_issue.side_effect = MyException with self.assertRaises(MyException): handler.ProcessLogEntry(self._make_commit('Message\nBug: 1234')) self.assertEqual( 1, bugdroid.BugdroidGitPollerHandler.bug_comments_metric.get({ 'project': 'foo', 'status': 'failure' }))
def test_unicode_decode_error(self, mock_debug): http = self.insert.return_value http.postproc.side_effect = UnicodeDecodeError('', '', 1, 2, '') # The real Http.execute calls postproc. Postproc calls str.decode which # sometimes raises a UnicodeDecodeError. We make our postproc raise that # UnicodeDecodeError by setting the side_effect above. # monorail_client monkey-patches the postproc method to catch that exception # and log it. def fake_execute(*_args, **_kwargs): # This calls the wrapped function, which calls the original one we set # the side_effect on above. http.postproc({'foo': 'bar'}, 'blah blah') http.execute.side_effect = fake_execute issue = monorail_client.Issue(123, []) issue.set_comment('hello') with self.assertRaises(UnicodeDecodeError): self.client.update_issue('foo', issue) mock_debug.assert_called_once_with( 'Error decoding UTF-8 HTTP response. Response headers:\n%r\n' 'Response body:\n%r', {'foo': 'bar'}, 'blah blah')
def test_update_issue_remove_non_existing_label(self): issue = monorail_client.Issue(123, ['one', 'two']) issue.remove_label('three') self.client.update_issue('foo', issue) self.assertFalse(self.insert.called)
def test_update_issue_add_existing_label(self): issue = monorail_client.Issue(123, ['one']) issue.add_label('one') self.client.update_issue('foo', issue) self.assertFalse(self.insert.called)
def test_update_not_dirty_issue(self): issue = monorail_client.Issue(123, []) self.client.update_issue('foo', issue) self.assertFalse(self.insert.called)