Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: sitescripts/hg/test/update_issues.py

Issue 29339548: Issue 3894 - Add tests for the update_issues hook (Closed)
Left Patch Set: Created April 7, 2016, 9:51 a.m.
Right Patch Set: Addressed Vasily's comments Created April 7, 2016, 3:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/hg/test/__init__.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 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 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 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/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import mock 16 import mock
17 import unittest 17 import unittest
18 18
19 import sitescripts.hg.bin.update_issues as update_issues 19 import sitescripts.hg.bin.update_issues as update_issues
20 20
21 def _create_mock_repo(node, message): 21 def _create_mock_repo(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() 22 mock_repo = mock.MagicMock()
23 mock_repo.__len__.return_value = 1 23 mock_repo.__len__.return_value = 1
24 mock_change = mock.MagicMock() 24 mock_change = mock.MagicMock()
25 mock_change.rev.return_value = node 25 mock_change.rev.return_value = 0
26 mock_change.description.return_value = message 26 mock_change.description.return_value = message
27 mock_repo.__getitem__.return_value = mock_change 27 mock_repo.__getitem__.return_value = mock_change
28 return mock_repo 28 return mock_repo
29 29
30 class TestUpdateIssues(unittest.TestCase): 30 class TestUpdateIssues(unittest.TestCase):
31 def setUp(self): 31 def setUp(self):
32 self.ui = mock.Mock() 32 self.ui = mock.Mock()
33 33
34 @mock.patch("xmlrpclib.ServerProxy") 34 @mock.patch("xmlrpclib.ServerProxy")
35 def test_commits_with_invalid_message_format_ignored(self, mock_server_proxy): 35 def test_commits_with_invalid_message_format_ignored(self,
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 mock_server_proxy):
36 messages = ["", "Issue #1337", "Tissue 1337", "Issue 13b"] 37 messages = ["", "Issue #1337", "Tissue 1337", "Issue 13b"]
37 for message in messages: 38 for message in messages:
38 node = 0 39 mock_repo = _create_mock_repo(message)
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, 0)
40 update_issues.hook(self.ui, mock_repo, node)
41 self.ui.warn.assert_called_once() 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) 42 self.assertFalse(mock_server_proxy.called)
43 self.ui.warn.reset_mock()
43 44
44 @mock.patch("xmlrpclib.ServerProxy") 45 @mock.patch("xmlrpclib.ServerProxy")
45 def test_noissue_commits_ignored(self, mock_server_proxy): 46 def test_noissue_commits_ignored(self, mock_server_proxy):
46 messages = ["Noissue", "noissue"] 47 messages = ["Noissue", "noissue"]
47 for message in messages: 48 for message in messages:
48 node = 0 49 mock_repo = _create_mock_repo(message)
49 mock_repo = _create_mock_repo(node, message) 50 update_issues.hook(self.ui, mock_repo, 0)
50 update_issues.hook(self.ui, mock_repo, node)
51 self.assertFalse(self.ui.warn.called) 51 self.assertFalse(self.ui.warn.called)
52 self.assertFalse(mock_server_proxy.called) 52 self.assertFalse(mock_server_proxy.called)
53 53
54 @mock.patch("xmlrpclib.ServerProxy") 54 @mock.patch("xmlrpclib.ServerProxy")
55 def test_single_issue_referenced(self, mock_server_proxy): 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 56 server_proxy_instance = mock_server_proxy.return_value
57 messages = ["Issue 1337", "issue 1337"] 57 messages = ["Issue 1337", "issue 1337"]
58 for message in messages: 58 for message in messages:
59 node = 0 59 mock_repo = _create_mock_repo(message)
60 mock_repo = _create_mock_repo(node, message) 60 update_issues.hook(self.ui, mock_repo, 0)
61 update_issues.hook(self.ui, mock_repo, node)
62 self.assertFalse(self.ui.warn.called) 61 self.assertFalse(self.ui.warn.called)
63 server_proxy_instance.ticket.update.assert_called_once() 62 server_proxy_instance.ticket.update.assert_called_once()
64 self.assertEqual(server_proxy_instance.ticket.update.call_args[0][0], 63 self.assertEqual(server_proxy_instance.ticket.update.call_args[0][0],
65 1337) 64 1337)
65 server_proxy_instance.reset_mock()
66 66
67 @mock.patch("xmlrpclib.ServerProxy") 67 @mock.patch("xmlrpclib.ServerProxy")
68 def test_multiple_issues_referenced(self, mock_server_proxy): 68 def test_multiple_issues_referenced(self, mock_server_proxy):
69 server_proxy_instance = mock_server_proxy.return_value 69 server_proxy_instance = mock_server_proxy.return_value
70 node = 0 70 mock_repo = _create_mock_repo("Issue 1337, issue 2448")
71 mock_repo = _create_mock_repo(node, "Issue 1337, issue 2448") 71 update_issues.hook(self.ui, mock_repo, 0)
72 update_issues.hook(self.ui, mock_repo, node)
73 self.assertFalse(self.ui.warn.called) 72 self.assertFalse(self.ui.warn.called)
74 calls = server_proxy_instance.ticket.update.call_args_list 73 calls = server_proxy_instance.ticket.update.call_args_list
75 self.assertEqual(len(calls), 2) 74 self.assertEqual(len(calls), 2)
76 self.assertEqual(calls[0][0][0], 1337) 75 self.assertEqual(calls[0][0][0], 1337)
77 self.assertEqual(calls[1][0][0], 2448) 76 self.assertEqual(calls[1][0][0], 2448)
78 77
79 if __name__ == "__main__": 78 if __name__ == "__main__":
80 unittest.main() 79 unittest.main()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld