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.
This commit is contained in:
Johannes Bornhold 2016-05-25 16:50:48 +02:00
parent 9f6ff5bd02
commit 6a540aa6fa
2 changed files with 19 additions and 4 deletions

View file

@ -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):

View file

@ -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']