Files
notifications-admin/tests/app/main/views/test_sign_out.py

43 lines
1.5 KiB
Python
Raw Normal View History

2016-01-06 16:40:38 +00:00
from datetime import datetime
from flask import url_for
from app.main.dao import users_dao
from app.models import User
from .test_sign_in import _set_up_mocker
2016-01-15 15:15:35 +00:00
def test_render_sign_out_redirects_to_sign_in(app_):
with app_.test_request_context():
response = app_.test_client().get(
2016-01-06 16:40:38 +00:00
url_for('main.sign_out'))
assert response.status_code == 302
assert response.location == url_for(
2016-01-06 17:17:02 +00:00
'main.sign_in', _external=True, next=url_for('main.sign_out'))
2016-01-06 16:40:38 +00:00
2016-01-15 15:15:35 +00:00
def test_sign_out_user(app_,
db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
2016-01-06 16:40:38 +00:00
email = 'valid@example.gov.uk'
password = 'val1dPassw0rd!'
user = User(email_address=email,
password=password,
mobile_number='+441234123123',
name='valid',
created_at=datetime.now(),
role_id=1,
state='active')
users_dao.insert_user(user)
2016-01-15 15:15:35 +00:00
with app_.test_client() as client:
2016-01-06 16:40:38 +00:00
client.login(user)
# Check we are logged in
response = client.get('/services/123/dashboard')
2016-01-06 16:40:38 +00:00
assert response.status_code == 200
response = client.get(url_for('main.sign_out'))
assert response.status_code == 302
assert response.location == url_for(
'main.index', _external=True)