# HG changeset patch # User Marcin Kuzminski # Date 2017-11-17 15:26:55 # Node ID e331d3e69fc1215a9a3eec1f45cb1c8fc65b7bc6 # Parent 82ef66953fbdf720658a70e3d6240c34dc82e58b testapp: moved login/csrf session methods into TestApp itself. - this allows easier control over which app is responsible for session handling. This comes in handy in CE vs EE test where EE get's a custom app. diff --git a/rhodecode/tests/utils.py b/rhodecode/tests/utils.py --- a/rhodecode/tests/utils.py +++ b/rhodecode/tests/utils.py @@ -42,7 +42,7 @@ from rhodecode.model.meta import Session from rhodecode.model.scm import ScmModel from rhodecode.lib.vcs.backends.svn.repository import SubversionRepository from rhodecode.lib.vcs.backends.base import EmptyCommit - +from rhodecode.tests import login_user_session log = logging.getLogger(__name__) @@ -72,7 +72,7 @@ class CustomTestResponse(TestResponse): no = [] if kw: raise TypeError( - "The only keyword argument allowed is 'no'") + "The only keyword argument allowed is 'no' got %s" % kw) f = self._save_output(str(self)) @@ -118,9 +118,27 @@ class TestRequest(webob.BaseRequest): class CustomTestApp(TestApp): """ - Custom app to make mustcontain more usefull + Custom app to make mustcontain more usefull, and extract special methods """ RequestClass = TestRequest + rc_login_data = {} + rc_current_session = None + + def login(self, username=None, password=None): + from rhodecode.lib import auth + + if username and password: + session = login_user_session(self, username, password) + else: + session = login_user_session(self) + + self.rc_login_data['csrf_token'] = auth.get_csrf_token(session) + self.rc_current_session = session + return session['rhodecode_user'] + + @property + def csrf_token(self): + return self.rc_login_data['csrf_token'] def set_anonymous_access(enabled):