mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
add test for choose services and related redirects to it
it'll just show the add service button if you only have archived services
This commit is contained in:
@@ -16,13 +16,13 @@ class ServiceAPIClient(BaseAPIClient):
|
|||||||
self.service_id = application.config['ADMIN_CLIENT_USER_NAME']
|
self.service_id = application.config['ADMIN_CLIENT_USER_NAME']
|
||||||
self.api_key = application.config['ADMIN_CLIENT_SECRET']
|
self.api_key = application.config['ADMIN_CLIENT_SECRET']
|
||||||
|
|
||||||
def create_service(self, service_name, active, message_limit, restricted, user_id, email_from):
|
def create_service(self, service_name, message_limit, restricted, user_id, email_from):
|
||||||
"""
|
"""
|
||||||
Create a service and return the json.
|
Create a service and return the json.
|
||||||
"""
|
"""
|
||||||
data = {
|
data = {
|
||||||
"name": service_name,
|
"name": service_name,
|
||||||
"active": active,
|
"active": True,
|
||||||
"message_limit": message_limit,
|
"message_limit": message_limit,
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"restricted": restricted,
|
"restricted": restricted,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import url_for, session
|
from flask import url_for
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_choose_services_page(app_,
|
def test_should_show_choose_services_page(app_,
|
||||||
@@ -18,13 +18,26 @@ def test_should_show_choose_services_page(app_,
|
|||||||
assert mock_get_services.called
|
assert mock_get_services.called
|
||||||
assert services['data'][0]['name'] in resp_data
|
assert services['data'][0]['name'] in resp_data
|
||||||
assert services['data'][1]['name'] in resp_data
|
assert services['data'][1]['name'] in resp_data
|
||||||
assert 'List all services' not in resp_data
|
|
||||||
|
|
||||||
|
def test_should_show_choose_services_page_if_no_services(
|
||||||
|
client,
|
||||||
|
mock_login,
|
||||||
|
api_user_active,
|
||||||
|
):
|
||||||
|
# if users last service has been archived there'll be no services
|
||||||
|
# mock_login already patches get_services to return no data
|
||||||
|
client.login(api_user_active)
|
||||||
|
response = client.get(url_for('main.choose_service'))
|
||||||
|
assert response.status_code == 200
|
||||||
|
resp_data = response.get_data(as_text=True)
|
||||||
|
assert 'Choose service' in resp_data
|
||||||
|
assert 'Add a new service' in resp_data
|
||||||
|
|
||||||
|
|
||||||
def test_redirect_if_only_one_service(
|
def test_redirect_if_only_one_service(
|
||||||
app_,
|
app_,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_get_user,
|
|
||||||
api_user_active,
|
api_user_active,
|
||||||
mock_get_services_with_one_service
|
mock_get_services_with_one_service
|
||||||
):
|
):
|
||||||
@@ -41,9 +54,7 @@ def test_redirect_if_only_one_service(
|
|||||||
def test_redirect_if_multiple_services(
|
def test_redirect_if_multiple_services(
|
||||||
app_,
|
app_,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_get_user,
|
|
||||||
api_user_active,
|
api_user_active,
|
||||||
mock_get_services
|
|
||||||
):
|
):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
@@ -57,7 +68,6 @@ def test_redirect_if_multiple_services(
|
|||||||
def test_redirect_if_service_in_session(
|
def test_redirect_if_service_in_session(
|
||||||
app_,
|
app_,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_get_user,
|
|
||||||
api_user_active,
|
api_user_active,
|
||||||
mock_get_services,
|
mock_get_services,
|
||||||
mock_get_service
|
mock_get_service
|
||||||
|
|||||||
@@ -12,15 +12,9 @@ def test_render_sign_in_returns_sign_in_template(app_):
|
|||||||
assert 'Forgot your password?' in response.get_data(as_text=True)
|
assert 'Forgot your password?' in response.get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
def test_logged_in_user_redirects_to_choose_service(app_,
|
def test_logged_in_user_redirects_to_choose_service(logged_in_client):
|
||||||
api_user_active,
|
response = logged_in_client.get(url_for('main.sign_in'))
|
||||||
mock_get_user):
|
assert response.location == url_for('main.choose_service', _external=True)
|
||||||
|
|
||||||
with app_.test_request_context():
|
|
||||||
with app_.test_client() as client:
|
|
||||||
client.login(api_user_active)
|
|
||||||
response = client.get(url_for('main.sign_in'))
|
|
||||||
assert response.location == url_for('main.choose_service', _external=True)
|
|
||||||
|
|
||||||
|
|
||||||
def test_process_sign_in_return_2fa_template(app_,
|
def test_process_sign_in_return_2fa_template(app_,
|
||||||
@@ -88,24 +82,44 @@ def test_should_attempt_redirect_when_user_is_pending(app_,
|
|||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
|
|
||||||
|
|
||||||
def test_not_fresh_session_login(app_,
|
def test_not_fresh_session_login_redirects_to_dashboard(
|
||||||
api_user_active,
|
client,
|
||||||
mock_login,
|
api_user_active,
|
||||||
mock_get_user_by_email,
|
mock_login,
|
||||||
mock_verify_password,
|
mock_get_user_by_email,
|
||||||
mock_get_services_with_one_service):
|
mock_verify_password,
|
||||||
with app_.test_request_context():
|
mock_get_services_with_one_service
|
||||||
with app_.test_client() as client:
|
):
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
with client.session_transaction() as session:
|
with client.session_transaction() as session:
|
||||||
assert session['_fresh']
|
assert session['_fresh']
|
||||||
session['_fresh'] = False
|
session['_fresh'] = False
|
||||||
# This should skip the two factor
|
# This should skip the two factor
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_for('main.sign_in'), data={
|
url_for('main.sign_in'), data={
|
||||||
'email_address': api_user_active.email_address,
|
'email_address': api_user_active.email_address,
|
||||||
'password': 'val1dPassw0rd!'})
|
'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)
|
||||||
|
|
||||||
|
def test_not_fresh_session_login_redirects_to_choose_service(
|
||||||
|
client,
|
||||||
|
api_user_active,
|
||||||
|
mock_login,
|
||||||
|
mock_get_user_by_email,
|
||||||
|
mock_verify_password,
|
||||||
|
mock_get_services
|
||||||
|
):
|
||||||
|
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
|
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.choose_service', _external=True)
|
||||||
assert response.location == url_for(
|
|
||||||
'main.service_dashboard', service_id=service_dct['id'], _external=True)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user