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

Unified Diff: sitescripts/hg/test/update_issues.py

Issue 29339548: Issue 3894 - Add tests for the update_issues hook (Closed)
Patch Set: Created April 7, 2016, 9:51 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/hg/test/__init__.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/hg/test/update_issues.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/sitescripts/hg/test/update_issues.py
@@ -0,0 +1,80 @@
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2006-2016 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import mock
+import unittest
+
+import sitescripts.hg.bin.update_issues as update_issues
+
+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
+ mock_repo = mock.MagicMock()
+ mock_repo.__len__.return_value = 1
+ mock_change = mock.MagicMock()
+ mock_change.rev.return_value = node
+ mock_change.description.return_value = message
+ mock_repo.__getitem__.return_value = mock_change
+ return mock_repo
+
+class TestUpdateIssues(unittest.TestCase):
+ def setUp(self):
+ self.ui = mock.Mock()
+
+ @mock.patch("xmlrpclib.ServerProxy")
+ 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.
+ messages = ["", "Issue #1337", "Tissue 1337", "Issue 13b"]
+ for message in messages:
+ 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.
+ mock_repo = _create_mock_repo(node, message)
+ update_issues.hook(self.ui, mock_repo, node)
+ 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
+ self.assertFalse(mock_server_proxy.called)
+
+ @mock.patch("xmlrpclib.ServerProxy")
+ def test_noissue_commits_ignored(self, mock_server_proxy):
+ messages = ["Noissue", "noissue"]
+ for message in messages:
+ node = 0
+ mock_repo = _create_mock_repo(node, message)
+ update_issues.hook(self.ui, mock_repo, node)
+ self.assertFalse(self.ui.warn.called)
+ self.assertFalse(mock_server_proxy.called)
+
+ @mock.patch("xmlrpclib.ServerProxy")
+ 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.
+ server_proxy_instance = mock_server_proxy.return_value
+ messages = ["Issue 1337", "issue 1337"]
+ for message in messages:
+ node = 0
+ mock_repo = _create_mock_repo(node, message)
+ update_issues.hook(self.ui, mock_repo, node)
+ self.assertFalse(self.ui.warn.called)
+ server_proxy_instance.ticket.update.assert_called_once()
+ self.assertEqual(server_proxy_instance.ticket.update.call_args[0][0],
+ 1337)
+
+ @mock.patch("xmlrpclib.ServerProxy")
+ def test_multiple_issues_referenced(self, mock_server_proxy):
+ server_proxy_instance = mock_server_proxy.return_value
+ node = 0
+ mock_repo = _create_mock_repo(node, "Issue 1337, issue 2448")
+ update_issues.hook(self.ui, mock_repo, node)
+ self.assertFalse(self.ui.warn.called)
+ calls = server_proxy_instance.ticket.update.call_args_list
+ self.assertEqual(len(calls), 2)
+ self.assertEqual(calls[0][0][0], 1337)
+ self.assertEqual(calls[1][0][0], 2448)
+
+if __name__ == "__main__":
+ unittest.main()
« no previous file with comments | « sitescripts/hg/test/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld