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

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

Issue 30048555: Issue 7334 - Remove handling of "Fixes XXXX - ..." commit messages (Closed) Base URL: https://hg.adblockplus.org/sitescripts
Left Patch Set: Created April 18, 2019, 3:48 p.m.
Right Patch Set: Address review comments on PS1 Created May 14, 2019, 10:22 a.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/bin/update_issues.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-present eyeo GmbH 2 # Copyright (C) 2006-present 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 """Test Mercurial Trac integration hook.""" 16 """Test Mercurial Trac integration hook."""
17 17
18 import mock 18 import mock
19 import pytest 19 import pytest
20 20
21 import sitescripts.hg.bin.update_issues as update_issues 21 import sitescripts.hg.bin.update_issues as update_issues
22 22
23 COMMIT_HASH = '000011112222'
23 24
24 class RepoMock(list): 25
25 """Very simple mock of a Mercurial repository.""" 26 class MercurialRepositoryMock(list):
mathias 2019/05/14 09:32:02 If you call the class "MercurialRepositoryMock" th
Vasily Kuznetsov 2019/05/14 10:29:00 Done.
26 27
27 def __init__(self, message): 28 def __init__(self, message):
28 change_mock = mock.MagicMock() 29 change_mock = mock.MagicMock()
29 change_mock.rev.return_value = 0 30 change_mock.rev.return_value = 0
30 change_mock.hex.return_value = '000011112222' 31 change_mock.hex.return_value = COMMIT_HASH
mathias 2019/05/14 09:32:02 This magic number string should be a constant.
Vasily Kuznetsov 2019/05/14 10:29:00 Done.
31 change_mock.description.return_value = message 32 change_mock.description.return_value = message
32 list.__init__(self, [change_mock]) 33 list.__init__(self, [change_mock])
33 34
34 def url(self): 35 def url(self):
35 return 'repo/mock' 36 return 'repo/mock'
36 37
37 38
38 @pytest.fixture 39 @pytest.fixture
39 def server_proxy_mock(mocker): 40 def server_proxy_mock(mocker):
40 return mocker.patch('xmlrpclib.ServerProxy') 41 return mocker.patch('xmlrpclib.ServerProxy')
41 42
42 43
43 @pytest.fixture 44 @pytest.fixture
44 def ui_mock(): 45 def ui_mock():
45 return mock.MagicMock() 46 return mock.MagicMock()
46 47
47 48
48 @pytest.mark.parametrize('message', [ 49 @pytest.mark.parametrize('message', [
49 '', 'Issue #1337', 'Tissue 1337', 'Issue 13b', 50 '', 'Issue #1337', 'Tissue 1337', 'Issue 13b',
50 ]) 51 ])
51 def test_invalid_message_format(message, ui_mock, server_proxy_mock): 52 def test_invalid_message_format(message, ui_mock, server_proxy_mock):
52 """Check that commits with invalid messages are ignored with a warning.""" 53 """Check that commits with invalid messages are ignored with a warning."""
53 repo_mock = RepoMock(message) 54 repo_mock = MercurialRepositoryMock(message)
54 update_issues.hook(ui_mock, repo_mock, 0) 55 update_issues.hook(ui_mock, repo_mock, 0)
55 ui_mock.warn.assert_called_once() 56 ui_mock.warn.assert_called_once()
56 assert not server_proxy_mock.called 57 assert not server_proxy_mock.called
57 58
58 59
59 @pytest.mark.parametrize('message', ['Noissue - foobar', 'noissue']) 60 @pytest.mark.parametrize('message', ['Noissue - foobar', 'noissue'])
60 def test_noissue(message, ui_mock, server_proxy_mock): 61 def test_noissue(message, ui_mock, server_proxy_mock):
61 """Check that noissue commits are ignored without warning.""" 62 """Check that noissue commits are ignored without warning."""
62 repo_mock = RepoMock(message) 63 repo_mock = MercurialRepositoryMock(message)
63 update_issues.hook(ui_mock, repo_mock, 0) 64 update_issues.hook(ui_mock, repo_mock, 0)
64 assert not ui_mock.warn.called 65 assert not ui_mock.warn.called
65 assert not server_proxy_mock.called 66 assert not server_proxy_mock.called
66 67
67 68
68 @pytest.mark.parametrize('message', ['Issue 1337 - foo', 'issue 1337 - foo']) 69 @pytest.mark.parametrize('message', ['Issue 1337 - foo', 'issue 1337 - foo'])
69 def test_single_issue(message, ui_mock, server_proxy_mock): 70 def test_single_issue(message, ui_mock, server_proxy_mock):
70 """Check that a commit referencing a single issue gets linked.""" 71 """Check that a commit referencing a single issue gets linked."""
71 server_proxy = server_proxy_mock.return_value 72 server_proxy = server_proxy_mock.return_value
72 repo_mock = RepoMock(message) 73 repo_mock = MercurialRepositoryMock(message)
73 update_issues.hook(ui_mock, repo_mock, 0) 74 update_issues.hook(ui_mock, repo_mock, 0)
74 assert not ui_mock.warn.called 75 assert not ui_mock.warn.called
75 server_proxy.ticket.update.assert_called_once() 76 server_proxy.ticket.update.assert_called_once()
76 call = server_proxy.ticket.update.call_args 77 call = server_proxy.ticket.update.call_args
77 assert call[0][0] == 1337 78 assert call[0][0] == 1337
78 comment = call[0][1] 79 comment = call[0][1]
79 assert comment.startswith('A commit referencing this issue has landed') 80 assert comment.startswith('A commit referencing this issue has landed')
80 assert '000011112222' in comment 81 assert COMMIT_HASH in comment
mathias 2019/05/14 09:32:02 This magic number string should be a constant.
Vasily Kuznetsov 2019/05/14 10:29:00 Done.
81 assert comment.endswith('- foo]') 82 assert comment.endswith('- foo]')
82 83
83 84
84 def test_multiple_issues(ui_mock, server_proxy_mock): 85 def test_multiple_issues(ui_mock, server_proxy_mock):
85 """Check that a commit referencing two issues gets linked twice.""" 86 """Check that a commit referencing two issues gets linked twice."""
86 server_proxy = server_proxy_mock.return_value 87 server_proxy = server_proxy_mock.return_value
87 repo_mock = RepoMock('Issue 1337, issue 2448') 88 repo_mock = MercurialRepositoryMock('Issue 1337, issue 2448')
88 update_issues.hook(ui_mock, repo_mock, 0) 89 update_issues.hook(ui_mock, repo_mock, 0)
89 assert not ui_mock.warn.called 90 assert not ui_mock.warn.called
90 calls = server_proxy.ticket.update.call_args_list 91 calls = server_proxy.ticket.update.call_args_list
91 assert len(calls) == 2 92 assert len(calls) == 2
92 assert calls[0][0][0] == 1337 93 assert calls[0][0][0] == 1337
93 assert calls[1][0][0] == 2448 94 assert calls[1][0][0] == 2448
LEFTRIGHT

Powered by Google App Engine
This is Rietveld