##// END OF EJS Templates
tests: Adapt tests to recent changes.
Martin Bornhold -
r612:47f28cf8 default
parent child Browse files
Show More
@@ -1,130 +1,130 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-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 import mock
22 22 import Pyro4
23 23 import pytest
24 24 import webtest
25 25
26 26 from rhodecode.lib.middleware.utils import scm_app_http, scm_app
27 27 from rhodecode.lib.vcs.conf import settings
28 28
29 29
30 30 def vcs_http_app(vcsserver_http_echo_app):
31 31 """
32 32 VcsHttpProxy wrapped in WebTest.
33 33 """
34 34 git_url = vcsserver_http_echo_app.http_url + 'stream/git/'
35 35 vcs_http_proxy = scm_app_http.VcsHttpProxy(
36 git_url, 'stub_path', 'stub_name', None)
36 git_url, 'stub_path', 'stub_name', None, 'stub_backend')
37 37 app = webtest.TestApp(vcs_http_proxy)
38 38 return app
39 39
40 40
41 41 @pytest.fixture(scope='module')
42 42 def vcsserver_http_echo_app(request, vcsserver_factory):
43 43 """
44 44 A running VCSServer with the EchoApp activated via HTTP.
45 45 """
46 46 vcsserver = vcsserver_factory(
47 47 request=request,
48 48 use_http=True,
49 49 overrides=[{'app:main': {'dev.use_echo_app': 'true'}}])
50 50 return vcsserver
51 51
52 52
53 53 @pytest.fixture(scope='session')
54 54 def data():
55 55 one_kb = "x" * 1024
56 56 return one_kb * 1024 * 10
57 57
58 58
59 59 def test_reuse_app_no_data(repeat, vcsserver_http_echo_app):
60 60 app = vcs_http_app(vcsserver_http_echo_app)
61 61 for x in xrange(repeat / 10):
62 62 response = app.post('/')
63 63 assert response.status_code == 200
64 64
65 65
66 66 def test_reuse_app_with_data(data, repeat, vcsserver_http_echo_app):
67 67 app = vcs_http_app(vcsserver_http_echo_app)
68 68 for x in xrange(repeat / 10):
69 69 response = app.post('/', params=data)
70 70 assert response.status_code == 200
71 71
72 72
73 73 def test_create_app_per_request_no_data(repeat, vcsserver_http_echo_app):
74 74 for x in xrange(repeat / 10):
75 75 app = vcs_http_app(vcsserver_http_echo_app)
76 76 response = app.post('/')
77 77 assert response.status_code == 200
78 78
79 79
80 80 def test_create_app_per_request_with_data(
81 81 data, repeat, vcsserver_http_echo_app):
82 82 for x in xrange(repeat / 10):
83 83 app = vcs_http_app(vcsserver_http_echo_app)
84 84 response = app.post('/', params=data)
85 85 assert response.status_code == 200
86 86
87 87
88 88 @pytest.fixture(scope='module')
89 89 def vcsserver_pyro_echo_app(request, vcsserver_factory):
90 90 """
91 91 A running VCSServer with the EchoApp activated via Pyro4.
92 92 """
93 93 vcsserver = vcsserver_factory(
94 94 request=request,
95 95 use_http=False,
96 96 overrides=[{'DEFAULT': {'dev.use_echo_app': 'true'}}])
97 97 return vcsserver
98 98
99 99
100 100 def vcs_pyro4_app(vcsserver_pyro_echo_app):
101 101 """
102 102 Pyro4 based Vcs proxy wrapped in WebTest
103 103 """
104 104 stub_config = {
105 105 'git_update_server_info': 'stub',
106 106 }
107 107 server_and_port = vcsserver_pyro_echo_app.server_and_port
108 108 GIT_REMOTE_WSGI = Pyro4.Proxy(
109 109 settings.pyro_remote(
110 110 settings.PYRO_GIT_REMOTE_WSGI, server_and_port))
111 111 with mock.patch('rhodecode.lib.middleware.utils.scm_app.GIT_REMOTE_WSGI',
112 112 GIT_REMOTE_WSGI):
113 113 pyro4_app = scm_app.create_git_wsgi_app(
114 114 'stub_path', 'stub_name', stub_config)
115 115 app = webtest.TestApp(pyro4_app)
116 116 return app
117 117
118 118
119 119 def test_pyro4_no_data(repeat, pylonsapp, vcsserver_pyro_echo_app):
120 120 for x in xrange(repeat / 10):
121 121 app = vcs_pyro4_app(vcsserver_pyro_echo_app)
122 122 response = app.post('/')
123 123 assert response.status_code == 200
124 124
125 125
126 126 def test_pyro4_with_data(repeat, pylonsapp, vcsserver_pyro_echo_app, data):
127 127 for x in xrange(repeat / 10):
128 128 app = vcs_pyro4_app(vcsserver_pyro_echo_app)
129 129 response = app.post('/', params=data)
130 130 assert response.status_code == 200
@@ -1,136 +1,136 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-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 """
22 22 Checking the chunked data transfer via HTTP
23 23 """
24 24
25 25 import os
26 26 import time
27 27 import subprocess
28 28
29 29 import pytest
30 30 import requests
31 31
32 32 from rhodecode.lib.middleware.utils import scm_app_http
33 33 from rhodecode.tests.utils import wait_for_url
34 34
35 35
36 36 def test_does_chunked_end_to_end_transfer(scm_app):
37 37 response = requests.post(scm_app, data='', stream=True)
38 38 assert response.headers['Transfer-Encoding'] == 'chunked'
39 39 times = [time.time() for chunk in response.raw.read_chunked()]
40 40 assert times[1] - times[0] > 0.1, "Chunks arrived at the same time"
41 41
42 42
43 43 @pytest.fixture
44 44 def echo_app_chunking(request, available_port_factory):
45 45 """
46 46 Run the EchoApp via Waitress in a subprocess.
47 47
48 48 Return the URL endpoint to reach the app.
49 49 """
50 50 port = available_port_factory()
51 51 command = (
52 52 'waitress-serve --send-bytes 1 --port {port} --call '
53 53 'rhodecode.tests.lib.middleware.utils.test_scm_app_http_chunking'
54 54 ':create_echo_app')
55 55 command = command.format(port=port)
56 56 proc = subprocess.Popen(command.split(' '), bufsize=0)
57 57 echo_app_url = 'http://localhost:' + str(port)
58 58
59 59 @request.addfinalizer
60 60 def stop_echo_app():
61 61 proc.kill()
62 62
63 63 return echo_app_url
64 64
65 65
66 66 @pytest.fixture
67 67 def scm_app(request, available_port_factory, echo_app_chunking):
68 68 """
69 69 Run the scm_app in Waitress.
70 70
71 71 Returns the URL endpoint where this app can be reached.
72 72 """
73 73 port = available_port_factory()
74 74 command = (
75 75 'waitress-serve --send-bytes 1 --port {port} --call '
76 76 'rhodecode.tests.lib.middleware.utils.test_scm_app_http_chunking'
77 77 ':create_scm_app')
78 78 command = command.format(port=port)
79 79 env = os.environ.copy()
80 80 env["RC_ECHO_URL"] = echo_app_chunking
81 81 proc = subprocess.Popen(command.split(' '), bufsize=0, env=env)
82 82 scm_app_url = 'http://localhost:' + str(port)
83 83 wait_for_url(scm_app_url)
84 84
85 85 @request.addfinalizer
86 86 def stop_echo_app():
87 87 proc.kill()
88 88
89 89 return scm_app_url
90 90
91 91
92 92 class EchoApp(object):
93 93 """
94 94 Stub WSGI application which returns a chunked response to every request.
95 95 """
96 96
97 97 def __init__(self, repo_path, repo_name, config):
98 98 self._repo_path = repo_path
99 99
100 100 def __call__(self, environ, start_response):
101 101 environ['wsgi.input'].read()
102 102 status = '200 OK'
103 103 headers = []
104 104 start_response(status, headers)
105 105 return result_generator()
106 106
107 107
108 108 def result_generator():
109 109 """
110 110 Simulate chunked results.
111 111
112 112 The intended usage is to simulate a chunked response as we would get it
113 113 out of a vcs operation during a call to "hg clone".
114 114 """
115 115 yield 'waiting 2 seconds'
116 116 # Wait long enough so that the first chunk can go out
117 117 time.sleep(2)
118 118 yield 'final chunk'
119 119 # Another small wait, otherwise they go together
120 120 time.sleep(0.1)
121 121
122 122
123 123 def create_echo_app():
124 124 """
125 125 Create EchoApp filled with stub data.
126 126 """
127 127 return EchoApp('stub_path', 'repo_name', {})
128 128
129 129
130 130 def create_scm_app():
131 131 """
132 132 Create a scm_app hooked up to speak to EchoApp.
133 133 """
134 134 echo_app_url = os.environ["RC_ECHO_URL"]
135 135 return scm_app_http.VcsHttpProxy(
136 echo_app_url, 'stub_path', 'stub_name', None)
136 echo_app_url, 'stub_path', 'stub_name', None, 'stub_backend')
General Comments 0
You need to be logged in to leave comments. Login now