##// END OF EJS Templates
tests: Adapt tests to recent changes in vcs lib.
Martin Bornhold -
r849:87280852 default
parent child Browse files
Show More
@@ -1,130 +1,131 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2016 RhodeCode GmbH
3 # Copyright (C) 2016-2016 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 Pyro4
22 import Pyro4
23 import pytest
23 import pytest
24 import webtest
24 import webtest
25
25
26 from rhodecode.lib.middleware.utils import scm_app_http, scm_app
26 from rhodecode.lib.middleware.utils import scm_app_http, scm_app
27 from rhodecode.lib.middleware.simplegit import SimpleGit
27 from rhodecode.lib.vcs.conf import settings
28 from rhodecode.lib.vcs.conf import settings
28
29
29
30
30 def vcs_http_app(vcsserver_http_echo_app):
31 def vcs_http_app(vcsserver_http_echo_app):
31 """
32 """
32 VcsHttpProxy wrapped in WebTest.
33 VcsHttpProxy wrapped in WebTest.
33 """
34 """
34 git_url = vcsserver_http_echo_app.http_url + 'stream/git/'
35 git_url = vcsserver_http_echo_app.http_url + 'stream/git/'
35 vcs_http_proxy = scm_app_http.VcsHttpProxy(
36 vcs_http_proxy = scm_app_http.VcsHttpProxy(
36 git_url, 'stub_path', 'stub_name', None, 'stub_backend')
37 git_url, 'stub_path', 'stub_name', None, 'stub_backend')
37 app = webtest.TestApp(vcs_http_proxy)
38 app = webtest.TestApp(vcs_http_proxy)
38 return app
39 return app
39
40
40
41
41 @pytest.fixture(scope='module')
42 @pytest.fixture(scope='module')
42 def vcsserver_http_echo_app(request, vcsserver_factory):
43 def vcsserver_http_echo_app(request, vcsserver_factory):
43 """
44 """
44 A running VCSServer with the EchoApp activated via HTTP.
45 A running VCSServer with the EchoApp activated via HTTP.
45 """
46 """
46 vcsserver = vcsserver_factory(
47 vcsserver = vcsserver_factory(
47 request=request,
48 request=request,
48 use_http=True,
49 use_http=True,
49 overrides=[{'app:main': {'dev.use_echo_app': 'true'}}])
50 overrides=[{'app:main': {'dev.use_echo_app': 'true'}}])
50 return vcsserver
51 return vcsserver
51
52
52
53
53 @pytest.fixture(scope='session')
54 @pytest.fixture(scope='session')
54 def data():
55 def data():
55 one_kb = "x" * 1024
56 one_kb = "x" * 1024
56 return one_kb * 1024 * 10
57 return one_kb * 1024 * 10
57
58
58
59
59 def test_reuse_app_no_data(repeat, vcsserver_http_echo_app):
60 def test_reuse_app_no_data(repeat, vcsserver_http_echo_app):
60 app = vcs_http_app(vcsserver_http_echo_app)
61 app = vcs_http_app(vcsserver_http_echo_app)
61 for x in xrange(repeat / 10):
62 for x in xrange(repeat / 10):
62 response = app.post('/')
63 response = app.post('/')
63 assert response.status_code == 200
64 assert response.status_code == 200
64
65
65
66
66 def test_reuse_app_with_data(data, repeat, vcsserver_http_echo_app):
67 def test_reuse_app_with_data(data, repeat, vcsserver_http_echo_app):
67 app = vcs_http_app(vcsserver_http_echo_app)
68 app = vcs_http_app(vcsserver_http_echo_app)
68 for x in xrange(repeat / 10):
69 for x in xrange(repeat / 10):
69 response = app.post('/', params=data)
70 response = app.post('/', params=data)
70 assert response.status_code == 200
71 assert response.status_code == 200
71
72
72
73
73 def test_create_app_per_request_no_data(repeat, vcsserver_http_echo_app):
74 def test_create_app_per_request_no_data(repeat, vcsserver_http_echo_app):
74 for x in xrange(repeat / 10):
75 for x in xrange(repeat / 10):
75 app = vcs_http_app(vcsserver_http_echo_app)
76 app = vcs_http_app(vcsserver_http_echo_app)
76 response = app.post('/')
77 response = app.post('/')
77 assert response.status_code == 200
78 assert response.status_code == 200
78
79
79
80
80 def test_create_app_per_request_with_data(
81 def test_create_app_per_request_with_data(
81 data, repeat, vcsserver_http_echo_app):
82 data, repeat, vcsserver_http_echo_app):
82 for x in xrange(repeat / 10):
83 for x in xrange(repeat / 10):
83 app = vcs_http_app(vcsserver_http_echo_app)
84 app = vcs_http_app(vcsserver_http_echo_app)
84 response = app.post('/', params=data)
85 response = app.post('/', params=data)
85 assert response.status_code == 200
86 assert response.status_code == 200
86
87
87
88
88 @pytest.fixture(scope='module')
89 @pytest.fixture(scope='module')
89 def vcsserver_pyro_echo_app(request, vcsserver_factory):
90 def vcsserver_pyro_echo_app(request, vcsserver_factory):
90 """
91 """
91 A running VCSServer with the EchoApp activated via Pyro4.
92 A running VCSServer with the EchoApp activated via Pyro4.
92 """
93 """
93 vcsserver = vcsserver_factory(
94 vcsserver = vcsserver_factory(
94 request=request,
95 request=request,
95 use_http=False,
96 use_http=False,
96 overrides=[{'DEFAULT': {'dev.use_echo_app': 'true'}}])
97 overrides=[{'DEFAULT': {'dev.use_echo_app': 'true'}}])
97 return vcsserver
98 return vcsserver
98
99
99
100
100 def vcs_pyro4_app(vcsserver_pyro_echo_app):
101 def vcs_pyro4_app(vcsserver_pyro_echo_app):
101 """
102 """
102 Pyro4 based Vcs proxy wrapped in WebTest
103 Pyro4 based Vcs proxy wrapped in WebTest
103 """
104 """
104 stub_config = {
105 stub_config = {
105 'git_update_server_info': 'stub',
106 'git_update_server_info': 'stub',
106 }
107 }
107 server_and_port = vcsserver_pyro_echo_app.server_and_port
108 server_and_port = vcsserver_pyro_echo_app.server_and_port
108 GIT_REMOTE_WSGI = Pyro4.Proxy(
109 GIT_REMOTE_WSGI = Pyro4.Proxy(
109 settings.pyro_remote(
110 settings.pyro_remote(
110 settings.PYRO_GIT_REMOTE_WSGI, server_and_port))
111 settings.PYRO_GIT_REMOTE_WSGI, server_and_port))
111 with mock.patch('rhodecode.lib.middleware.utils.scm_app.GIT_REMOTE_WSGI',
112 with mock.patch('rhodecode.lib.middleware.utils.scm_app.GIT_REMOTE_WSGI',
112 GIT_REMOTE_WSGI):
113 GIT_REMOTE_WSGI):
113 pyro4_app = scm_app.create_git_wsgi_app(
114 pyro4_app = scm_app.create_git_wsgi_app(
114 'stub_path', 'stub_name', stub_config)
115 'stub_path', 'stub_name', stub_config, SimpleGit.SCM)
115 app = webtest.TestApp(pyro4_app)
116 app = webtest.TestApp(pyro4_app)
116 return app
117 return app
117
118
118
119
119 def test_pyro4_no_data(repeat, pylonsapp, vcsserver_pyro_echo_app):
120 def test_pyro4_no_data(repeat, pylonsapp, vcsserver_pyro_echo_app):
120 for x in xrange(repeat / 10):
121 for x in xrange(repeat / 10):
121 app = vcs_pyro4_app(vcsserver_pyro_echo_app)
122 app = vcs_pyro4_app(vcsserver_pyro_echo_app)
122 response = app.post('/')
123 response = app.post('/')
123 assert response.status_code == 200
124 assert response.status_code == 200
124
125
125
126
126 def test_pyro4_with_data(repeat, pylonsapp, vcsserver_pyro_echo_app, data):
127 def test_pyro4_with_data(repeat, pylonsapp, vcsserver_pyro_echo_app, data):
127 for x in xrange(repeat / 10):
128 for x in xrange(repeat / 10):
128 app = vcs_pyro4_app(vcsserver_pyro_echo_app)
129 app = vcs_pyro4_app(vcsserver_pyro_echo_app)
129 response = app.post('/', params=data)
130 response = app.post('/', params=data)
130 assert response.status_code == 200
131 assert response.status_code == 200
@@ -1,98 +1,102 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
3 # Copyright (C) 2010-2016 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 webtest
21 import webtest
22
22
23 from rhodecode.lib.middleware.utils import wsgi_app_caller_client
23 from rhodecode.lib.middleware.utils import wsgi_app_caller_client
24
24
25 # pylint: disable=protected-access,too-many-public-methods
25 # pylint: disable=protected-access,too-many-public-methods
26
26
27
27
28 BASE_ENVIRON = {
28 BASE_ENVIRON = {
29 'REQUEST_METHOD': 'GET',
29 'REQUEST_METHOD': 'GET',
30 'SERVER_NAME': 'localhost',
30 'SERVER_NAME': 'localhost',
31 'SERVER_PORT': '80',
31 'SERVER_PORT': '80',
32 'SCRIPT_NAME': '',
32 'SCRIPT_NAME': '',
33 'PATH_INFO': '/',
33 'PATH_INFO': '/',
34 'QUERY_STRING': '',
34 'QUERY_STRING': '',
35 'foo.bool_var': True,
35 'foo.bool_var': True,
36 'foo.str_var': 'True',
36 'foo.str_var': 'True',
37 'wsgi.foo': True,
37 'wsgi.foo': True,
38 # Some non string values. The validator expects to get an iterable as
38 # Some non string values. The validator expects to get an iterable as
39 # value.
39 # value.
40 (42,): '42',
40 (42,): '42',
41 (True,): 'False',
41 (True,): 'False',
42 }
42 }
43
43
44
44
45 def assert_all_values_are_str(environ):
45 def assert_all_values_are_str(environ):
46 """Checks that all values of a dict are str."""
46 """Checks that all values of a dict are str."""
47 for key, value in environ.iteritems():
47 for key, value in environ.iteritems():
48 assert isinstance(value, str), (
48 assert isinstance(value, str), (
49 "Value for key %s: has type %s but 'str' was expected. Value: %s" %
49 "Value for key %s: has type %s but 'str' was expected. Value: %s" %
50 (key, type(value), repr(value)))
50 (key, type(value), repr(value)))
51
51
52
52
53 def assert_all_keys_are_str(environ):
53 def assert_all_keys_are_str(environ):
54 """Checks that all keys of a dict are str."""
54 """Checks that all keys of a dict are str."""
55 for key, value in environ.iteritems():
55 for key, value in environ.iteritems():
56 assert isinstance(value, str), (
56 assert isinstance(value, str), (
57 "Key %s: has type %s but 'str' was expected. " %
57 "Key %s: has type %s but 'str' was expected. " %
58 (repr(key), type(key)))
58 (repr(key), type(key)))
59
59
60
60
61 def assert_no_prefix_in_keys(environ, prefix):
61 def assert_no_prefix_in_keys(environ, prefix):
62 """Checks that no key of the dict starts with the prefix."""
62 """Checks that no key of the dict starts with the prefix."""
63 for key in environ:
63 for key in environ:
64 assert not key.startswith(prefix), 'Key %s should not be present' % key
64 assert not key.startswith(prefix), 'Key %s should not be present' % key
65
65
66
66
67 def test_get_environ():
67 def test_get_environ():
68 clean_environ = wsgi_app_caller_client._get_clean_environ(BASE_ENVIRON)
68 clean_environ = wsgi_app_caller_client._get_clean_environ(BASE_ENVIRON)
69
69
70 assert len(clean_environ) == 7
70 assert len(clean_environ) == 7
71 assert_no_prefix_in_keys(clean_environ, 'wsgi.')
71 assert_no_prefix_in_keys(clean_environ, 'wsgi.')
72 assert_all_keys_are_str(clean_environ)
72 assert_all_keys_are_str(clean_environ)
73 assert_all_values_are_str(clean_environ)
73 assert_all_values_are_str(clean_environ)
74
74
75
75
76 def test_remote_app_caller():
76 def test_remote_app_caller():
77
77
78 class RemoteAppCallerMock(object):
78 class RemoteAppCallerMock(object):
79
79
80 def handle(self, environ, input_data, arg1, arg2,
80 def handle(self, environ, input_data, arg1, arg2,
81 arg3=None, arg4=None, arg5=None):
81 arg3=None, arg4=None, arg5=None):
82 assert ((arg1, arg2, arg3, arg4, arg5) ==
82 assert ((arg1, arg2, arg3, arg4, arg5) ==
83 ('a1', 'a2', 'a3', 'a4', None))
83 ('a1', 'a2', 'a3', 'a4', None))
84 # Note: RemoteAppCaller is expected to return a tuple like the
84 # Note: RemoteAppCaller is expected to return a tuple like the
85 # following one
85 # following one
86 return (['content'], '200 OK', [('Content-Type', 'text/plain')])
86 return (['content'], '200 OK', [('Content-Type', 'text/plain')])
87
87
88 wrapper_app = wsgi_app_caller_client.RemoteAppCaller(
88 wrapper_app = wsgi_app_caller_client.RemoteAppCaller(
89 RemoteAppCallerMock(), 'a1', 'a2', arg3='a3', arg4='a4')
89 RemoteAppCallerMock(), 'dummy-backend',
90 'a1', 'a2', arg3='a3', arg4='a4')
90
91
91 test_app = webtest.TestApp(wrapper_app)
92 test_app = webtest.TestApp(wrapper_app)
92
93
93 response = test_app.get('/path')
94 response = test_app.get('/path')
94
95
95 assert response.status == '200 OK'
96 assert response.status == '200 OK'
96 assert response.headers.items() == [
97 assert sorted(response.headers.items()) == sorted([
97 ('Content-Type', 'text/plain'), ('Content-Length', '7')]
98 ('X-RhodeCode-Backend', 'dummy-backend'),
99 ('Content-Type', 'text/plain'),
100 ('Content-Length', '7'),
101 ])
98 assert response.body == 'content'
102 assert response.body == 'content'
General Comments 0
You need to be logged in to leave comments. Login now