##// END OF EJS Templates
tests: Fix up PATH_INFO to start with a slash...
johbo -
r438:de4b4a78 default
parent child Browse files
Show More
@@ -1,134 +1,134 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 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 from mock import patch, Mock
22 22
23 23 import rhodecode
24 24 from rhodecode.lib.middleware import vcs
25 25
26 26
27 27 def test_is_hg():
28 28 environ = {
29 'PATH_INFO': 'rhodecode-dev',
29 'PATH_INFO': '/rhodecode-dev',
30 30 'QUERY_STRING': 'cmd=changegroup',
31 31 'HTTP_ACCEPT': 'application/mercurial'
32 32 }
33 33 assert vcs.is_hg(environ)
34 34
35 35
36 36 def test_is_hg_no_cmd():
37 37 environ = {
38 'PATH_INFO': 'rhodecode-dev',
38 'PATH_INFO': '/rhodecode-dev',
39 39 'QUERY_STRING': '',
40 40 'HTTP_ACCEPT': 'application/mercurial'
41 41 }
42 42 assert not vcs.is_hg(environ)
43 43
44 44
45 45 def test_is_hg_empty_cmd():
46 46 environ = {
47 'PATH_INFO': 'rhodecode-dev',
47 'PATH_INFO': '/rhodecode-dev',
48 48 'QUERY_STRING': 'cmd=',
49 49 'HTTP_ACCEPT': 'application/mercurial'
50 50 }
51 51 assert not vcs.is_hg(environ)
52 52
53 53
54 54 def test_is_svn_returns_true_if_subversion_is_in_a_dav_header():
55 55 environ = {
56 'PATH_INFO': 'rhodecode-dev',
56 'PATH_INFO': '/rhodecode-dev',
57 57 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log-revprops'
58 58 }
59 59 assert vcs.is_svn(environ) is True
60 60
61 61
62 62 def test_is_svn_returns_false_if_subversion_is_not_in_a_dav_header():
63 63 environ = {
64 'PATH_INFO': 'rhodecode-dev',
64 'PATH_INFO': '/rhodecode-dev',
65 65 'HTTP_DAV': 'http://stuff.tigris.org/xmlns/dav/svn/log-revprops'
66 66 }
67 67 assert vcs.is_svn(environ) is False
68 68
69 69
70 70 def test_is_svn_returns_false_if_no_dav_header():
71 71 environ = {
72 'PATH_INFO': 'rhodecode-dev',
72 'PATH_INFO': '/rhodecode-dev',
73 73 }
74 74 assert vcs.is_svn(environ) is False
75 75
76 76
77 77 def test_is_svn_returns_true_if_magic_path_segment():
78 78 environ = {
79 79 'PATH_INFO': '/stub-repository/!svn/rev/4',
80 80 }
81 81 assert vcs.is_svn(environ)
82 82
83 83
84 84 def test_is_svn_allows_to_configure_the_magic_path(monkeypatch):
85 85 """
86 86 This is intended as a fallback in case someone has configured his
87 87 Subversion server with a different magic path segment.
88 88 """
89 89 monkeypatch.setitem(
90 90 rhodecode.CONFIG, 'rhodecode_subversion_magic_path', '/!my-magic')
91 91 environ = {
92 92 'PATH_INFO': '/stub-repository/!my-magic/rev/4',
93 93 }
94 94 assert vcs.is_svn(environ)
95 95
96 96
97 97 class TestVCSMiddleware(object):
98 98 def test_get_handler_app_retuns_svn_app_when_proxy_enabled(self):
99 99 environ = {
100 100 'PATH_INFO': 'rhodecode-dev',
101 101 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log'
102 102 }
103 103 app = Mock()
104 104 config = Mock()
105 105 middleware = vcs.VCSMiddleware(
106 106 app, config=config, appenlight_client=None)
107 107 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
108 108 settings_patch = patch.dict(
109 109 rhodecode.CONFIG,
110 110 {'rhodecode_proxy_subversion_http_requests': True})
111 111 with snv_patch as svn_mock, settings_patch:
112 112 svn_mock.return_value = None
113 113 middleware._get_handler_app(environ)
114 114
115 115 svn_mock.assert_called_once_with(app, config)
116 116
117 117 def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self):
118 118 environ = {
119 119 'PATH_INFO': 'rhodecode-dev',
120 120 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log'
121 121 }
122 122 app = Mock()
123 123 config = Mock()
124 124 middleware = vcs.VCSMiddleware(
125 125 app, config=config, appenlight_client=None)
126 126 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
127 127 settings_patch = patch.dict(
128 128 rhodecode.CONFIG,
129 129 {'rhodecode_proxy_subversion_http_requests': False})
130 130 with snv_patch as svn_mock, settings_patch:
131 131 app = middleware._get_handler_app(environ)
132 132
133 133 assert svn_mock.call_count == 0
134 134 assert app is None
General Comments 0
You need to be logged in to leave comments. Login now