Show More
@@ -1,50 +1,60 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2016 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import mock |
|
21 | import mock | |
22 | import pytest |
|
22 | import pytest | |
23 | import rhodecode.lib.vcs.client as client |
|
|||
24 | from rhodecode.lib.middleware.error_handling import ( |
|
|||
25 | PylonsErrorHandlingMiddleware) |
|
|||
26 |
|
23 | |||
27 |
|
24 | |||
28 | @pytest.mark.usefixtures('autologin_user', 'app') |
|
25 | @pytest.mark.usefixtures('autologin_user', 'app') | |
29 | def test_vcs_available_returns_summary_page(app, backend): |
|
26 | def test_vcs_available_returns_summary_page(app, backend): | |
30 | url = '/{repo_name}'.format(repo_name=backend.repo.repo_name) |
|
27 | url = '/{repo_name}'.format(repo_name=backend.repo.repo_name) | |
31 | response = app.get(url) |
|
28 | response = app.get(url) | |
32 | assert response.status_code == 200 |
|
29 | assert response.status_code == 200 | |
33 | assert 'Summary' in response.body |
|
30 | assert 'Summary' in response.body | |
34 |
|
31 | |||
35 |
|
32 | |||
36 | @pytest.mark.usefixtures('autologin_user', 'app') |
|
33 | @pytest.mark.usefixtures('autologin_user', 'app') | |
37 | def test_vcs_unavailable_returns_vcs_error_page(app, backend): |
|
34 | def test_vcs_unavailable_returns_vcs_error_page(app, backend, app_settings): | |
|
35 | import rhodecode | |||
|
36 | from rhodecode.lib.vcs.exceptions import VCSCommunicationError | |||
|
37 | ||||
|
38 | # Depending on the used VCSServer protocol we have to patch a different | |||
|
39 | # RemoteRepo class to raise an exception. For the test it doesn't matter | |||
|
40 | # if http or pyro4 is used, it just requires the exception to be raised. | |||
|
41 | vcs_protocol = app_settings['vcs.server.protocol'] | |||
|
42 | if vcs_protocol == 'http': | |||
|
43 | from rhodecode.lib.vcs.client_http import RemoteRepo | |||
|
44 | elif vcs_protocol == 'pyro4': | |||
|
45 | from rhodecode.lib.vcs.client import RemoteRepo | |||
|
46 | else: | |||
|
47 | pytest.fail('Unknown VCS server protocol: "{}"'.format(vcs_protocol)) | |||
|
48 | ||||
38 | url = '/{repo_name}'.format(repo_name=backend.repo.repo_name) |
|
49 | url = '/{repo_name}'.format(repo_name=backend.repo.repo_name) | |
39 |
|
50 | |||
40 |
# Pat |
|
51 | # Patch remote repo to raise an exception instead of making a RPC. | |
41 | # call to the vcsserver. |
|
52 | with mock.patch.object(RemoteRepo, '__getattr__') as remote_mock: | |
42 | with mock.patch.object(client, '_get_proxy_method') as p: |
|
53 | remote_mock.side_effect = VCSCommunicationError() | |
43 | p.side_effect = client.exceptions.PyroVCSCommunicationError() |
|
|||
44 | # Patch pylons error handling middleware to not re-raise exceptions. |
|
54 | # Patch pylons error handling middleware to not re-raise exceptions. | |
45 | with mock.patch.object(PylonsErrorHandlingMiddleware, 'reraise') as r: |
|
55 | with mock.patch.object(PylonsErrorHandlingMiddleware, 'reraise') as r: | |
46 | r.return_value = False |
|
56 | r.return_value = False | |
47 | response = app.get(url, expect_errors=True) |
|
57 | response = app.get(url, expect_errors=True) | |
48 |
|
58 | |||
49 | assert response.status_code == 502 |
|
59 | assert response.status_code == 502 | |
50 | assert 'Could not connect to VCS Server' in response.body |
|
60 | assert 'Could not connect to VCS Server' in response.body |
General Comments 0
You need to be logged in to leave comments.
Login now