From 6a540aa6fa5afc2dbe9b11d91ac3acab0935e4b8 Mon Sep 17 00:00:00 2001 From: Johannes Bornhold Date: Wed, 25 May 2016 16:50:48 +0200 Subject: [PATCH] pytest: Fix the user login function. - Pyramid doesn't expose the session as pylons does it as `response.session` - Therefore we have to look it up in the environ. --- rhodecode/tests/__init__.py | 13 +++++++++---- rhodecode/tests/utils.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rhodecode/tests/__init__.py b/rhodecode/tests/__init__.py index 9228ce47..e89a6bd2 100644 --- a/rhodecode/tests/__init__.py +++ b/rhodecode/tests/__init__.py @@ -49,6 +49,7 @@ from rhodecode.model.db import User from rhodecode.lib import auth from rhodecode.lib.helpers import flash, link_to from rhodecode.lib.utils2 import safe_unicode, safe_str +from rhodecode.tests.utils import get_session_from_response # TODO: johbo: Solve time zone related issues and remove this tweak os.environ['TZ'] = 'UTC' @@ -186,12 +187,16 @@ def login_user_session( pytest.fail('could not login using %s %s' % (username, password)) assert response.status == '302 Found' - ses = response.session['rhodecode_user'] - assert ses.get('username') == username response = response.follow() - assert ses.get('is_authenticated') + assert response.status == '200 OK' - return response.session + session = get_session_from_response(response) + assert 'rhodecode_user' in session + rc_user = session['rhodecode_user'] + assert rc_user.get('username') == username + assert rc_user.get('is_authenticated') + + return session def logout_user_session(app, csrf_token): diff --git a/rhodecode/tests/utils.py b/rhodecode/tests/utils.py index f9919918..49329dc3 100644 --- a/rhodecode/tests/utils.py +++ b/rhodecode/tests/utils.py @@ -270,3 +270,13 @@ def is_url_reachable(url): except urllib2.URLError: return False return True + + +def get_session_from_response(response): + """ + This returns the session from a response object. Pylons has some magic + to make the session available as `response.session`. But pyramid + doesn't expose it. + """ + # TODO: Try to look up the session key also. + return response.request.environ['beaker.session']