OLD | NEW |
(Empty) | |
| 1 # This file is part of the Adblock Plus web scripts, |
| 2 # Copyright (C) 2006-2016 Eyeo GmbH |
| 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. |
| 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. |
| 12 # |
| 13 # You should have received a copy of the GNU General Public License |
| 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
| 16 import mock |
| 17 import unittest |
| 18 |
| 19 import sitescripts.hg.bin.update_issues as update_issues |
| 20 |
| 21 def _create_mock_repo(message): |
| 22 mock_repo = mock.MagicMock() |
| 23 mock_repo.__len__.return_value = 1 |
| 24 mock_change = mock.MagicMock() |
| 25 mock_change.rev.return_value = 0 |
| 26 mock_change.description.return_value = message |
| 27 mock_repo.__getitem__.return_value = mock_change |
| 28 return mock_repo |
| 29 |
| 30 class TestUpdateIssues(unittest.TestCase): |
| 31 def setUp(self): |
| 32 self.ui = mock.Mock() |
| 33 |
| 34 @mock.patch("xmlrpclib.ServerProxy") |
| 35 def test_commits_with_invalid_message_format_ignored(self, |
| 36 mock_server_proxy): |
| 37 messages = ["", "Issue #1337", "Tissue 1337", "Issue 13b"] |
| 38 for message in messages: |
| 39 mock_repo = _create_mock_repo(message) |
| 40 update_issues.hook(self.ui, mock_repo, 0) |
| 41 self.ui.warn.assert_called_once() |
| 42 self.assertFalse(mock_server_proxy.called) |
| 43 self.ui.warn.reset_mock() |
| 44 |
| 45 @mock.patch("xmlrpclib.ServerProxy") |
| 46 def test_noissue_commits_ignored(self, mock_server_proxy): |
| 47 messages = ["Noissue", "noissue"] |
| 48 for message in messages: |
| 49 mock_repo = _create_mock_repo(message) |
| 50 update_issues.hook(self.ui, mock_repo, 0) |
| 51 self.assertFalse(self.ui.warn.called) |
| 52 self.assertFalse(mock_server_proxy.called) |
| 53 |
| 54 @mock.patch("xmlrpclib.ServerProxy") |
| 55 def test_single_issue_referenced(self, mock_server_proxy): |
| 56 server_proxy_instance = mock_server_proxy.return_value |
| 57 messages = ["Issue 1337", "issue 1337"] |
| 58 for message in messages: |
| 59 mock_repo = _create_mock_repo(message) |
| 60 update_issues.hook(self.ui, mock_repo, 0) |
| 61 self.assertFalse(self.ui.warn.called) |
| 62 server_proxy_instance.ticket.update.assert_called_once() |
| 63 self.assertEqual(server_proxy_instance.ticket.update.call_args[0][0], |
| 64 1337) |
| 65 server_proxy_instance.reset_mock() |
| 66 |
| 67 @mock.patch("xmlrpclib.ServerProxy") |
| 68 def test_multiple_issues_referenced(self, mock_server_proxy): |
| 69 server_proxy_instance = mock_server_proxy.return_value |
| 70 mock_repo = _create_mock_repo("Issue 1337, issue 2448") |
| 71 update_issues.hook(self.ui, mock_repo, 0) |
| 72 self.assertFalse(self.ui.warn.called) |
| 73 calls = server_proxy_instance.ticket.update.call_args_list |
| 74 self.assertEqual(len(calls), 2) |
| 75 self.assertEqual(calls[0][0][0], 1337) |
| 76 self.assertEqual(calls[1][0][0], 2448) |
| 77 |
| 78 if __name__ == "__main__": |
| 79 unittest.main() |
OLD | NEW |