Show More
@@ -1,117 +1,121 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import mock |
|
22 | 22 | import pytest |
|
23 | 23 | |
|
24 | 24 | import rhodecode |
|
25 | from rhodecode.model.db import Repository | |
|
25 | 26 | from rhodecode.model.settings import SettingsModel |
|
26 | 27 | from rhodecode.tests import url |
|
27 | 28 | from rhodecode.tests.utils import AssertResponse |
|
28 | 29 | |
|
29 | 30 | |
|
30 | 31 | def route_path(name, params=None, **kwargs): |
|
31 | 32 | import urllib |
|
32 | 33 | |
|
33 | 34 | base_url = { |
|
34 | 35 | 'edit_repo': '/{repo_name}/settings', |
|
35 | 36 | }[name].format(**kwargs) |
|
36 | 37 | |
|
37 | 38 | if params: |
|
38 | 39 | base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) |
|
39 | 40 | return base_url |
|
40 | 41 | |
|
41 | 42 | |
|
42 | 43 | @pytest.mark.usefixtures('autologin_user', 'app') |
|
43 | 44 | class TestAdminRepoVcsSettings(object): |
|
44 | 45 | |
|
45 | 46 | @pytest.mark.parametrize('setting_name, setting_backends', [ |
|
46 | 47 | ('hg_use_rebase_for_merging', ['hg']), |
|
47 | 48 | ]) |
|
48 | 49 | def test_labs_settings_visible_if_enabled( |
|
49 | 50 | self, setting_name, setting_backends, backend): |
|
50 | 51 | if backend.alias not in setting_backends: |
|
51 | 52 | pytest.skip('Setting not available for backend {}'.format(backend)) |
|
52 | 53 | |
|
53 | 54 | vcs_settings_url = url( |
|
54 | 55 | 'repo_vcs_settings', repo_name=backend.repo.repo_name) |
|
55 | 56 | |
|
56 | 57 | with mock.patch.dict( |
|
57 | 58 | rhodecode.CONFIG, {'labs_settings_active': 'true'}): |
|
58 | 59 | response = self.app.get(vcs_settings_url) |
|
59 | 60 | |
|
60 | 61 | assertr = AssertResponse(response) |
|
61 | 62 | assertr.one_element_exists('#rhodecode_{}'.format(setting_name)) |
|
62 | 63 | |
|
63 | 64 | @pytest.mark.parametrize('setting_name, setting_backends', [ |
|
64 | 65 | ('hg_use_rebase_for_merging', ['hg']), |
|
65 | 66 | ]) |
|
66 | 67 | def test_labs_settings_not_visible_if_disabled( |
|
67 | 68 | self, setting_name, setting_backends, backend): |
|
68 | 69 | if backend.alias not in setting_backends: |
|
69 | 70 | pytest.skip('Setting not available for backend {}'.format(backend)) |
|
70 | 71 | |
|
71 | 72 | vcs_settings_url = url( |
|
72 | 73 | 'repo_vcs_settings', repo_name=backend.repo.repo_name) |
|
73 | 74 | |
|
74 | 75 | with mock.patch.dict( |
|
75 | 76 | rhodecode.CONFIG, {'labs_settings_active': 'false'}): |
|
76 | 77 | response = self.app.get(vcs_settings_url) |
|
77 | 78 | |
|
78 | 79 | assertr = AssertResponse(response) |
|
79 | 80 | assertr.no_element_exists('#rhodecode_{}'.format(setting_name)) |
|
80 | 81 | |
|
81 | 82 | @pytest.mark.parametrize('setting_name, setting_backends', [ |
|
82 | 83 | ('hg_use_rebase_for_merging', ['hg']), |
|
83 | 84 | ]) |
|
84 | 85 | def test_update_boolean_settings( |
|
85 | 86 | self, csrf_token, setting_name, setting_backends, backend): |
|
86 | 87 | if backend.alias not in setting_backends: |
|
87 | 88 | pytest.skip('Setting not available for backend {}'.format(backend)) |
|
88 | 89 | |
|
89 | 90 | repo = backend.create_repo() |
|
91 | repo_name = repo.repo_name | |
|
90 | 92 | |
|
91 | 93 | settings_model = SettingsModel(repo=repo) |
|
92 | 94 | vcs_settings_url = url( |
|
93 |
'repo_vcs_settings', repo_name= |
|
|
95 | 'repo_vcs_settings', repo_name=repo_name) | |
|
94 | 96 | |
|
95 | 97 | self.app.post( |
|
96 | 98 | vcs_settings_url, |
|
97 | 99 | params={ |
|
98 | 100 | 'inherit_global_settings': False, |
|
99 | 101 | 'new_svn_branch': 'dummy-value-for-testing', |
|
100 | 102 | 'new_svn_tag': 'dummy-value-for-testing', |
|
101 | 103 | 'rhodecode_{}'.format(setting_name): 'true', |
|
102 | 104 | 'csrf_token': csrf_token, |
|
103 | 105 | }) |
|
106 | settings_model = SettingsModel(repo=Repository.get_by_repo_name(repo_name)) | |
|
104 | 107 | setting = settings_model.get_setting_by_name(setting_name) |
|
105 | 108 | assert setting.app_settings_value |
|
106 | 109 | |
|
107 | 110 | self.app.post( |
|
108 | 111 | vcs_settings_url, |
|
109 | 112 | params={ |
|
110 | 113 | 'inherit_global_settings': False, |
|
111 | 114 | 'new_svn_branch': 'dummy-value-for-testing', |
|
112 | 115 | 'new_svn_tag': 'dummy-value-for-testing', |
|
113 | 116 | 'rhodecode_{}'.format(setting_name): 'false', |
|
114 | 117 | 'csrf_token': csrf_token, |
|
115 | 118 | }) |
|
119 | settings_model = SettingsModel(repo=Repository.get_by_repo_name(repo_name)) | |
|
116 | 120 | setting = settings_model.get_setting_by_name(setting_name) |
|
117 | 121 | assert not setting.app_settings_value |
@@ -1,119 +1,122 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | 22 | |
|
23 | 23 | from rhodecode.lib.utils2 import md5 |
|
24 | from rhodecode.model.db import Repository | |
|
24 | 25 | from rhodecode.model.meta import Session |
|
25 | 26 | from rhodecode.model.settings import SettingsModel, IssueTrackerSettingsModel |
|
26 | 27 | from rhodecode.tests import url |
|
27 | 28 | |
|
28 | 29 | |
|
29 | 30 | @pytest.mark.usefixtures("app") |
|
30 | 31 | class TestAdminRepos: |
|
31 | 32 | def test_issuetracker_index(self, autologin_user, backend): |
|
32 | 33 | repo = backend.create_repo() |
|
33 | 34 | response = self.app.get(url('repo_settings_issuetracker', |
|
34 | 35 | repo_name=repo.repo_name)) |
|
35 | 36 | assert response.status_code == 200 |
|
36 | 37 | |
|
37 | 38 | def test_add_issuetracker_patterns( |
|
38 | 39 | self, autologin_user, backend, csrf_token, request): |
|
39 | 40 | pattern = 'issuetracker_pat' |
|
40 | 41 | another_pattern = pattern+'1' |
|
41 | 42 | post_url = url('repo_issuetracker_save', |
|
42 | 43 | repo_name=backend.repo.repo_name) |
|
43 | 44 | post_data = { |
|
44 | 45 | 'new_pattern_pattern_0': pattern, |
|
45 | 46 | 'new_pattern_url_0': 'url', |
|
46 | 47 | 'new_pattern_prefix_0': 'prefix', |
|
47 | 48 | 'new_pattern_description_0': 'description', |
|
48 | 49 | 'new_pattern_pattern_1': another_pattern, |
|
49 | 50 | 'new_pattern_url_1': 'url1', |
|
50 | 51 | 'new_pattern_prefix_1': 'prefix1', |
|
51 | 52 | 'new_pattern_description_1': 'description1', |
|
52 | 53 | 'csrf_token': csrf_token |
|
53 | 54 | } |
|
54 | 55 | self.app.post(post_url, post_data, status=302) |
|
55 | 56 | self.settings_model = IssueTrackerSettingsModel(repo=backend.repo) |
|
56 | 57 | settings = self.settings_model.get_repo_settings() |
|
57 | 58 | self.uid = md5(pattern) |
|
58 | 59 | assert settings[self.uid]['pat'] == pattern |
|
59 | 60 | self.another_uid = md5(another_pattern) |
|
60 | 61 | assert settings[self.another_uid]['pat'] == another_pattern |
|
61 | 62 | |
|
62 | 63 | @request.addfinalizer |
|
63 | 64 | def cleanup(): |
|
64 | 65 | self.settings_model.delete_entries(self.uid) |
|
65 | 66 | self.settings_model.delete_entries(self.another_uid) |
|
66 | 67 | |
|
67 | 68 | def test_edit_issuetracker_pattern( |
|
68 | 69 | self, autologin_user, backend, csrf_token, request): |
|
69 | 70 | entry_key = 'issuetracker_pat_' |
|
70 | 71 | pattern = 'issuetracker_pat2' |
|
71 | 72 | old_pattern = 'issuetracker_pat' |
|
72 | 73 | old_uid = md5(old_pattern) |
|
73 | 74 | |
|
74 | 75 | sett = SettingsModel(repo=backend.repo).create_or_update_setting( |
|
75 | 76 | entry_key+old_uid, old_pattern, 'unicode') |
|
76 | 77 | Session().add(sett) |
|
77 | 78 | Session().commit() |
|
78 | 79 | post_url = url('repo_issuetracker_save', |
|
79 | 80 | repo_name=backend.repo.repo_name) |
|
80 | 81 | post_data = { |
|
81 | 82 | 'new_pattern_pattern_0': pattern, |
|
82 | 83 | 'new_pattern_url_0': 'url', |
|
83 | 84 | 'new_pattern_prefix_0': 'prefix', |
|
84 | 85 | 'new_pattern_description_0': 'description', |
|
85 | 86 | 'uid': old_uid, |
|
86 | 87 | 'csrf_token': csrf_token |
|
87 | 88 | } |
|
88 | 89 | self.app.post(post_url, post_data, status=302) |
|
89 | 90 | self.settings_model = IssueTrackerSettingsModel(repo=backend.repo) |
|
90 | 91 | settings = self.settings_model.get_repo_settings() |
|
91 | 92 | self.uid = md5(pattern) |
|
92 | 93 | assert settings[self.uid]['pat'] == pattern |
|
93 | 94 | with pytest.raises(KeyError): |
|
94 | 95 | settings[old_uid] |
|
95 | 96 | |
|
96 | 97 | @request.addfinalizer |
|
97 | 98 | def cleanup(): |
|
98 | 99 | self.settings_model.delete_entries(self.uid) |
|
99 | 100 | |
|
100 | 101 | def test_delete_issuetracker_pattern( |
|
101 | 102 | self, autologin_user, backend, csrf_token, settings_util): |
|
102 | 103 | repo = backend.create_repo() |
|
104 | repo_name = repo.repo_name | |
|
103 | 105 | entry_key = 'issuetracker_pat_' |
|
104 | 106 | pattern = 'issuetracker_pat3' |
|
105 | 107 | uid = md5(pattern) |
|
106 | 108 | settings_util.create_repo_rhodecode_setting( |
|
107 | 109 | repo=backend.repo, name=entry_key+uid, |
|
108 | 110 | value=entry_key, type_='unicode', cleanup=False) |
|
109 | 111 | |
|
110 | 112 | self.app.post( |
|
111 | 113 | url('repo_issuetracker_delete', |
|
112 | 114 | repo_name=backend.repo.repo_name), |
|
113 | 115 | { |
|
114 | 116 | '_method': 'delete', |
|
115 | 117 | 'uid': uid, |
|
116 | 118 | 'csrf_token': csrf_token |
|
117 | 119 | }, status=302) |
|
118 |
settings = IssueTrackerSettingsModel( |
|
|
120 | settings = IssueTrackerSettingsModel( | |
|
121 | repo=Repository.get_by_repo_name(repo_name)).get_repo_settings() | |
|
119 | 122 | assert 'rhodecode_%s%s' % (entry_key, uid) not in settings |
General Comments 0
You need to be logged in to leave comments.
Login now