##// 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 38 from pylons.util import ContextObj
39 39
40 40 from routes.util import URLGenerator
41 from webtest import TestApp
42 41 from nose.plugins.skip import SkipTest
43 42 import pytest
44 43
@@ -21,15 +21,15 b''
21 21 import wsgiref.simple_server
22 22
23 23 import pytest
24 import webtest
25 24
25 from rhodecode.tests.utils import CustomTestApp
26 26 from rhodecode.lib.middleware import csrf
27 27
28 28
29 29 def test_origin_checker_no_origin():
30 30 app = csrf.OriginChecker(
31 31 wsgiref.simple_server.demo_app, 'https://safe.org')
32 app = webtest.TestApp(app)
32 app = CustomTestApp(app)
33 33
34 34 app.post('/foo')
35 35
@@ -37,7 +37,7 b' def test_origin_checker_no_origin():'
37 37 def test_origin_checker_null_origin():
38 38 app = csrf.OriginChecker(
39 39 wsgiref.simple_server.demo_app, 'https://safe.org')
40 app = webtest.TestApp(app)
40 app = CustomTestApp(app)
41 41
42 42 app.post('/foo', headers={'Origin': 'null'})
43 43
@@ -50,7 +50,7 b' def test_origin_checker_null_origin():'
50 50 def test_origin_checker_valid_origin(origin):
51 51 app = csrf.OriginChecker(
52 52 wsgiref.simple_server.demo_app, 'http://safe.org')
53 app = webtest.TestApp(app)
53 app = CustomTestApp(app)
54 54
55 55 app.post('/foo', headers={'Origin': origin})
56 56
@@ -63,7 +63,7 b' def test_origin_checker_valid_origin(ori'
63 63 def test_origin_checker_valid_origin_https(origin):
64 64 app = csrf.OriginChecker(
65 65 wsgiref.simple_server.demo_app, 'https://safe.org')
66 app = webtest.TestApp(app)
66 app = CustomTestApp(app)
67 67
68 68 app.post('/foo', headers={'Origin': origin})
69 69
@@ -76,7 +76,7 b' def test_origin_checker_valid_origin_htt'
76 76 def test_origin_checker_invalid_origin(origin):
77 77 app = csrf.OriginChecker(
78 78 wsgiref.simple_server.demo_app, 'https://safe.org')
79 app = webtest.TestApp(app)
79 app = CustomTestApp(app)
80 80
81 81 app.post('/foo', headers={'Origin': origin}, status=403)
82 82
@@ -84,6 +84,6 b' def test_origin_checker_invalid_origin(o'
84 84 def test_origin_checker_invalid_origin_skipped_url():
85 85 app = csrf.OriginChecker(
86 86 wsgiref.simple_server.demo_app, 'https://safe.org', skip_urls=['/foo'])
87 app = webtest.TestApp(app)
87 app = CustomTestApp(app)
88 88
89 89 app.post('/foo', headers={'Origin': 'http://www.evil.org'})
@@ -22,7 +22,8 b' import base64'
22 22
23 23 import mock
24 24 import pytest
25 import webtest.app
25
26 from rhodecode.tests.utils import CustomTestApp
26 27
27 28 from rhodecode.lib.caching_query import FromCache
28 29 from rhodecode.lib.hooks_daemon import DummyHooksCallbackDaemon
@@ -72,7 +73,7 b' def vcscontroller(pylonsapp, config_stub'
72 73 set_anonymous_access(True)
73 74 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
74 75 app = HttpsFixup(controller, pylonsapp.config)
75 app = webtest.app.TestApp(app)
76 app = CustomTestApp(app)
76 77
77 78 _remove_default_user_from_query_cache()
78 79
@@ -137,7 +138,7 b' class StubFailVCSController(simplevcs.Si'
137 138 def fail_controller(pylonsapp):
138 139 controller = StubFailVCSController(pylonsapp, pylonsapp.config, None)
139 140 controller = HttpsFixup(controller, pylonsapp.config)
140 controller = webtest.app.TestApp(controller)
141 controller = CustomTestApp(controller)
141 142 return controller
142 143
143 144
@@ -21,8 +21,8 b''
21 21 import mock
22 22 import Pyro4
23 23 import pytest
24 import webtest
25 24
25 from rhodecode.tests.utils import CustomTestApp
26 26 from rhodecode.lib.middleware.utils import scm_app_http, scm_app
27 27 from rhodecode.lib.vcs.conf import settings
28 28
@@ -34,7 +34,7 b' def vcs_http_app(vcsserver_http_echo_app'
34 34 git_url = vcsserver_http_echo_app.http_url + 'stream/git/'
35 35 vcs_http_proxy = scm_app_http.VcsHttpProxy(
36 36 git_url, 'stub_path', 'stub_name', None)
37 app = webtest.TestApp(vcs_http_proxy)
37 app = CustomTestApp(vcs_http_proxy)
38 38 return app
39 39
40 40
@@ -112,7 +112,7 b' def vcs_pyro4_app(vcsserver_pyro_echo_ap'
112 112 GIT_REMOTE_WSGI):
113 113 pyro4_app = scm_app.create_git_wsgi_app(
114 114 'stub_path', 'stub_name', stub_config)
115 app = webtest.TestApp(pyro4_app)
115 app = CustomTestApp(pyro4_app)
116 116 return app
117 117
118 118
@@ -18,8 +18,7 b''
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 import webtest
22
21 from rhodecode.tests.utils import CustomTestApp
23 22 from rhodecode.lib.middleware.utils import wsgi_app_caller_client
24 23
25 24 # pylint: disable=protected-access,too-many-public-methods
@@ -88,7 +87,7 b' def test_remote_app_caller():'
88 87 wrapper_app = wsgi_app_caller_client.RemoteAppCaller(
89 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 92 response = test_app.get('/path')
94 93
@@ -35,7 +35,6 b' import pyramid.testing'
35 35 import pytest
36 36 import colander
37 37 import requests
38 from webtest.app import TestApp
39 38
40 39 import rhodecode
41 40 from rhodecode.lib.utils2 import AttributeDict
@@ -62,6 +61,7 b' from rhodecode.tests import ('
62 61 login_user_session, get_new_dir, utils, TESTS_TMP_PATH,
63 62 TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR2_LOGIN,
64 63 TEST_USER_REGULAR_PASS)
64 from rhodecode.tests.utils import CustomTestApp
65 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 212 @pytest.fixture(scope='function')
213 213 def app(request, pylonsapp, http_environ):
214 app = TestApp(
214
215
216 app = CustomTestApp(
215 217 pylonsapp,
216 218 extra_environ=http_environ)
217 219 if request.cls:
@@ -23,14 +23,18 b' import time'
23 23 import logging
24 24 import os.path
25 25 import subprocess32
26 import tempfile
26 27 import urllib2
27 28 from urlparse import urlparse, parse_qsl
28 29 from urllib import unquote_plus
29 30
31 from webtest.app import (
32 Request, TestResponse, TestApp, print_stderr, string_types)
33
30 34 import pytest
31 35 import rc_testdata
32 36
33 from rhodecode.model.db import User
37 from rhodecode.model.db import User, Repository
34 38 from rhodecode.model.meta import Session
35 39 from rhodecode.model.scm import ScmModel
36 40 from rhodecode.lib.vcs.backends.svn.repository import SubversionRepository
@@ -39,6 +43,72 b' from rhodecode.lib.vcs.backends.svn.repo'
39 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 112 def set_anonymous_access(enabled):
43 113 """(Dis)allows anonymous access depending on parameter `enabled`"""
44 114 user = User.get_default_user()
General Comments 0
You need to be logged in to leave comments. Login now