Left: | ||
Right: |
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(node, message): | |
Vasily Kuznetsov
2016/04/07 14:17:22
It seems that `repo` is essentially a list of chan
Felix Dahlke
2016/04/07 15:42:00
It's unfortunately not just a list, there are some
Vasily Kuznetsov
2016/04/07 21:16:49
Ok, yeah, I see, it does repo.url(). Then you'd ha
| |
22 mock_repo = mock.MagicMock() | |
23 mock_repo.__len__.return_value = 1 | |
24 mock_change = mock.MagicMock() | |
25 mock_change.rev.return_value = node | |
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, mock_server_proxy): | |
Vasily Kuznetsov
2016/04/07 14:17:22
Nit: this line is 80 characters long. PEP8 recomme
Felix Dahlke
2016/04/07 15:42:00
Done.
| |
36 messages = ["", "Issue #1337", "Tissue 1337", "Issue 13b"] | |
37 for message in messages: | |
38 node = 0 | |
Vasily Kuznetsov
2016/04/07 14:17:22
I think the `node` variable is a bit redundant her
Felix Dahlke
2016/04/07 15:42:00
Done.
| |
39 mock_repo = _create_mock_repo(node, message) | |
40 update_issues.hook(self.ui, mock_repo, node) | |
41 self.ui.warn.assert_called_once() | |
Vasily Kuznetsov
2016/04/07 14:17:22
Does this work for you? When I run the test it fai
Felix Dahlke
2016/04/07 15:42:00
Done.
I originally did reset the mocks. Then chec
| |
42 self.assertFalse(mock_server_proxy.called) | |
43 | |
44 @mock.patch("xmlrpclib.ServerProxy") | |
45 def test_noissue_commits_ignored(self, mock_server_proxy): | |
46 messages = ["Noissue", "noissue"] | |
47 for message in messages: | |
48 node = 0 | |
49 mock_repo = _create_mock_repo(node, message) | |
50 update_issues.hook(self.ui, mock_repo, node) | |
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): | |
Vasily Kuznetsov
2016/04/07 14:17:22
This also fails for me. Looks like the same proble
Felix Dahlke
2016/04/07 15:42:00
Done.
| |
56 server_proxy_instance = mock_server_proxy.return_value | |
57 messages = ["Issue 1337", "issue 1337"] | |
58 for message in messages: | |
59 node = 0 | |
60 mock_repo = _create_mock_repo(node, message) | |
61 update_issues.hook(self.ui, mock_repo, node) | |
62 self.assertFalse(self.ui.warn.called) | |
63 server_proxy_instance.ticket.update.assert_called_once() | |
64 self.assertEqual(server_proxy_instance.ticket.update.call_args[0][0], | |
65 1337) | |
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 node = 0 | |
71 mock_repo = _create_mock_repo(node, "Issue 1337, issue 2448") | |
72 update_issues.hook(self.ui, mock_repo, node) | |
73 self.assertFalse(self.ui.warn.called) | |
74 calls = server_proxy_instance.ticket.update.call_args_list | |
75 self.assertEqual(len(calls), 2) | |
76 self.assertEqual(calls[0][0][0], 1337) | |
77 self.assertEqual(calls[1][0][0], 2448) | |
78 | |
79 if __name__ == "__main__": | |
80 unittest.main() | |
OLD | NEW |