##// END OF EJS Templates
tests: fixed few possible cases of detached instance errors.
marcink -
r1902:9b3b9a29 default
parent child Browse files
Show More
@@ -1,117 +1,121
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
3 # Copyright (C) 2010-2017 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
23
24 import rhodecode
24 import rhodecode
25 from rhodecode.model.db import Repository
25 from rhodecode.model.settings import SettingsModel
26 from rhodecode.model.settings import SettingsModel
26 from rhodecode.tests import url
27 from rhodecode.tests import url
27 from rhodecode.tests.utils import AssertResponse
28 from rhodecode.tests.utils import AssertResponse
28
29
29
30
30 def route_path(name, params=None, **kwargs):
31 def route_path(name, params=None, **kwargs):
31 import urllib
32 import urllib
32
33
33 base_url = {
34 base_url = {
34 'edit_repo': '/{repo_name}/settings',
35 'edit_repo': '/{repo_name}/settings',
35 }[name].format(**kwargs)
36 }[name].format(**kwargs)
36
37
37 if params:
38 if params:
38 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
39 base_url = '{}?{}'.format(base_url, urllib.urlencode(params))
39 return base_url
40 return base_url
40
41
41
42
42 @pytest.mark.usefixtures('autologin_user', 'app')
43 @pytest.mark.usefixtures('autologin_user', 'app')
43 class TestAdminRepoVcsSettings(object):
44 class TestAdminRepoVcsSettings(object):
44
45
45 @pytest.mark.parametrize('setting_name, setting_backends', [
46 @pytest.mark.parametrize('setting_name, setting_backends', [
46 ('hg_use_rebase_for_merging', ['hg']),
47 ('hg_use_rebase_for_merging', ['hg']),
47 ])
48 ])
48 def test_labs_settings_visible_if_enabled(
49 def test_labs_settings_visible_if_enabled(
49 self, setting_name, setting_backends, backend):
50 self, setting_name, setting_backends, backend):
50 if backend.alias not in setting_backends:
51 if backend.alias not in setting_backends:
51 pytest.skip('Setting not available for backend {}'.format(backend))
52 pytest.skip('Setting not available for backend {}'.format(backend))
52
53
53 vcs_settings_url = url(
54 vcs_settings_url = url(
54 'repo_vcs_settings', repo_name=backend.repo.repo_name)
55 'repo_vcs_settings', repo_name=backend.repo.repo_name)
55
56
56 with mock.patch.dict(
57 with mock.patch.dict(
57 rhodecode.CONFIG, {'labs_settings_active': 'true'}):
58 rhodecode.CONFIG, {'labs_settings_active': 'true'}):
58 response = self.app.get(vcs_settings_url)
59 response = self.app.get(vcs_settings_url)
59
60
60 assertr = AssertResponse(response)
61 assertr = AssertResponse(response)
61 assertr.one_element_exists('#rhodecode_{}'.format(setting_name))
62 assertr.one_element_exists('#rhodecode_{}'.format(setting_name))
62
63
63 @pytest.mark.parametrize('setting_name, setting_backends', [
64 @pytest.mark.parametrize('setting_name, setting_backends', [
64 ('hg_use_rebase_for_merging', ['hg']),
65 ('hg_use_rebase_for_merging', ['hg']),
65 ])
66 ])
66 def test_labs_settings_not_visible_if_disabled(
67 def test_labs_settings_not_visible_if_disabled(
67 self, setting_name, setting_backends, backend):
68 self, setting_name, setting_backends, backend):
68 if backend.alias not in setting_backends:
69 if backend.alias not in setting_backends:
69 pytest.skip('Setting not available for backend {}'.format(backend))
70 pytest.skip('Setting not available for backend {}'.format(backend))
70
71
71 vcs_settings_url = url(
72 vcs_settings_url = url(
72 'repo_vcs_settings', repo_name=backend.repo.repo_name)
73 'repo_vcs_settings', repo_name=backend.repo.repo_name)
73
74
74 with mock.patch.dict(
75 with mock.patch.dict(
75 rhodecode.CONFIG, {'labs_settings_active': 'false'}):
76 rhodecode.CONFIG, {'labs_settings_active': 'false'}):
76 response = self.app.get(vcs_settings_url)
77 response = self.app.get(vcs_settings_url)
77
78
78 assertr = AssertResponse(response)
79 assertr = AssertResponse(response)
79 assertr.no_element_exists('#rhodecode_{}'.format(setting_name))
80 assertr.no_element_exists('#rhodecode_{}'.format(setting_name))
80
81
81 @pytest.mark.parametrize('setting_name, setting_backends', [
82 @pytest.mark.parametrize('setting_name, setting_backends', [
82 ('hg_use_rebase_for_merging', ['hg']),
83 ('hg_use_rebase_for_merging', ['hg']),
83 ])
84 ])
84 def test_update_boolean_settings(
85 def test_update_boolean_settings(
85 self, csrf_token, setting_name, setting_backends, backend):
86 self, csrf_token, setting_name, setting_backends, backend):
86 if backend.alias not in setting_backends:
87 if backend.alias not in setting_backends:
87 pytest.skip('Setting not available for backend {}'.format(backend))
88 pytest.skip('Setting not available for backend {}'.format(backend))
88
89
89 repo = backend.create_repo()
90 repo = backend.create_repo()
91 repo_name = repo.repo_name
90
92
91 settings_model = SettingsModel(repo=repo)
93 settings_model = SettingsModel(repo=repo)
92 vcs_settings_url = url(
94 vcs_settings_url = url(
93 'repo_vcs_settings', repo_name=repo.repo_name)
95 'repo_vcs_settings', repo_name=repo_name)
94
96
95 self.app.post(
97 self.app.post(
96 vcs_settings_url,
98 vcs_settings_url,
97 params={
99 params={
98 'inherit_global_settings': False,
100 'inherit_global_settings': False,
99 'new_svn_branch': 'dummy-value-for-testing',
101 'new_svn_branch': 'dummy-value-for-testing',
100 'new_svn_tag': 'dummy-value-for-testing',
102 'new_svn_tag': 'dummy-value-for-testing',
101 'rhodecode_{}'.format(setting_name): 'true',
103 'rhodecode_{}'.format(setting_name): 'true',
102 'csrf_token': csrf_token,
104 'csrf_token': csrf_token,
103 })
105 })
106 settings_model = SettingsModel(repo=Repository.get_by_repo_name(repo_name))
104 setting = settings_model.get_setting_by_name(setting_name)
107 setting = settings_model.get_setting_by_name(setting_name)
105 assert setting.app_settings_value
108 assert setting.app_settings_value
106
109
107 self.app.post(
110 self.app.post(
108 vcs_settings_url,
111 vcs_settings_url,
109 params={
112 params={
110 'inherit_global_settings': False,
113 'inherit_global_settings': False,
111 'new_svn_branch': 'dummy-value-for-testing',
114 'new_svn_branch': 'dummy-value-for-testing',
112 'new_svn_tag': 'dummy-value-for-testing',
115 'new_svn_tag': 'dummy-value-for-testing',
113 'rhodecode_{}'.format(setting_name): 'false',
116 'rhodecode_{}'.format(setting_name): 'false',
114 'csrf_token': csrf_token,
117 'csrf_token': csrf_token,
115 })
118 })
119 settings_model = SettingsModel(repo=Repository.get_by_repo_name(repo_name))
116 setting = settings_model.get_setting_by_name(setting_name)
120 setting = settings_model.get_setting_by_name(setting_name)
117 assert not setting.app_settings_value
121 assert not setting.app_settings_value
@@ -1,119 +1,122
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
3 # Copyright (C) 2010-2017 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 pytest
21 import pytest
22
22
23 from rhodecode.lib.utils2 import md5
23 from rhodecode.lib.utils2 import md5
24 from rhodecode.model.db import Repository
24 from rhodecode.model.meta import Session
25 from rhodecode.model.meta import Session
25 from rhodecode.model.settings import SettingsModel, IssueTrackerSettingsModel
26 from rhodecode.model.settings import SettingsModel, IssueTrackerSettingsModel
26 from rhodecode.tests import url
27 from rhodecode.tests import url
27
28
28
29
29 @pytest.mark.usefixtures("app")
30 @pytest.mark.usefixtures("app")
30 class TestAdminRepos:
31 class TestAdminRepos:
31 def test_issuetracker_index(self, autologin_user, backend):
32 def test_issuetracker_index(self, autologin_user, backend):
32 repo = backend.create_repo()
33 repo = backend.create_repo()
33 response = self.app.get(url('repo_settings_issuetracker',
34 response = self.app.get(url('repo_settings_issuetracker',
34 repo_name=repo.repo_name))
35 repo_name=repo.repo_name))
35 assert response.status_code == 200
36 assert response.status_code == 200
36
37
37 def test_add_issuetracker_patterns(
38 def test_add_issuetracker_patterns(
38 self, autologin_user, backend, csrf_token, request):
39 self, autologin_user, backend, csrf_token, request):
39 pattern = 'issuetracker_pat'
40 pattern = 'issuetracker_pat'
40 another_pattern = pattern+'1'
41 another_pattern = pattern+'1'
41 post_url = url('repo_issuetracker_save',
42 post_url = url('repo_issuetracker_save',
42 repo_name=backend.repo.repo_name)
43 repo_name=backend.repo.repo_name)
43 post_data = {
44 post_data = {
44 'new_pattern_pattern_0': pattern,
45 'new_pattern_pattern_0': pattern,
45 'new_pattern_url_0': 'url',
46 'new_pattern_url_0': 'url',
46 'new_pattern_prefix_0': 'prefix',
47 'new_pattern_prefix_0': 'prefix',
47 'new_pattern_description_0': 'description',
48 'new_pattern_description_0': 'description',
48 'new_pattern_pattern_1': another_pattern,
49 'new_pattern_pattern_1': another_pattern,
49 'new_pattern_url_1': 'url1',
50 'new_pattern_url_1': 'url1',
50 'new_pattern_prefix_1': 'prefix1',
51 'new_pattern_prefix_1': 'prefix1',
51 'new_pattern_description_1': 'description1',
52 'new_pattern_description_1': 'description1',
52 'csrf_token': csrf_token
53 'csrf_token': csrf_token
53 }
54 }
54 self.app.post(post_url, post_data, status=302)
55 self.app.post(post_url, post_data, status=302)
55 self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
56 self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
56 settings = self.settings_model.get_repo_settings()
57 settings = self.settings_model.get_repo_settings()
57 self.uid = md5(pattern)
58 self.uid = md5(pattern)
58 assert settings[self.uid]['pat'] == pattern
59 assert settings[self.uid]['pat'] == pattern
59 self.another_uid = md5(another_pattern)
60 self.another_uid = md5(another_pattern)
60 assert settings[self.another_uid]['pat'] == another_pattern
61 assert settings[self.another_uid]['pat'] == another_pattern
61
62
62 @request.addfinalizer
63 @request.addfinalizer
63 def cleanup():
64 def cleanup():
64 self.settings_model.delete_entries(self.uid)
65 self.settings_model.delete_entries(self.uid)
65 self.settings_model.delete_entries(self.another_uid)
66 self.settings_model.delete_entries(self.another_uid)
66
67
67 def test_edit_issuetracker_pattern(
68 def test_edit_issuetracker_pattern(
68 self, autologin_user, backend, csrf_token, request):
69 self, autologin_user, backend, csrf_token, request):
69 entry_key = 'issuetracker_pat_'
70 entry_key = 'issuetracker_pat_'
70 pattern = 'issuetracker_pat2'
71 pattern = 'issuetracker_pat2'
71 old_pattern = 'issuetracker_pat'
72 old_pattern = 'issuetracker_pat'
72 old_uid = md5(old_pattern)
73 old_uid = md5(old_pattern)
73
74
74 sett = SettingsModel(repo=backend.repo).create_or_update_setting(
75 sett = SettingsModel(repo=backend.repo).create_or_update_setting(
75 entry_key+old_uid, old_pattern, 'unicode')
76 entry_key+old_uid, old_pattern, 'unicode')
76 Session().add(sett)
77 Session().add(sett)
77 Session().commit()
78 Session().commit()
78 post_url = url('repo_issuetracker_save',
79 post_url = url('repo_issuetracker_save',
79 repo_name=backend.repo.repo_name)
80 repo_name=backend.repo.repo_name)
80 post_data = {
81 post_data = {
81 'new_pattern_pattern_0': pattern,
82 'new_pattern_pattern_0': pattern,
82 'new_pattern_url_0': 'url',
83 'new_pattern_url_0': 'url',
83 'new_pattern_prefix_0': 'prefix',
84 'new_pattern_prefix_0': 'prefix',
84 'new_pattern_description_0': 'description',
85 'new_pattern_description_0': 'description',
85 'uid': old_uid,
86 'uid': old_uid,
86 'csrf_token': csrf_token
87 'csrf_token': csrf_token
87 }
88 }
88 self.app.post(post_url, post_data, status=302)
89 self.app.post(post_url, post_data, status=302)
89 self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
90 self.settings_model = IssueTrackerSettingsModel(repo=backend.repo)
90 settings = self.settings_model.get_repo_settings()
91 settings = self.settings_model.get_repo_settings()
91 self.uid = md5(pattern)
92 self.uid = md5(pattern)
92 assert settings[self.uid]['pat'] == pattern
93 assert settings[self.uid]['pat'] == pattern
93 with pytest.raises(KeyError):
94 with pytest.raises(KeyError):
94 settings[old_uid]
95 settings[old_uid]
95
96
96 @request.addfinalizer
97 @request.addfinalizer
97 def cleanup():
98 def cleanup():
98 self.settings_model.delete_entries(self.uid)
99 self.settings_model.delete_entries(self.uid)
99
100
100 def test_delete_issuetracker_pattern(
101 def test_delete_issuetracker_pattern(
101 self, autologin_user, backend, csrf_token, settings_util):
102 self, autologin_user, backend, csrf_token, settings_util):
102 repo = backend.create_repo()
103 repo = backend.create_repo()
104 repo_name = repo.repo_name
103 entry_key = 'issuetracker_pat_'
105 entry_key = 'issuetracker_pat_'
104 pattern = 'issuetracker_pat3'
106 pattern = 'issuetracker_pat3'
105 uid = md5(pattern)
107 uid = md5(pattern)
106 settings_util.create_repo_rhodecode_setting(
108 settings_util.create_repo_rhodecode_setting(
107 repo=backend.repo, name=entry_key+uid,
109 repo=backend.repo, name=entry_key+uid,
108 value=entry_key, type_='unicode', cleanup=False)
110 value=entry_key, type_='unicode', cleanup=False)
109
111
110 self.app.post(
112 self.app.post(
111 url('repo_issuetracker_delete',
113 url('repo_issuetracker_delete',
112 repo_name=backend.repo.repo_name),
114 repo_name=backend.repo.repo_name),
113 {
115 {
114 '_method': 'delete',
116 '_method': 'delete',
115 'uid': uid,
117 'uid': uid,
116 'csrf_token': csrf_token
118 'csrf_token': csrf_token
117 }, status=302)
119 }, status=302)
118 settings = IssueTrackerSettingsModel(repo=repo).get_repo_settings()
120 settings = IssueTrackerSettingsModel(
121 repo=Repository.get_by_repo_name(repo_name)).get_repo_settings()
119 assert 'rhodecode_%s%s' % (entry_key, uid) not in settings
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