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