mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
This is the first PR in the story to create a suspend service feature.
- Renaming /service/<id>/deactivate to /service/<id>/archive to match language on the UI. - Will need to update admin before deleting the deactive service method - Created dao and endpoint methods to suspend and resume a service. - I confirm the use of suspend and resume with a couple people on the team, seems to be the right choice. The idea is that if you archive a service there is no coming back from that. To suspend a service is marking it as inactive and revoking the api keys. To resume a service is to mark the service as active, the service will need to create new API keys. It makes sense that if a service is under threat that the API keys should be renewed. The next PR will update the code to check that the service is active before sending the request or allowing any actions by the service.
This commit is contained in:
72
tests/app/service/test_suspend_resume_service.py
Normal file
72
tests/app/service/test_suspend_resume_service.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
import uuid
|
||||
|
||||
from app.models import Service
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
@pytest.mark.parametrize("endpoint", ["suspend", "resume"])
|
||||
def test_only_allows_post(client, endpoint):
|
||||
auth_header = create_authorization_header()
|
||||
response = client.get("/service/{}/{}".format(uuid.uuid4(), endpoint),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 405
|
||||
|
||||
|
||||
@pytest.mark.parametrize("endpoint", ["suspend", "resume"])
|
||||
def test_returns_404_when_service_does_not_exist(client, endpoint):
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post("/service/{}/{}".format(uuid.uuid4(), endpoint),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.parametrize("action, active", [("suspend", False), ("resume", True)])
|
||||
def test_has_not_effect_when_service_is_already_that_state(client, sample_service, action, active, mocker):
|
||||
mocked = mocker.patch("app.service.rest.dao_{}_service".format(action))
|
||||
sample_service.active = active
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post("/service/{}/{}".format(sample_service.id, action),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 204
|
||||
mocked.assert_not_called()
|
||||
assert mocked.called == 0
|
||||
|
||||
|
||||
def test_suspending_service_revokes_api_keys(client, sample_service, sample_api_key):
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post("/service/{}/archive".format(sample_service.id),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 204
|
||||
assert sample_api_key.expiry_date.date() == datetime.utcnow().date()
|
||||
|
||||
|
||||
def test_resume_service_leaves_api_keys_revokes(client, sample_service, sample_api_key):
|
||||
sample_api_key.expiry_date = datetime.utcnow()
|
||||
sample_service.active = False
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post("/service/{}/archive".format(sample_service.id),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 204
|
||||
assert sample_api_key.expiry_date.date() == datetime.utcnow().date()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("action, original_state", [("suspend", True), ("resume", False)])
|
||||
def test_service_history_is_created(client, sample_service, action, original_state):
|
||||
sample_service.active = original_state
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post("/service/{}/{}".format(sample_service.id, action),
|
||||
headers=[auth_header])
|
||||
ServiceHistory = Service.get_history_model()
|
||||
history = ServiceHistory.query.filter_by(
|
||||
id=sample_service.id
|
||||
).order_by(
|
||||
ServiceHistory.version.desc()
|
||||
).first()
|
||||
|
||||
assert response.status_code == 204
|
||||
assert history.version == 2
|
||||
assert history.active != original_state
|
||||
Reference in New Issue
Block a user