##// END OF EJS Templates
tests: use custom test app for better debug of .mustcontain function....
marcink -
r1256:c3a5baac default
parent child Browse files
Show More
@@ -38,7 +38,6 b' from pylons.i18n.translation import _get'
38 from pylons.util import ContextObj
38 from pylons.util import ContextObj
39
39
40 from routes.util import URLGenerator
40 from routes.util import URLGenerator
41 from webtest import TestApp
42 from nose.plugins.skip import SkipTest
41 from nose.plugins.skip import SkipTest
43 import pytest
42 import pytest
44
43
@@ -21,15 +21,15 b''
21 import wsgiref.simple_server
21 import wsgiref.simple_server
22
22
23 import pytest
23 import pytest
24 import webtest
25
24
25 from rhodecode.tests.utils import CustomTestApp
26 from rhodecode.lib.middleware import csrf
26 from rhodecode.lib.middleware import csrf
27
27
28
28
29 def test_origin_checker_no_origin():
29 def test_origin_checker_no_origin():
30 app = csrf.OriginChecker(
30 app = csrf.OriginChecker(
31 wsgiref.simple_server.demo_app, 'https://safe.org')
31 wsgiref.simple_server.demo_app, 'https://safe.org')
32 app = webtest.TestApp(app)
32 app = CustomTestApp(app)
33
33
34 app.post('/foo')
34 app.post('/foo')
35
35
@@ -37,7 +37,7 b' def test_origin_checker_no_origin():'
37 def test_origin_checker_null_origin():
37 def test_origin_checker_null_origin():
38 app = csrf.OriginChecker(
38 app = csrf.OriginChecker(
39 wsgiref.simple_server.demo_app, 'https://safe.org')
39 wsgiref.simple_server.demo_app, 'https://safe.org')
40 app = webtest.TestApp(app)
40 app = CustomTestApp(app)
41
41
42 app.post('/foo', headers={'Origin': 'null'})
42 app.post('/foo', headers={'Origin': 'null'})
43
43
@@ -50,7 +50,7 b' def test_origin_checker_null_origin():'
50 def test_origin_checker_valid_origin(origin):
50 def test_origin_checker_valid_origin(origin):
51 app = csrf.OriginChecker(
51 app = csrf.OriginChecker(
52 wsgiref.simple_server.demo_app, 'http://safe.org')
52 wsgiref.simple_server.demo_app, 'http://safe.org')
53 app = webtest.TestApp(app)
53 app = CustomTestApp(app)
54
54
55 app.post('/foo', headers={'Origin': origin})
55 app.post('/foo', headers={'Origin': origin})
56
56
@@ -63,7 +63,7 b' def test_origin_checker_valid_origin(ori'
63 def test_origin_checker_valid_origin_https(origin):
63 def test_origin_checker_valid_origin_https(origin):
64 app = csrf.OriginChecker(
64 app = csrf.OriginChecker(
65 wsgiref.simple_server.demo_app, 'https://safe.org')
65 wsgiref.simple_server.demo_app, 'https://safe.org')
66 app = webtest.TestApp(app)
66 app = CustomTestApp(app)
67
67
68 app.post('/foo', headers={'Origin': origin})
68 app.post('/foo', headers={'Origin': origin})
69
69
@@ -76,7 +76,7 b' def test_origin_checker_valid_origin_htt'
76 def test_origin_checker_invalid_origin(origin):
76 def test_origin_checker_invalid_origin(origin):
77 app = csrf.OriginChecker(
77 app = csrf.OriginChecker(
78 wsgiref.simple_server.demo_app, 'https://safe.org')
78 wsgiref.simple_server.demo_app, 'https://safe.org')
79 app = webtest.TestApp(app)
79 app = CustomTestApp(app)
80
80
81 app.post('/foo', headers={'Origin': origin}, status=403)
81 app.post('/foo', headers={'Origin': origin}, status=403)
82
82
@@ -84,6 +84,6 b' def test_origin_checker_invalid_origin(o'
84 def test_origin_checker_invalid_origin_skipped_url():
84 def test_origin_checker_invalid_origin_skipped_url():
85 app = csrf.OriginChecker(
85 app = csrf.OriginChecker(
86 wsgiref.simple_server.demo_app, 'https://safe.org', skip_urls=['/foo'])
86 wsgiref.simple_server.demo_app, 'https://safe.org', skip_urls=['/foo'])
87 app = webtest.TestApp(app)
87 app = CustomTestApp(app)
88
88
89 app.post('/foo', headers={'Origin': 'http://www.evil.org'})
89 app.post('/foo', headers={'Origin': 'http://www.evil.org'})
@@ -22,7 +22,8 b' import base64'
22
22
23 import mock
23 import mock
24 import pytest
24 import pytest
25 import webtest.app
25
26 from rhodecode.tests.utils import CustomTestApp
26
27
27 from rhodecode.lib.caching_query import FromCache
28 from rhodecode.lib.caching_query import FromCache
28 from rhodecode.lib.hooks_daemon import DummyHooksCallbackDaemon
29 from rhodecode.lib.hooks_daemon import DummyHooksCallbackDaemon
@@ -72,7 +73,7 b' def vcscontroller(pylonsapp, config_stub'
72 set_anonymous_access(True)
73 set_anonymous_access(True)
73 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
74 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
74 app = HttpsFixup(controller, pylonsapp.config)
75 app = HttpsFixup(controller, pylonsapp.config)
75 app = webtest.app.TestApp(app)
76 app = CustomTestApp(app)
76
77
77 _remove_default_user_from_query_cache()
78 _remove_default_user_from_query_cache()
78
79
@@ -137,7 +138,7 b' class StubFailVCSController(simplevcs.Si'
137 def fail_controller(pylonsapp):
138 def fail_controller(pylonsapp):
138 controller = StubFailVCSController(pylonsapp, pylonsapp.config, None)
139 controller = StubFailVCSController(pylonsapp, pylonsapp.config, None)
139 controller = HttpsFixup(controller, pylonsapp.config)
140 controller = HttpsFixup(controller, pylonsapp.config)
140 controller = webtest.app.TestApp(controller)
141 controller = CustomTestApp(controller)
141 return controller
142 return controller
142
143
143
144
@@ -21,8 +21,8 b''
21 import mock
21 import mock
22 import Pyro4
22 import Pyro4
23 import pytest
23 import pytest
24 import webtest
25
24
25 from rhodecode.tests.utils import CustomTestApp
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.vcs.conf import settings
27 from rhodecode.lib.vcs.conf import settings
28
28
@@ -34,7 +34,7 b' def vcs_http_app(vcsserver_http_echo_app'
34 git_url = vcsserver_http_echo_app.http_url + 'stream/git/'
34 git_url = vcsserver_http_echo_app.http_url + 'stream/git/'
35 vcs_http_proxy = scm_app_http.VcsHttpProxy(
35 vcs_http_proxy = scm_app_http.VcsHttpProxy(
36 git_url, 'stub_path', 'stub_name', None)
36 git_url, 'stub_path', 'stub_name', None)
37 app = webtest.TestApp(vcs_http_proxy)
37 app = CustomTestApp(vcs_http_proxy)
38 return app
38 return app
39
39
40
40
@@ -112,7 +112,7 b' def vcs_pyro4_app(vcsserver_pyro_echo_ap'
112 GIT_REMOTE_WSGI):
112 GIT_REMOTE_WSGI):
113 pyro4_app = scm_app.create_git_wsgi_app(
113 pyro4_app = scm_app.create_git_wsgi_app(
114 'stub_path', 'stub_name', stub_config)
114 'stub_path', 'stub_name', stub_config)
115 app = webtest.TestApp(pyro4_app)
115 app = CustomTestApp(pyro4_app)
116 return app
116 return app
117
117
118
118
@@ -18,8 +18,7 b''
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 from rhodecode.tests.utils import CustomTestApp
22
23 from rhodecode.lib.middleware.utils import wsgi_app_caller_client
22 from rhodecode.lib.middleware.utils import wsgi_app_caller_client
24
23
25 # pylint: disable=protected-access,too-many-public-methods
24 # pylint: disable=protected-access,too-many-public-methods
@@ -88,7 +87,7 b' def test_remote_app_caller():'
88 wrapper_app = wsgi_app_caller_client.RemoteAppCaller(
87 wrapper_app = wsgi_app_caller_client.RemoteAppCaller(
89 RemoteAppCallerMock(), 'a1', 'a2', arg3='a3', arg4='a4')
88 RemoteAppCallerMock(), 'a1', 'a2', arg3='a3', arg4='a4')
90
89
91 test_app = webtest.TestApp(wrapper_app)
90 test_app = CustomTestApp(wrapper_app)
92
91
93 response = test_app.get('/path')
92 response = test_app.get('/path')
94
93
@@ -35,7 +35,6 b' import pyramid.testing'
35 import pytest
35 import pytest
36 import colander
36 import colander
37 import requests
37 import requests
38 from webtest.app import TestApp
39
38
40 import rhodecode
39 import rhodecode
41 from rhodecode.lib.utils2 import AttributeDict
40 from rhodecode.lib.utils2 import AttributeDict
@@ -62,6 +61,7 b' from rhodecode.tests import ('
62 login_user_session, get_new_dir, utils, TESTS_TMP_PATH,
61 login_user_session, get_new_dir, utils, TESTS_TMP_PATH,
63 TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR2_LOGIN,
62 TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR2_LOGIN,
64 TEST_USER_REGULAR_PASS)
63 TEST_USER_REGULAR_PASS)
64 from rhodecode.tests.utils import CustomTestApp
65 from rhodecode.tests.fixture import Fixture
65 from rhodecode.tests.fixture import Fixture
66
66
67
67
@@ -211,7 +211,9 b' def http_environ(http_host_stub):'
211
211
212 @pytest.fixture(scope='function')
212 @pytest.fixture(scope='function')
213 def app(request, pylonsapp, http_environ):
213 def app(request, pylonsapp, http_environ):
214 app = TestApp(
214
215
216 app = CustomTestApp(
215 pylonsapp,
217 pylonsapp,
216 extra_environ=http_environ)
218 extra_environ=http_environ)
217 if request.cls:
219 if request.cls:
@@ -23,14 +23,18 b' import time'
23 import logging
23 import logging
24 import os.path
24 import os.path
25 import subprocess32
25 import subprocess32
26 import tempfile
26 import urllib2
27 import urllib2
27 from urlparse import urlparse, parse_qsl
28 from urlparse import urlparse, parse_qsl
28 from urllib import unquote_plus
29 from urllib import unquote_plus
29
30
31 from webtest.app import (
32 Request, TestResponse, TestApp, print_stderr, string_types)
33
30 import pytest
34 import pytest
31 import rc_testdata
35 import rc_testdata
32
36
33 from rhodecode.model.db import User
37 from rhodecode.model.db import User, Repository
34 from rhodecode.model.meta import Session
38 from rhodecode.model.meta import Session
35 from rhodecode.model.scm import ScmModel
39 from rhodecode.model.scm import ScmModel
36 from rhodecode.lib.vcs.backends.svn.repository import SubversionRepository
40 from rhodecode.lib.vcs.backends.svn.repository import SubversionRepository
@@ -39,6 +43,72 b' from rhodecode.lib.vcs.backends.svn.repo'
39 log = logging.getLogger(__name__)
43 log = logging.getLogger(__name__)
40
44
41
45
46 class CustomTestResponse(TestResponse):
47 def _save_output(self, out):
48 f = tempfile.NamedTemporaryFile(
49 delete=False, prefix='rc-test-', suffix='.html')
50 f.write(out)
51 return f.name
52
53 def mustcontain(self, *strings, **kw):
54 """
55 Assert that the response contains all of the strings passed
56 in as arguments.
57
58 Equivalent to::
59
60 assert string in res
61 """
62 if 'no' in kw:
63 no = kw['no']
64 del kw['no']
65 if isinstance(no, string_types):
66 no = [no]
67 else:
68 no = []
69 if kw:
70 raise TypeError(
71 "The only keyword argument allowed is 'no'")
72
73 f = self._save_output(str(self))
74
75 for s in strings:
76 if not s in self:
77 print_stderr("Actual response (no %r):" % s)
78 print_stderr(str(self))
79 raise IndexError(
80 "Body does not contain string %r, output saved as %s" % (
81 s, f))
82
83 for no_s in no:
84 if no_s in self:
85 print_stderr("Actual response (has %r)" % no_s)
86 print_stderr(str(self))
87 raise IndexError(
88 "Body contains bad string %r, output saved as %s" % (
89 no_s, f))
90
91 def assert_response(self):
92 return AssertResponse(self)
93
94
95 class TestRequest(Request):
96
97 # for py.test
98 disabled = True
99 ResponseClass = CustomTestResponse
100
101
102 class CustomTestApp(TestApp):
103 """
104 Custom app to make mustcontain more usefull
105 """
106 RequestClass = TestRequest
107
108
109
110
111
42 def set_anonymous_access(enabled):
112 def set_anonymous_access(enabled):
43 """(Dis)allows anonymous access depending on parameter `enabled`"""
113 """(Dis)allows anonymous access depending on parameter `enabled`"""
44 user = User.get_default_user()
114 user = User.get_default_user()
General Comments 0
You need to be logged in to leave comments. Login now