##// END OF EJS Templates
vcs: moved svn proxy settings into vcs related settings...
marcink -
r754:f39fd7f4 default
parent child Browse files
Show More
@@ -135,6 +135,7 b' class SettingsController(BaseController)'
135 c.svn_tag_patterns = model.get_global_svn_tag_patterns()
135 c.svn_tag_patterns = model.get_global_svn_tag_patterns()
136
136
137 application_form = ApplicationUiSettingsForm()()
137 application_form = ApplicationUiSettingsForm()()
138
138 try:
139 try:
139 form_result = application_form.to_python(dict(request.POST))
140 form_result = application_form.to_python(dict(request.POST))
140 except formencode.Invalid as errors:
141 except formencode.Invalid as errors:
@@ -151,12 +152,14 b' class SettingsController(BaseController)'
151 )
152 )
152
153
153 try:
154 try:
154 model.update_global_ssl_setting(form_result['web_push_ssl'])
155 if c.visual.allow_repo_location_change:
155 if c.visual.allow_repo_location_change:
156 model.update_global_path_setting(
156 model.update_global_path_setting(
157 form_result['paths_root_path'])
157 form_result['paths_root_path'])
158
159 model.update_global_ssl_setting(form_result['web_push_ssl'])
158 model.update_global_hook_settings(form_result)
160 model.update_global_hook_settings(form_result)
159 model.create_global_svn_settings(form_result)
161
162 model.create_or_update_global_svn_settings(form_result)
160 model.create_or_update_global_hg_settings(form_result)
163 model.create_or_update_global_hg_settings(form_result)
161 model.create_or_update_global_pr_settings(form_result)
164 model.create_or_update_global_pr_settings(form_result)
162 except Exception:
165 except Exception:
@@ -276,7 +276,7 b' def attach_context_attributes(context, r'
276 # Visual options
276 # Visual options
277 context.visual = AttributeDict({})
277 context.visual = AttributeDict({})
278
278
279 # DB store
279 # DB stored Visual Items
280 context.visual.show_public_icon = str2bool(
280 context.visual.show_public_icon = str2bool(
281 rc_config.get('rhodecode_show_public_icon'))
281 rc_config.get('rhodecode_show_public_icon'))
282 context.visual.show_private_icon = str2bool(
282 context.visual.show_private_icon = str2bool(
@@ -772,10 +772,10 b' def get_repo_type_by_name(repo_name):'
772
772
773
773
774 def is_svn_without_proxy(repository):
774 def is_svn_without_proxy(repository):
775 from rhodecode import CONFIG
776 if is_svn(repository):
775 if is_svn(repository):
777 if not CONFIG.get('rhodecode_proxy_subversion_http_requests', False):
776 from rhodecode.model.settings import VcsSettingsModel
778 return True
777 conf = VcsSettingsModel().get_ui_settings_as_config_obj()
778 return not str2bool(conf.get('vcs_svn_proxy', 'http_requests_enabled'))
779 return False
779 return False
780
780
781
781
@@ -22,10 +22,11 b' import logging'
22 from urlparse import urljoin
22 from urlparse import urljoin
23
23
24 import requests
24 import requests
25 from webob.exc import HTTPNotAcceptable
25
26
26 import rhodecode
27 from rhodecode.lib.middleware import simplevcs
27 from rhodecode.lib.middleware import simplevcs
28 from rhodecode.lib.utils import is_valid_repo
28 from rhodecode.lib.utils import is_valid_repo
29 from rhodecode.lib.utils2 import str2bool
29
30
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
31
32
@@ -95,10 +96,21 b' class SimpleSvnApp(object):'
95 return headers
96 return headers
96
97
97
98
99 class DisabledSimpleSvnApp(object):
100 def __init__(self, config):
101 self.config = config
102
103 def __call__(self, environ, start_response):
104 reason = 'Cannot handle SVN call because: SVN HTTP Proxy is not enabled'
105 log.warning(reason)
106 return HTTPNotAcceptable(reason)(environ, start_response)
107
108
98 class SimpleSvn(simplevcs.SimpleVCS):
109 class SimpleSvn(simplevcs.SimpleVCS):
99
110
100 SCM = 'svn'
111 SCM = 'svn'
101 READ_ONLY_COMMANDS = ('OPTIONS', 'PROPFIND', 'GET', 'REPORT')
112 READ_ONLY_COMMANDS = ('OPTIONS', 'PROPFIND', 'GET', 'REPORT')
113 DEFAULT_HTTP_SERVER = 'http://localhost:8090'
102
114
103 def _get_repository_name(self, environ):
115 def _get_repository_name(self, environ):
104 """
116 """
@@ -129,11 +141,19 b' class SimpleSvn(simplevcs.SimpleVCS):'
129 else 'push')
141 else 'push')
130
142
131 def _create_wsgi_app(self, repo_path, repo_name, config):
143 def _create_wsgi_app(self, repo_path, repo_name, config):
132 return SimpleSvnApp(config)
144 if self._is_svn_enabled():
145 return SimpleSvnApp(config)
146 # we don't have http proxy enabled return dummy request handler
147 return DisabledSimpleSvnApp(config)
148
149 def _is_svn_enabled(self):
150 conf = self.repo_vcs_config
151 return str2bool(conf.get('vcs_svn_proxy', 'http_requests_enabled'))
133
152
134 def _create_config(self, extras, repo_name):
153 def _create_config(self, extras, repo_name):
135 server_url = rhodecode.CONFIG.get(
154 conf = self.repo_vcs_config
136 'rhodecode_subversion_http_server_url', '')
155 server_url = conf.get('vcs_svn_proxy', 'http_server_url')
137 extras['subversion_http_server_url'] = (
156 server_url = server_url or self.DEFAULT_HTTP_SERVER
138 server_url or 'http://localhost/')
157
158 extras['subversion_http_server_url'] = server_url
139 return extras
159 return extras
@@ -46,11 +46,13 b' from rhodecode.lib.utils import ('
46 is_valid_repo, get_rhodecode_realm, get_rhodecode_base_path)
46 is_valid_repo, get_rhodecode_realm, get_rhodecode_base_path)
47 from rhodecode.lib.utils2 import safe_str, fix_PATH, str2bool
47 from rhodecode.lib.utils2 import safe_str, fix_PATH, str2bool
48 from rhodecode.lib.vcs.conf import settings as vcs_settings
48 from rhodecode.lib.vcs.conf import settings as vcs_settings
49 from rhodecode.lib.vcs.backends import base
49 from rhodecode.model import meta
50 from rhodecode.model import meta
50 from rhodecode.model.db import User, Repository
51 from rhodecode.model.db import User, Repository
51 from rhodecode.model.scm import ScmModel
52 from rhodecode.model.scm import ScmModel
52 from rhodecode.model.settings import SettingsModel
53 from rhodecode.model.settings import SettingsModel
53
54
55
54 log = logging.getLogger(__name__)
56 log = logging.getLogger(__name__)
55
57
56
58
@@ -86,6 +88,8 b' class SimpleVCS(object):'
86 self.registry = registry
88 self.registry = registry
87 self.application = application
89 self.application = application
88 self.config = config
90 self.config = config
91 # re-populated by specialized middlewares
92 self.repo_vcs_config = base.Config()
89 # base path of repo locations
93 # base path of repo locations
90 self.basepath = get_rhodecode_base_path()
94 self.basepath = get_rhodecode_base_path()
91 # authenticate this VCS request using authfunc
95 # authenticate this VCS request using authfunc
@@ -29,7 +29,8 b' from rhodecode.lib.middleware.appenlight'
29 from rhodecode.lib.middleware.simplegit import SimpleGit, GIT_PROTO_PAT
29 from rhodecode.lib.middleware.simplegit import SimpleGit, GIT_PROTO_PAT
30 from rhodecode.lib.middleware.simplehg import SimpleHg
30 from rhodecode.lib.middleware.simplehg import SimpleHg
31 from rhodecode.lib.middleware.simplesvn import SimpleSvn
31 from rhodecode.lib.middleware.simplesvn import SimpleSvn
32
32 from rhodecode.lib.vcs.backends import base
33 from rhodecode.model.settings import VcsSettingsModel
33
34
34 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
35
36
@@ -131,22 +132,38 b' class VCSMiddleware(object):'
131 self.config = config
132 self.config = config
132 self.appenlight_client = appenlight_client
133 self.appenlight_client = appenlight_client
133 self.registry = registry
134 self.registry = registry
135 self.repo_vcs_config = base.Config()
136 self.use_gzip = True
137
138 def vcs_config(self, repo_name=None):
139 """
140 returns serialized VcsSettings
141 """
142 return VcsSettingsModel(repo=repo_name).get_ui_settings_as_config_obj()
143
144 def wrap_in_gzip_if_enabled(self, app):
145 if self.use_gzip:
146 app = GunzipMiddleware(app)
147 return app
134
148
135 def _get_handler_app(self, environ):
149 def _get_handler_app(self, environ):
136 app = None
150 app = None
151
137 if is_hg(environ):
152 if is_hg(environ):
138 app = SimpleHg(self.application, self.config, self.registry)
153 app = SimpleHg(self.application, self.config, self.registry)
139
154
140 if is_git(environ):
155 if is_git(environ):
141 app = SimpleGit(self.application, self.config, self.registry)
156 app = SimpleGit(self.application, self.config, self.registry)
142
157
143 proxy_svn = rhodecode.CONFIG.get(
158 if is_svn(environ):
144 'rhodecode_proxy_subversion_http_requests', False)
145 if proxy_svn and is_svn(environ):
146 app = SimpleSvn(self.application, self.config, self.registry)
159 app = SimpleSvn(self.application, self.config, self.registry)
147
160
148 if app:
161 if app:
149 app = GunzipMiddleware(app)
162 repo_name = app._get_repository_name(environ)
163 self.repo_vcs_config = self.vcs_config(repo_name)
164 app.repo_vcs_config = self.repo_vcs_config
165
166 app = self.wrap_in_gzip_if_enabled(app)
150 app, _ = wrap_in_appenlight_if_enabled(
167 app, _ = wrap_in_appenlight_if_enabled(
151 app, self.config, self.appenlight_client)
168 app, self.config, self.appenlight_client)
152
169
@@ -389,9 +389,9 b' class _BaseVcsSettingsForm(formencode.Sc'
389 rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False)
389 rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False)
390 rhodecode_hg_use_rebase_for_merging = v.StringBoolean(if_missing=False)
390 rhodecode_hg_use_rebase_for_merging = v.StringBoolean(if_missing=False)
391
391
392 rhodecode_proxy_subversion_http_requests = v.StringBoolean(if_missing=False)
392 vcs_svn_proxy_http_requests_enabled = v.StringBoolean(if_missing=False)
393 rhodecode_subversion_http_server_url = v.UnicodeString(
393 vcs_svn_proxy_http_server_url = v.UnicodeString(strip=True, if_missing=None)
394 strip=True, if_missing=None)
394
395
395
396 def ApplicationUiSettingsForm():
396 def ApplicationUiSettingsForm():
397 class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
397 class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
@@ -24,9 +24,9 b' from collections import namedtuple'
24 from functools import wraps
24 from functools import wraps
25
25
26 from rhodecode.lib import caches
26 from rhodecode.lib import caches
27 from rhodecode.lib.caching_query import FromCache
28 from rhodecode.lib.utils2 import (
27 from rhodecode.lib.utils2 import (
29 Optional, AttributeDict, safe_str, remove_prefix, str2bool)
28 Optional, AttributeDict, safe_str, remove_prefix, str2bool)
29 from rhodecode.lib.vcs.backends import base
30 from rhodecode.model import BaseModel
30 from rhodecode.model import BaseModel
31 from rhodecode.model.db import (
31 from rhodecode.model.db import (
32 RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting)
32 RepoRhodeCodeUi, RepoRhodeCodeSetting, RhodeCodeUi, RhodeCodeSetting)
@@ -402,18 +402,25 b' class VcsSettingsModel(object):'
402
402
403 INHERIT_SETTINGS = 'inherit_vcs_settings'
403 INHERIT_SETTINGS = 'inherit_vcs_settings'
404 GENERAL_SETTINGS = (
404 GENERAL_SETTINGS = (
405 'use_outdated_comments', 'pr_merge_enabled',
405 'use_outdated_comments',
406 'pr_merge_enabled',
406 'hg_use_rebase_for_merging')
407 'hg_use_rebase_for_merging')
408
407 HOOKS_SETTINGS = (
409 HOOKS_SETTINGS = (
408 ('hooks', 'changegroup.repo_size'),
410 ('hooks', 'changegroup.repo_size'),
409 ('hooks', 'changegroup.push_logger'),
411 ('hooks', 'changegroup.push_logger'),
410 ('hooks', 'outgoing.pull_logger'))
412 ('hooks', 'outgoing.pull_logger'))
411 HG_SETTINGS = (
413 HG_SETTINGS = (
412 ('extensions', 'largefiles'), ('phases', 'publish'))
414 ('extensions', 'largefiles'),
413 GLOBAL_HG_SETTINGS = HG_SETTINGS + (('extensions', 'hgsubversion'), )
415 ('phases', 'publish'))
416 GLOBAL_HG_SETTINGS = (
417 ('extensions', 'largefiles'),
418 ('phases', 'publish'),
419 ('extensions', 'hgsubversion'))
414 GLOBAL_SVN_SETTINGS = (
420 GLOBAL_SVN_SETTINGS = (
415 'rhodecode_proxy_subversion_http_requests',
421 ('vcs_svn_proxy', 'http_requests_enabled'),
416 'rhodecode_subversion_http_server_url')
422 ('vcs_svn_proxy', 'http_server_url'))
423
417 SVN_BRANCH_SECTION = 'vcs_svn_branch'
424 SVN_BRANCH_SECTION = 'vcs_svn_branch'
418 SVN_TAG_SECTION = 'vcs_svn_tag'
425 SVN_TAG_SECTION = 'vcs_svn_tag'
419 SSL_SETTING = ('web', 'push_ssl')
426 SSL_SETTING = ('web', 'push_ssl')
@@ -523,13 +530,10 b' class VcsSettingsModel(object):'
523 def create_repo_svn_settings(self, data):
530 def create_repo_svn_settings(self, data):
524 return self._create_svn_settings(self.repo_settings, data)
531 return self._create_svn_settings(self.repo_settings, data)
525
532
526 def create_global_svn_settings(self, data):
527 return self._create_svn_settings(self.global_settings, data)
528
529 @assert_repo_settings
533 @assert_repo_settings
530 def create_or_update_repo_hg_settings(self, data):
534 def create_or_update_repo_hg_settings(self, data):
531 largefiles, phases = self.HG_SETTINGS
535 largefiles, phases = self.HG_SETTINGS
532 largefiles_key, phases_key = self._get_hg_settings(
536 largefiles_key, phases_key = self._get_settings_keys(
533 self.HG_SETTINGS, data)
537 self.HG_SETTINGS, data)
534 self._create_or_update_ui(
538 self._create_or_update_ui(
535 self.repo_settings, *largefiles, value='',
539 self.repo_settings, *largefiles, value='',
@@ -538,8 +542,8 b' class VcsSettingsModel(object):'
538 self.repo_settings, *phases, value=safe_str(data[phases_key]))
542 self.repo_settings, *phases, value=safe_str(data[phases_key]))
539
543
540 def create_or_update_global_hg_settings(self, data):
544 def create_or_update_global_hg_settings(self, data):
541 largefiles, phases, subversion = self.GLOBAL_HG_SETTINGS
545 largefiles, phases, hgsubversion = self.GLOBAL_HG_SETTINGS
542 largefiles_key, phases_key, subversion_key = self._get_hg_settings(
546 largefiles_key, phases_key, subversion_key = self._get_settings_keys(
543 self.GLOBAL_HG_SETTINGS, data)
547 self.GLOBAL_HG_SETTINGS, data)
544 self._create_or_update_ui(
548 self._create_or_update_ui(
545 self.global_settings, *largefiles, value='',
549 self.global_settings, *largefiles, value='',
@@ -547,22 +551,22 b' class VcsSettingsModel(object):'
547 self._create_or_update_ui(
551 self._create_or_update_ui(
548 self.global_settings, *phases, value=safe_str(data[phases_key]))
552 self.global_settings, *phases, value=safe_str(data[phases_key]))
549 self._create_or_update_ui(
553 self._create_or_update_ui(
550 self.global_settings, *subversion, active=data[subversion_key])
554 self.global_settings, *hgsubversion, active=data[subversion_key])
551
555
552 def create_or_update_global_svn_settings(self, data):
556 def create_or_update_global_svn_settings(self, data):
553 rhodecode_proxy_subversion_http_requests,
557 # branch/tags patterns
554 rhodecode_subversion_http_server_url = self.GLOBAL_SVN_SETTINGS
558 self._create_svn_settings(self.global_settings, data)
555 rhodecode_proxy_subversion_http_requests_key,
559
556 rhodecode_subversion_http_server_url_key = self._get_svn_settings(
560 http_requests_enabled, http_server_url = self.GLOBAL_SVN_SETTINGS
561 http_requests_enabled_key, http_server_url_key = self._get_settings_keys(
557 self.GLOBAL_SVN_SETTINGS, data)
562 self.GLOBAL_SVN_SETTINGS, data)
563
558 self._create_or_update_ui(
564 self._create_or_update_ui(
559 self.global_settings,
565 self.global_settings, *http_requests_enabled,
560 *rhodecode_proxy_subversion_http_requests,
566 value=safe_str(data[http_requests_enabled_key]))
561 value=safe_str(data[rhodecode_proxy_subversion_http_requests_key]))
562 self._create_or_update_ui(
567 self._create_or_update_ui(
563 self.global_settings,
568 self.global_settings, *http_server_url,
564 *rhodecode_subversion_http_server_url,
569 value=data[http_server_url_key])
565 active=data[rhodecode_subversion_http_server_url_key])
566
570
567 def update_global_ssl_setting(self, value):
571 def update_global_ssl_setting(self, value):
568 self._create_or_update_ui(
572 self._create_or_update_ui(
@@ -600,6 +604,16 b' class VcsSettingsModel(object):'
600 def get_global_ui_settings(self, section=None, key=None):
604 def get_global_ui_settings(self, section=None, key=None):
601 return self.global_settings.get_ui(section, key)
605 return self.global_settings.get_ui(section, key)
602
606
607 def get_ui_settings_as_config_obj(self, section=None, key=None):
608 config = base.Config()
609
610 ui_settings = self.get_ui_settings(section=section, key=key)
611
612 for entry in ui_settings:
613 config.set(entry.section, entry.key, entry.value)
614
615 return config
616
603 def get_ui_settings(self, section=None, key=None):
617 def get_ui_settings(self, section=None, key=None):
604 if not self.repo_settings or self.inherit_global_settings:
618 if not self.repo_settings or self.inherit_global_settings:
605 return self.get_global_ui_settings(section, key)
619 return self.get_global_ui_settings(section, key)
@@ -707,7 +721,7 b' class VcsSettingsModel(object):'
707 name, data[data_key], 'bool')
721 name, data[data_key], 'bool')
708 Session().add(setting)
722 Session().add(setting)
709
723
710 def _get_hg_settings(self, settings, data):
724 def _get_settings_keys(self, settings, data):
711 data_keys = [self._get_form_ui_key(*s) for s in settings]
725 data_keys = [self._get_form_ui_key(*s) for s in settings]
712 for data_key in data_keys:
726 for data_key in data_keys:
713 if data_key not in data:
727 if data_key not in data:
@@ -138,16 +138,16 b''
138
138
139 % endif
139 % endif
140
140
141 % if display_globals or repo_type in ['svn']:
141 % if display_globals:
142 <div class="panel panel-default">
142 <div class="panel panel-default">
143 <div class="panel-heading">
143 <div class="panel-heading">
144 <h3 class="panel-title">${_('Subversion Settings')}</h3>
144 <h3 class="panel-title">${_('Global Subversion Settings')}</h3>
145 </div>
145 </div>
146 <div class="panel-body">
146 <div class="panel-body">
147 <div class="field">
147 <div class="field">
148 <div class="checkbox">
148 <div class="checkbox">
149 ${h.checkbox('rhodecode_proxy_subversion_http_requests' + suffix, 'True', **kwargs)}
149 ${h.checkbox('vcs_svn_proxy_http_requests_enabled' + suffix, 'True', **kwargs)}
150 <label for="rhodecode_proxy_subversion_http_requests${suffix}">${_('Proxy subversion HTTP requests')}</label>
150 <label for="vcs_svn_proxy_http_requests_enabled{suffix}">${_('Proxy subversion HTTP requests')}</label>
151 </div>
151 </div>
152 <div class="label">
152 <div class="label">
153 <span class="help-block">${_('Subversion HTTP Support. Enables communication with SVN over HTTP protocol.')}</span>
153 <span class="help-block">${_('Subversion HTTP Support. Enables communication with SVN over HTTP protocol.')}</span>
@@ -155,17 +155,22 b''
155 </div>
155 </div>
156 <div class="field">
156 <div class="field">
157 <div class="label">
157 <div class="label">
158 <label for="rhodecode_subversion_http_server_url">${_('Subversion HTTP Server URL')}</label><br/>
158 <label for="vcs_svn_proxy_http_server_url">${_('Subversion HTTP Server URL')}</label><br/>
159 </div>
159 </div>
160 <div class="input">
160 <div class="input">
161 ${h.text('rhodecode_subversion_http_server_url',size=59)}
161 ${h.text('vcs_svn_proxy_http_server_url',size=59)}
162 </div>
162 </div>
163 </div>
163 </div>
164 <div class="field">
164 </div>
165 <div class="label">
165 </div>
166 <span class="help-block">${_('Url to Apache Proxy, e.g. http://localhost:8080/')}</span>
166 % endif
167 </div>
167
168 </div>
168 % if display_globals or repo_type in ['svn']:
169 <div class="panel panel-default">
170 <div class="panel-heading">
171 <h3 class="panel-title">${_('Subversion Settings')}</h3>
172 </div>
173 <div class="panel-body">
169 <div class="field">
174 <div class="field">
170 <div class="content" >
175 <div class="content" >
171 <label>${_('Repository patterns')}</label><br/>
176 <label>${_('Repository patterns')}</label><br/>
@@ -232,6 +237,9 b''
232 ${h.hidden('new_svn_tag' + suffix, '')}
237 ${h.hidden('new_svn_tag' + suffix, '')}
233 % endif
238 % endif
234
239
240
241
242
235 % if display_globals or repo_type in ['hg', 'git']:
243 % if display_globals or repo_type in ['hg', 'git']:
236 <div class="panel panel-default">
244 <div class="panel panel-default">
237 <div class="panel-heading">
245 <div class="panel-heading">
@@ -347,13 +347,13 b' class TestAdminSettingsVcs:'
347 with mock.patch.dict(
347 with mock.patch.dict(
348 rhodecode.CONFIG, {'labs_settings_active': 'true'}):
348 rhodecode.CONFIG, {'labs_settings_active': 'true'}):
349 response = self.app.get(url('admin_settings_vcs'))
349 response = self.app.get(url('admin_settings_vcs'))
350 response.mustcontain('Labs settings:')
350 response.mustcontain('Labs Settings')
351
351
352 def test_has_not_a_section_for_labs_settings_if_disables(self, app):
352 def test_has_not_a_section_for_labs_settings_if_disables(self, app):
353 with mock.patch.dict(
353 with mock.patch.dict(
354 rhodecode.CONFIG, {'labs_settings_active': 'false'}):
354 rhodecode.CONFIG, {'labs_settings_active': 'false'}):
355 response = self.app.get(url('admin_settings_vcs'))
355 response = self.app.get(url('admin_settings_vcs'))
356 response.mustcontain(no='Labs settings:')
356 response.mustcontain(no='Labs Settings')
357
357
358 @pytest.mark.parametrize('new_value', [True, False])
358 @pytest.mark.parametrize('new_value', [True, False])
359 def test_allows_to_change_hg_rebase_merge_strategy(
359 def test_allows_to_change_hg_rebase_merge_strategy(
@@ -444,50 +444,6 b' class TestLabsSettings(object):'
444 assert '<p class="help-block">text help</p>' in response
444 assert '<p class="help-block">text help</p>' in response
445 assert 'name="rhodecode_text" size="60" type="text"' in response
445 assert 'name="rhodecode_text" size="60" type="text"' in response
446
446
447 @pytest.mark.parametrize('setting_name', [
448 'proxy_subversion_http_requests',
449 ])
450 def test_update_boolean_settings(self, csrf_token, setting_name):
451 self.app.post(
452 url('admin_settings_labs'),
453 params={
454 'rhodecode_{}'.format(setting_name): 'true',
455 'csrf_token': csrf_token,
456 })
457 setting = SettingsModel().get_setting_by_name(setting_name)
458 assert setting.app_settings_value
459
460 self.app.post(
461 url('admin_settings_labs'),
462 params={
463 'rhodecode_{}'.format(setting_name): 'false',
464 'csrf_token': csrf_token,
465 })
466 setting = SettingsModel().get_setting_by_name(setting_name)
467 assert not setting.app_settings_value
468
469 @pytest.mark.parametrize('setting_name', [
470 'subversion_http_server_url',
471 ])
472 def test_update_string_settings(self, csrf_token, setting_name):
473 self.app.post(
474 url('admin_settings_labs'),
475 params={
476 'rhodecode_{}'.format(setting_name): 'Test 1',
477 'csrf_token': csrf_token,
478 })
479 setting = SettingsModel().get_setting_by_name(setting_name)
480 assert setting.app_settings_value == 'Test 1'
481
482 self.app.post(
483 url('admin_settings_labs'),
484 params={
485 'rhodecode_{}'.format(setting_name): ' Test 2 ',
486 'csrf_token': csrf_token,
487 })
488 setting = SettingsModel().get_setting_by_name(setting_name)
489 assert setting.app_settings_value == 'Test 2'
490
491
447
492 @pytest.mark.usefixtures('app')
448 @pytest.mark.usefixtures('app')
493 class TestOpenSourceLicenses(object):
449 class TestOpenSourceLicenses(object):
@@ -78,14 +78,29 b' class TestSimpleSvn(object):'
78 assert name == repo.repo_name
78 assert name == repo.repo_name
79
79
80 def test_create_wsgi_app(self):
80 def test_create_wsgi_app(self):
81 with patch('rhodecode.lib.middleware.simplesvn.SimpleSvnApp') as (
81 with patch.object(SimpleSvn, '_is_svn_enabled') as mock_method:
82 wsgi_app_mock):
82 mock_method.return_value = False
83 config = Mock()
83 with patch('rhodecode.lib.middleware.simplesvn.DisabledSimpleSvnApp') as (
84 wsgi_app = self.app._create_wsgi_app(
84 wsgi_app_mock):
85 repo_path='', repo_name='', config=config)
85 config = Mock()
86 wsgi_app = self.app._create_wsgi_app(
87 repo_path='', repo_name='', config=config)
88
89 wsgi_app_mock.assert_called_once_with(config)
90 assert wsgi_app == wsgi_app_mock()
86
91
87 wsgi_app_mock.assert_called_once_with(config)
92 def test_create_wsgi_app_when_enabled(self):
88 assert wsgi_app == wsgi_app_mock()
93 with patch.object(SimpleSvn, '_is_svn_enabled') as mock_method:
94 mock_method.return_value = True
95 with patch('rhodecode.lib.middleware.simplesvn.SimpleSvnApp') as (
96 wsgi_app_mock):
97 config = Mock()
98 wsgi_app = self.app._create_wsgi_app(
99 repo_path='', repo_name='', config=config)
100
101 wsgi_app_mock.assert_called_once_with(config)
102 assert wsgi_app == wsgi_app_mock()
103
89
104
90
105
91 class TestSimpleSvnApp(object):
106 class TestSimpleSvnApp(object):
@@ -22,11 +22,15 b' from mock import patch, Mock'
22
22
23 import rhodecode
23 import rhodecode
24 from rhodecode.lib.middleware import vcs
24 from rhodecode.lib.middleware import vcs
25 from rhodecode.lib.middleware.simplesvn import (
26 SimpleSvn, DisabledSimpleSvnApp, SimpleSvnApp)
27 from rhodecode.tests import SVN_REPO
25
28
29 svn_repo_path = '/'+ SVN_REPO
26
30
27 def test_is_hg():
31 def test_is_hg():
28 environ = {
32 environ = {
29 'PATH_INFO': '/rhodecode-dev',
33 'PATH_INFO': svn_repo_path,
30 'QUERY_STRING': 'cmd=changegroup',
34 'QUERY_STRING': 'cmd=changegroup',
31 'HTTP_ACCEPT': 'application/mercurial'
35 'HTTP_ACCEPT': 'application/mercurial'
32 }
36 }
@@ -35,7 +39,7 b' def test_is_hg():'
35
39
36 def test_is_hg_no_cmd():
40 def test_is_hg_no_cmd():
37 environ = {
41 environ = {
38 'PATH_INFO': '/rhodecode-dev',
42 'PATH_INFO': svn_repo_path,
39 'QUERY_STRING': '',
43 'QUERY_STRING': '',
40 'HTTP_ACCEPT': 'application/mercurial'
44 'HTTP_ACCEPT': 'application/mercurial'
41 }
45 }
@@ -44,7 +48,7 b' def test_is_hg_no_cmd():'
44
48
45 def test_is_hg_empty_cmd():
49 def test_is_hg_empty_cmd():
46 environ = {
50 environ = {
47 'PATH_INFO': '/rhodecode-dev',
51 'PATH_INFO': svn_repo_path,
48 'QUERY_STRING': 'cmd=',
52 'QUERY_STRING': 'cmd=',
49 'HTTP_ACCEPT': 'application/mercurial'
53 'HTTP_ACCEPT': 'application/mercurial'
50 }
54 }
@@ -53,7 +57,7 b' def test_is_hg_empty_cmd():'
53
57
54 def test_is_svn_returns_true_if_subversion_is_in_a_dav_header():
58 def test_is_svn_returns_true_if_subversion_is_in_a_dav_header():
55 environ = {
59 environ = {
56 'PATH_INFO': '/rhodecode-dev',
60 'PATH_INFO': svn_repo_path,
57 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log-revprops'
61 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log-revprops'
58 }
62 }
59 assert vcs.is_svn(environ) is True
63 assert vcs.is_svn(environ) is True
@@ -61,7 +65,7 b' def test_is_svn_returns_true_if_subversi'
61
65
62 def test_is_svn_returns_false_if_subversion_is_not_in_a_dav_header():
66 def test_is_svn_returns_false_if_subversion_is_not_in_a_dav_header():
63 environ = {
67 environ = {
64 'PATH_INFO': '/rhodecode-dev',
68 'PATH_INFO': svn_repo_path,
65 'HTTP_DAV': 'http://stuff.tigris.org/xmlns/dav/svn/log-revprops'
69 'HTTP_DAV': 'http://stuff.tigris.org/xmlns/dav/svn/log-revprops'
66 }
70 }
67 assert vcs.is_svn(environ) is False
71 assert vcs.is_svn(environ) is False
@@ -69,7 +73,7 b' def test_is_svn_returns_false_if_subvers'
69
73
70 def test_is_svn_returns_false_if_no_dav_header():
74 def test_is_svn_returns_false_if_no_dav_header():
71 environ = {
75 environ = {
72 'PATH_INFO': '/rhodecode-dev',
76 'PATH_INFO': svn_repo_path,
73 }
77 }
74 assert vcs.is_svn(environ) is False
78 assert vcs.is_svn(environ) is False
75
79
@@ -95,42 +99,42 b' def test_is_svn_allows_to_configure_the_'
95
99
96
100
97 class TestVCSMiddleware(object):
101 class TestVCSMiddleware(object):
98 def test_get_handler_app_retuns_svn_app_when_proxy_enabled(self):
102 def test_get_handler_app_retuns_svn_app_when_proxy_enabled(self, app):
99 environ = {
103 environ = {
100 'PATH_INFO': 'rhodecode-dev',
104 'PATH_INFO': SVN_REPO,
101 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log'
105 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log'
102 }
106 }
103 app = Mock()
107 application = Mock()
104 config = Mock()
108 config = {'appenlight': False}
105 registry = Mock()
109 registry = Mock()
106 middleware = vcs.VCSMiddleware(
110 middleware = vcs.VCSMiddleware(
107 app, config=config, appenlight_client=None, registry=registry)
111 application, config=config,
108 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
112 appenlight_client=None, registry=registry)
109 settings_patch = patch.dict(
113 middleware.use_gzip = False
110 rhodecode.CONFIG,
111 {'rhodecode_proxy_subversion_http_requests': True})
112 with snv_patch as svn_mock, settings_patch:
113 svn_mock.return_value = None
114 middleware._get_handler_app(environ)
115
114
116 svn_mock.assert_called_once_with(app, config, registry)
115 with patch.object(SimpleSvn, '_is_svn_enabled') as mock_method:
116 mock_method.return_value = True
117 application = middleware._get_handler_app(environ)
118 assert isinstance(application, SimpleSvn)
119 assert isinstance(application._create_wsgi_app(
120 Mock(), Mock(), Mock()), SimpleSvnApp)
117
121
118 def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self):
122 def test_get_handler_app_retuns_dummy_svn_app_when_proxy_disabled(self, app):
119 environ = {
123 environ = {
120 'PATH_INFO': 'rhodecode-dev',
124 'PATH_INFO': SVN_REPO,
121 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log'
125 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log'
122 }
126 }
123 app = Mock()
127 application = Mock()
124 config = Mock()
128 config = {'appenlight': False}
125 registry = Mock()
129 registry = Mock()
126 middleware = vcs.VCSMiddleware(
130 middleware = vcs.VCSMiddleware(
127 app, config=config, appenlight_client=None, registry=registry)
131 application, config=config,
128 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
132 appenlight_client=None, registry=registry)
129 settings_patch = patch.dict(
133 middleware.use_gzip = False
130 rhodecode.CONFIG,
131 {'rhodecode_proxy_subversion_http_requests': False})
132 with snv_patch as svn_mock, settings_patch:
133 app = middleware._get_handler_app(environ)
134
134
135 assert svn_mock.call_count == 0
135 with patch.object(SimpleSvn, '_is_svn_enabled') as mock_method:
136 assert app is None
136 mock_method.return_value = False
137 application = middleware._get_handler_app(environ)
138 assert isinstance(application, SimpleSvn)
139 assert isinstance(application._create_wsgi_app(
140 Mock(), Mock(), Mock()), DisabledSimpleSvnApp)
@@ -404,15 +404,6 b' class TestCreateRepoSvnSettings(object):'
404 assert exc_info.value.message == 'Repository is not specified'
404 assert exc_info.value.message == 'Repository is not specified'
405
405
406
406
407 class TestCreateGlobalSvnSettings(object):
408 def test_calls_create_svn_settings(self):
409 model = VcsSettingsModel()
410 with mock.patch.object(model, '_create_svn_settings') as create_mock:
411 model.create_global_svn_settings(SVN_FORM_DATA)
412 create_mock.assert_called_once_with(
413 model.global_settings, SVN_FORM_DATA)
414
415
416 class TestCreateSvnSettings(object):
407 class TestCreateSvnSettings(object):
417 def test_create(self, repo_stub):
408 def test_create(self, repo_stub):
418 model = VcsSettingsModel(repo=repo_stub.repo_name)
409 model = VcsSettingsModel(repo=repo_stub.repo_name)
General Comments 0
You need to be logged in to leave comments. Login now