Remember me functionality added and tested.

Merge extra.

Fixed comment.
This commit is contained in:
Nicholas Staples
2016-02-23 15:45:19 +00:00
committed by Adam Shimali
parent bcf21f5ab2
commit c959678c49
11 changed files with 118 additions and 15 deletions

View File

@@ -90,3 +90,26 @@ def test_should_return_redirect_when_user_is_pending(app_,
'password': 'val1dPassw0rd!'})
assert response.status_code == 302
assert response.location == url_for('main.verify', _external=True)
def test_not_fresh_session_login(app_,
api_user_active,
mock_login,
mock_get_user_by_email,
mock_verify_password,
mock_get_services_with_one_service):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
with client.session_transaction() as session:
assert session['_fresh']
session['_fresh'] = False
# This should skip the two factor
response = client.post(
url_for('main.sign_in'), data={
'email_address': api_user_active.email_address,
'password': 'val1dPassw0rd!'})
assert response.status_code == 302
service_dct = mock_get_services_with_one_service(api_user_active.id)['data'][0]
assert response.location == url_for(
'main.service_dashboard', service_id=service_dct['id'], _external=True)

View File

@@ -7,7 +7,7 @@ def test_render_sign_out_redirects_to_sign_in(app_):
url_for('main.sign_out'))
assert response.status_code == 302
assert response.location == url_for(
'main.sign_in', _external=True, next=url_for('main.sign_out'))
'main.sign_in', _external=True)
def test_sign_out_user(app_,
@@ -22,9 +22,9 @@ def test_sign_out_user(app_,
email = 'valid@example.gov.uk'
password = 'val1dPassw0rd!'
with app_.test_client() as client:
with client.session_transaction() as session:
print('session: {}'.format(session))
client.login(api_user_active)
with client.session_transaction() as session:
assert session.get('user_id') is not None
# Check we are logged in
response = client.get(
url_for('main.service_dashboard', service_id="123"))
@@ -32,5 +32,6 @@ def test_sign_out_user(app_,
response = client.get(url_for('main.sign_out'))
assert response.status_code == 302
assert response.location == url_for(
'main.index', _external=True)
assert session.get('ItsdangerousSession') is None
'main.sign_in', _external=True)
with client.session_transaction() as session:
assert session.get('user_id') is None

View File

@@ -92,3 +92,20 @@ def test_should_login_user_when_multiple_valid_codes_exist(app_,
response = client.post(url_for('main.two_factor'),
data={'sms_code': '23456'})
assert response.status_code == 302
def test_remember_me_set(app_,
api_user_active,
mock_get_user,
mock_get_user_by_email,
mock_check_verify_code,
mock_get_services_with_one_service):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
session['user_details'] = {
'id': api_user_active.id,
'email': api_user_active.email_address}
response = client.post(url_for('main.two_factor'),
data={'sms_code': '23456', 'remember_me': True})
assert response.status_code == 302