| LEFT | RIGHT | 
|---|
| 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 | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 49     """Base class for hook tests that prepares the environment.""" | 49     """Base class for hook tests that prepares the environment.""" | 
| 50 | 50 | 
| 51     def _patchWith(self, target, return_value): | 51     def _patchWith(self, target, return_value): | 
| 52         patcher = mock.patch(target, return_value=return_value) | 52         patcher = mock.patch(target, return_value=return_value) | 
| 53         patcher.start() | 53         patcher.start() | 
| 54         self.addCleanup(patcher.stop) | 54         self.addCleanup(patcher.stop) | 
| 55 | 55 | 
| 56     def _create_mock_milestone_multicall(self): | 56     def _create_mock_milestone_multicall(self): | 
| 57         ret = [] | 57         ret = [] | 
| 58         multicall = mock.Mock(return_value=ret) | 58         multicall = mock.Mock(return_value=ret) | 
| 59         multicall.ticket.milestone.get = lambda id: ret.append(MILESTONES[id]) | 59         multicall.ticket.milestone.get = lambda i: ret.append(MILESTONES[i]) | 
| 60         return multicall | 60         return multicall | 
| 61 | 61 | 
| 62     def _mock_trac(self): | 62     def _mock_trac(self): | 
| 63         trac = mock.Mock() | 63         trac = mock.Mock() | 
| 64         trac.ticket.get = lambda id: [id, mock.ANY, mock.ANY, | 64         trac.ticket.get = lambda i: [i, mock.ANY, mock.ANY, ISSUES[i]['attrs']] | 
| 65                                       ISSUES[id]['attrs']] | 65         trac.ticket.getActions = lambda i: ISSUES[i]['actions'] | 
| 66         trac.ticket.getActions = lambda id: ISSUES[id]['actions'] |  | 
| 67         trac.ticket.milestone.getAll = lambda: MILESTONES.keys() | 66         trac.ticket.milestone.getAll = lambda: MILESTONES.keys() | 
| 68         self.trac_proxy_mock = trac | 67         self.trac_proxy_mock = trac | 
| 69         self._patchWith('xmlrpclib.ServerProxy', trac) | 68         self._patchWith('xmlrpclib.ServerProxy', trac) | 
| 70         self._patchWith('xmlrpclib.MultiCall', | 69         self._patchWith('xmlrpclib.MultiCall', | 
| 71                         self._create_mock_milestone_multicall()) | 70                         self._create_mock_milestone_multicall()) | 
| 72 | 71 | 
| 73     def _mock_config(self): | 72     def _mock_config(self): | 
| 74         config = ConfigParser.ConfigParser() | 73         config = ConfigParser.ConfigParser() | 
| 75         config.add_section('hg') | 74         config.add_section('hg') | 
| 76         config.set('hg', 'trac_xmlrpc_url', 'foo') | 75         config.set('hg', 'trac_xmlrpc_url', 'foo') | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 95             mock_commit.rev.return_value = i | 94             mock_commit.rev.return_value = i | 
| 96             mock_commit.hex.return_value = '{:010x}'.format(i) + '0' * 30 | 95             mock_commit.hex.return_value = '{:010x}'.format(i) + '0' * 30 | 
| 97             mock_commit.description.return_value = message | 96             mock_commit.description.return_value = message | 
| 98             self.append(mock_commit) | 97             self.append(mock_commit) | 
| 99         self.changelog = mock.Mock() | 98         self.changelog = mock.Mock() | 
| 100         self.changelog.findmissingrevs = self._findmissingrevs | 99         self.changelog.findmissingrevs = self._findmissingrevs | 
| 101 | 100 | 
| 102     def _findmissingrevs(self, olds, news): | 101     def _findmissingrevs(self, olds, news): | 
| 103         return range(olds[0] + 1, news[0] + 1) | 102         return range(olds[0] + 1, news[0] + 1) | 
| 104 | 103 | 
| 105     def __getitem__(self, id): | 104     def __getitem__(self, commit_id): | 
| 106         if isinstance(id, str): | 105         if isinstance(commit_id, str): | 
| 107             return [commit for commit in self if commit.hex() == id][0] | 106             return [commit for commit in self if commit.hex() == commit_id][0] | 
| 108         return list.__getitem__(self, id) | 107         return list.__getitem__(self, commit_id) | 
| 109 | 108 | 
| 110     def url(self): | 109     def url(self): | 
| 111         return 'mock/repo' | 110         return 'mock/repo' | 
| 112 | 111 | 
| 113 | 112 | 
| 114 class TestChangegroupHook(_TestBase): | 113 class TestChangegroupHook(_TestBase): | 
| 115 | 114 | 
| 116     def _run_hook(self, commit_messages, warning_count=0, update_count=0): | 115     def _run_hook(self, commit_messages, warning_count=0, update_count=0): | 
| 117         repo = _MockRepo(commit_messages) | 116         repo = _MockRepo(commit_messages) | 
| 118         update_issues.changegroup_hook(self.ui, repo, 0) | 117         update_issues.changegroup_hook(self.ui, repo, 0) | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 206         self._check_update(updates[0], 1337) | 205         self._check_update(updates[0], 1337) | 
| 207         self._check_update(updates[1], 2448, action='leave', milestone='other') | 206         self._check_update(updates[1], 2448, action='leave', milestone='other') | 
| 208 | 207 | 
| 209     def test_fix_nonexistent(self): | 208     def test_fix_nonexistent(self): | 
| 210         self._run_hook(['Fixes 7331 - Foo'], warning_count=1) | 209         self._run_hook(['Fixes 7331 - Foo'], warning_count=1) | 
| 211 | 210 | 
| 212     def test_fix_closed_with_assigned_milestone(self): | 211     def test_fix_closed_with_assigned_milestone(self): | 
| 213         self._run_hook(['fixes 3559 - Foo'])  # No updates. | 212         self._run_hook(['fixes 3559 - Foo'])  # No updates. | 
| 214 | 213 | 
| 215 | 214 | 
| 216 if __name__ == "__main__": | 215 if __name__ == '__main__': | 
| 217     unittest.main() | 216     unittest.main() | 
| LEFT | RIGHT | 
|---|