mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 18:37:33 -04:00
Merge pull request #450 from alphagov/make_service_live
Make service live and revert working, all tests passing.
This commit is contained in:
@@ -96,6 +96,23 @@ def service_request_to_go_live(service_id):
|
|||||||
return redirect(url_for('.service_settings', service_id=service_id))
|
return redirect(url_for('.service_settings', service_id=service_id))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<service_id>/service-settings/switch-live")
|
||||||
|
@login_required
|
||||||
|
@user_has_permissions(admin_override=True)
|
||||||
|
def service_switch_live(service_id):
|
||||||
|
service_api_client.update_service(
|
||||||
|
current_service['id'],
|
||||||
|
current_service['name'],
|
||||||
|
current_service['active'],
|
||||||
|
# TODO This limit should be set depending on the agreement signed by
|
||||||
|
# with Notify.
|
||||||
|
25000 if current_service['restricted'] else 50,
|
||||||
|
False if current_service['restricted'] else True,
|
||||||
|
current_service['users'],
|
||||||
|
current_service['email_from'])
|
||||||
|
return redirect(url_for('.service_settings', service_id=service_id))
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<service_id>/service-settings/status", methods=['GET', 'POST'])
|
@main.route("/services/<service_id>/service-settings/status", methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('manage_settings', admin_override=True)
|
@user_has_permissions('manage_settings', admin_override=True)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
'title': 'Request to go live and turn off sending restrictions',
|
'title': 'Request to go live and turn off sending restrictions',
|
||||||
'link': url_for('.service_request_to_go_live', service_id=current_service.id),
|
'link': url_for('.service_request_to_go_live', service_id=current_service.id),
|
||||||
'hint': 'A live service can send notifications to any phone number or email address',
|
'hint': 'A live service can send notifications to any phone number or email address',
|
||||||
} if not current_service.live else {
|
} if current_service.restricted else {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'title': 'Temporarily suspend API keys',
|
'title': 'Temporarily suspend API keys',
|
||||||
@@ -27,7 +27,15 @@
|
|||||||
} if not current_service.active else {
|
} if not current_service.active else {
|
||||||
'title': 'Reactivate API keys',
|
'title': 'Reactivate API keys',
|
||||||
'link': url_for('.service_status_change', service_id=current_service.id)
|
'link': url_for('.service_status_change', service_id=current_service.id)
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
'title': 'Make service live',
|
||||||
|
'link': url_for('.service_switch_live', service_id=current_service.id)
|
||||||
|
} if current_service.restricted and current_user.has_permissions([], admin_override=True) else {
|
||||||
|
'title': 'Revert service to trial',
|
||||||
|
'link': url_for('.service_switch_live', service_id=current_service.id)
|
||||||
|
} if not current_service.restricted and current_user.has_permissions([], admin_override=True) else {
|
||||||
|
},
|
||||||
]) }}
|
]) }}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import app
|
|||||||
from app.utils import email_safe
|
from app.utils import email_safe
|
||||||
from tests import validate_route_permission
|
from tests import validate_route_permission
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from unittest.mock import ANY
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_overview(app_,
|
def test_should_show_overview(app_,
|
||||||
@@ -37,13 +38,17 @@ def test_should_show_service_name(app_,
|
|||||||
|
|
||||||
|
|
||||||
def test_should_redirect_after_change_service_name(app_,
|
def test_should_redirect_after_change_service_name(app_,
|
||||||
active_user_with_permissions,
|
|
||||||
service_one,
|
service_one,
|
||||||
mocker,
|
active_user_with_permissions,
|
||||||
mock_get_services):
|
mock_login,
|
||||||
|
mock_get_user,
|
||||||
|
mock_get_service,
|
||||||
|
mock_update_service,
|
||||||
|
mock_get_services,
|
||||||
|
mock_has_permissions):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user_with_permissions, mocker, service_one)
|
client.login(active_user_with_permissions)
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_for('main.service_name_change', service_id=service_one['id']),
|
url_for('main.service_name_change', service_id=service_one['id']),
|
||||||
data={'name': "new name"})
|
data={'name': "new name"})
|
||||||
@@ -55,6 +60,46 @@ def test_should_redirect_after_change_service_name(app_,
|
|||||||
assert mock_get_services.called
|
assert mock_get_services.called
|
||||||
|
|
||||||
|
|
||||||
|
def test_switch_service_to_live(app_,
|
||||||
|
service_one,
|
||||||
|
mock_login,
|
||||||
|
mock_get_user,
|
||||||
|
active_user_with_permissions,
|
||||||
|
mock_get_service,
|
||||||
|
mock_update_service,
|
||||||
|
mock_has_permissions):
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
client.login(active_user_with_permissions)
|
||||||
|
response = client.get(
|
||||||
|
url_for('main.service_switch_live', service_id=service_one['id']))
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == url_for(
|
||||||
|
'main.service_settings',
|
||||||
|
service_id=service_one['id'], _external=True)
|
||||||
|
mock_update_service.assert_called_with(ANY, ANY, ANY, 25000, False, ANY, ANY)
|
||||||
|
|
||||||
|
|
||||||
|
def test_switch_service_to_restricted(app_,
|
||||||
|
service_one,
|
||||||
|
mock_login,
|
||||||
|
mock_get_user,
|
||||||
|
active_user_with_permissions,
|
||||||
|
mock_get_live_service,
|
||||||
|
mock_update_service,
|
||||||
|
mock_has_permissions):
|
||||||
|
with app_.test_request_context():
|
||||||
|
with app_.test_client() as client:
|
||||||
|
client.login(active_user_with_permissions)
|
||||||
|
response = client.get(
|
||||||
|
url_for('main.service_switch_live', service_id=service_one['id']))
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == url_for(
|
||||||
|
'main.service_settings',
|
||||||
|
service_id=service_one['id'], _external=True)
|
||||||
|
mock_update_service.assert_called_with(ANY, ANY, ANY, 50, True, ANY, ANY)
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_allow_duplicate_names(app_,
|
def test_should_not_allow_duplicate_names(app_,
|
||||||
active_user_with_permissions,
|
active_user_with_permissions,
|
||||||
mocker,
|
mocker,
|
||||||
@@ -127,7 +172,8 @@ def test_should_raise_duplicate_name_handled(app_,
|
|||||||
mocker,
|
mocker,
|
||||||
mock_get_services,
|
mock_get_services,
|
||||||
mock_update_service_raise_httperror_duplicate_name,
|
mock_update_service_raise_httperror_duplicate_name,
|
||||||
mock_verify_password):
|
mock_verify_password,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(active_user_with_permissions, mocker, service_one)
|
client.login(active_user_with_permissions, mocker, service_one)
|
||||||
@@ -151,11 +197,12 @@ def test_should_show_request_to_go_live(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.get(
|
response = client.get(
|
||||||
url_for('main.service_request_to_go_live', service_id=service_id))
|
url_for('main.service_request_to_go_live', service_id=service_id))
|
||||||
service = mock_get_service.side_effect(service_id)['data']
|
service = mock_get_service.side_effect(service_id)['data']
|
||||||
@@ -171,11 +218,12 @@ def test_should_redirect_after_request_to_go_live(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.post(url_for(
|
response = client.post(url_for(
|
||||||
'main.service_request_to_go_live', service_id=service_id))
|
'main.service_request_to_go_live', service_id=service_id))
|
||||||
|
|
||||||
@@ -187,7 +235,7 @@ def test_should_redirect_after_request_to_go_live(app_,
|
|||||||
|
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.post(url_for(
|
response = client.post(url_for(
|
||||||
'main.service_request_to_go_live', service_id=service_id), follow_redirects=True)
|
'main.service_request_to_go_live', service_id=service_id), follow_redirects=True)
|
||||||
|
|
||||||
@@ -202,11 +250,12 @@ def test_should_show_status_page(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.get(url_for(
|
response = client.get(url_for(
|
||||||
'main.service_status_change', service_id=service_id))
|
'main.service_status_change', service_id=service_id))
|
||||||
|
|
||||||
@@ -222,11 +271,12 @@ def test_should_show_redirect_after_status_change(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.post(url_for(
|
response = client.post(url_for(
|
||||||
'main.service_status_change', service_id=service_id))
|
'main.service_status_change', service_id=service_id))
|
||||||
|
|
||||||
@@ -243,11 +293,12 @@ def test_should_show_status_confirmation(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.get(url_for(
|
response = client.get(url_for(
|
||||||
'main.service_status_change_confirm', service_id=service_id))
|
'main.service_status_change_confirm', service_id=service_id))
|
||||||
|
|
||||||
@@ -265,11 +316,12 @@ def test_should_redirect_after_status_confirmation(app_,
|
|||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_verify_password,
|
mock_verify_password,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.post(url_for(
|
response = client.post(url_for(
|
||||||
'main.service_status_change_confirm', service_id=service_id))
|
'main.service_status_change_confirm', service_id=service_id))
|
||||||
|
|
||||||
@@ -287,11 +339,12 @@ def test_should_show_delete_page(app_,
|
|||||||
mock_get_service,
|
mock_get_service,
|
||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.get(url_for(
|
response = client.get(url_for(
|
||||||
'main.service_delete', service_id=service_id))
|
'main.service_delete', service_id=service_id))
|
||||||
|
|
||||||
@@ -306,11 +359,12 @@ def test_should_show_redirect_after_deleting_service(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.post(url_for(
|
response = client.post(url_for(
|
||||||
'main.service_delete', service_id=service_id))
|
'main.service_delete', service_id=service_id))
|
||||||
|
|
||||||
@@ -326,11 +380,12 @@ def test_should_show_delete_confirmation(app_,
|
|||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.get(url_for(
|
response = client.get(url_for(
|
||||||
'main.service_delete_confirm', service_id=service_id))
|
'main.service_delete_confirm', service_id=service_id))
|
||||||
|
|
||||||
@@ -347,11 +402,12 @@ def test_should_redirect_delete_confirmation(app_,
|
|||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_login,
|
mock_login,
|
||||||
mock_verify_password,
|
mock_verify_password,
|
||||||
mock_has_permissions):
|
mock_has_permissions,
|
||||||
|
fake_uuid):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
service_id = 123
|
service_id = fake_uuid
|
||||||
response = client.post(url_for(
|
response = client.post(url_for(
|
||||||
'main.service_delete_confirm', service_id=service_id))
|
'main.service_delete_confirm', service_id=service_id))
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,20 @@ def mock_get_service(mocker, api_user_active):
|
|||||||
return mocker.patch('app.service_api_client.get_service', side_effect=_get)
|
return mocker.patch('app.service_api_client.get_service', side_effect=_get)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_get_live_service(mocker, api_user_active):
|
||||||
|
def _get(service_id):
|
||||||
|
service = service_json(
|
||||||
|
service_id,
|
||||||
|
"Test Service",
|
||||||
|
[api_user_active.id],
|
||||||
|
message_limit=1000,
|
||||||
|
active=False,
|
||||||
|
restricted=False)
|
||||||
|
return {'data': service}
|
||||||
|
return mocker.patch('app.service_api_client.get_service', side_effect=_get)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_create_service(mocker):
|
def mock_create_service(mocker):
|
||||||
def _create(service_name, active, message_limit, restricted, user_id, email_from):
|
def _create(service_name, active, message_limit, restricted, user_id, email_from):
|
||||||
|
|||||||
Reference in New Issue
Block a user