2016-01-05 17:08:50 +00:00
|
|
|
|
from flask import json, url_for
|
2016-01-27 12:22:32 +00:00
|
|
|
|
from app.main.dao import users_dao
|
2016-01-19 22:47:42 +00:00
|
|
|
|
from tests import create_test_api_user
|
|
|
|
|
|
|
|
|
|
|
|
import pytest
|
2015-12-04 16:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-27 12:22:32 +00:00
|
|
|
|
def test_should_return_verify_template(app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_send_verify_code):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-05 17:08:50 +00:00
|
|
|
|
# TODO this lives here until we work out how to
|
|
|
|
|
|
# reassign the session after it is lost mid register process
|
|
|
|
|
|
with client.session_transaction() as session:
|
2016-01-27 12:22:32 +00:00
|
|
|
|
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
2016-01-05 17:08:50 +00:00
|
|
|
|
response = client.get(url_for('main.verify'))
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
assert (
|
2016-02-02 13:38:39 +00:00
|
|
|
|
"We’ve sent you confirmation codes by email and text message."
|
2016-02-02 15:41:54 +00:00
|
|
|
|
) in response.get_data(as_text=True)
|
2015-12-04 17:10:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
|
def test_should_redirect_to_add_service_when_code_are_correct(app_,
|
2016-01-27 12:22:32 +00:00
|
|
|
|
api_user_active,
|
2016-01-23 23:14:50 +00:00
|
|
|
|
mock_get_user,
|
2016-01-27 16:30:33 +00:00
|
|
|
|
mock_update_user,
|
2016-01-27 12:22:32 +00:00
|
|
|
|
mock_check_verify_code):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-05 17:08:50 +00:00
|
|
|
|
with client.session_transaction() as session:
|
2016-01-27 12:22:32 +00:00
|
|
|
|
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
2016-01-05 17:08:50 +00:00
|
|
|
|
response = client.post(url_for('main.verify'),
|
|
|
|
|
|
data={'sms_code': '12345',
|
|
|
|
|
|
'email_code': '23456'})
|
|
|
|
|
|
assert response.status_code == 302
|
2016-01-18 10:47:53 +00:00
|
|
|
|
assert response.location == url_for('main.add_service', first='first', _external=True)
|
2015-12-04 17:10:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-27 16:30:33 +00:00
|
|
|
|
def test_should_activate_user_after_verify(app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_send_verify_code,
|
|
|
|
|
|
mock_check_verify_code,
|
|
|
|
|
|
mock_update_user):
|
2016-01-23 23:14:50 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
with client.session_transaction() as session:
|
2016-01-27 16:30:33 +00:00
|
|
|
|
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
2016-01-23 23:14:50 +00:00
|
|
|
|
client.post(url_for('main.verify'),
|
|
|
|
|
|
data={'sms_code': '12345',
|
|
|
|
|
|
'email_code': '23456'})
|
2016-01-27 16:30:33 +00:00
|
|
|
|
assert mock_update_user.called
|
2015-12-07 16:08:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-27 12:22:32 +00:00
|
|
|
|
def test_should_return_200_when_codes_are_wrong(app_,
|
|
|
|
|
|
api_user_active,
|
2016-01-27 16:30:33 +00:00
|
|
|
|
mock_get_user,
|
2016-01-27 12:22:32 +00:00
|
|
|
|
mock_check_verify_code_code_not_found):
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-05 17:08:50 +00:00
|
|
|
|
with client.session_transaction() as session:
|
2016-01-27 12:22:32 +00:00
|
|
|
|
session['user_details'] = {'email_address': api_user_active.email_address, 'id': api_user_active.id}
|
2016-01-05 17:08:50 +00:00
|
|
|
|
response = client.post(url_for('main.verify'),
|
|
|
|
|
|
data={'sms_code': '12345',
|
|
|
|
|
|
'email_code': '23456'})
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
resp_data = response.get_data(as_text=True)
|
2016-01-27 12:22:32 +00:00
|
|
|
|
assert resp_data.count('Code not found') == 2
|