mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Removed the need for 2 return statements.
Update tests to fix copy/paste errors, use freezetime to ensure there is never a random failing test.
This commit is contained in:
@@ -659,6 +659,7 @@ def test_fetch_stats_by_date_range_for_all_services(notify_db, notify_db_session
|
||||
assert results[0] == ('sms', 'created', result_one.service_id, 2)
|
||||
|
||||
|
||||
@freeze_time('2001-01-01T23:59:00')
|
||||
def test_dao_suspend_service_marks_service_as_inactive_and_expires_api_keys(sample_service, sample_api_key):
|
||||
dao_suspend_service(sample_service.id)
|
||||
service = Service.query.get(sample_service.id)
|
||||
@@ -666,9 +667,10 @@ def test_dao_suspend_service_marks_service_as_inactive_and_expires_api_keys(samp
|
||||
assert service.name == sample_service.name
|
||||
|
||||
api_key = ApiKey.query.get(sample_api_key.id)
|
||||
assert api_key.expiry_date.date() == datetime.utcnow().date()
|
||||
assert api_key.expiry_date == datetime(2001, 1, 1, 23, 59, 00)
|
||||
|
||||
|
||||
@freeze_time('2001-01-01T23:59:00')
|
||||
def test_dao_resume_service_marks_service_as_active_and_api_keys_are_still_revoked(sample_service, sample_api_key):
|
||||
dao_suspend_service(sample_service.id)
|
||||
service = Service.query.get(sample_service.id)
|
||||
@@ -678,4 +680,4 @@ def test_dao_resume_service_marks_service_as_active_and_api_keys_are_still_revok
|
||||
assert Service.query.get(service.id).active
|
||||
|
||||
api_key = ApiKey.query.get(sample_api_key.id)
|
||||
assert api_key.expiry_date.date() == datetime.utcnow().date()
|
||||
assert api_key.expiry_date == datetime(2001, 1, 1, 23, 59, 00)
|
||||
|
||||
@@ -4,7 +4,9 @@ import pytest
|
||||
|
||||
import uuid
|
||||
|
||||
from app.models import Service
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.models import Service, ApiKey
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
@@ -33,25 +35,31 @@ def test_has_not_effect_when_service_is_already_that_state(client, sample_servic
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 204
|
||||
mocked.assert_not_called()
|
||||
assert mocked.called == 0
|
||||
assert sample_service.active == active
|
||||
|
||||
|
||||
@freeze_time('2001-01-01T23:59:00')
|
||||
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),
|
||||
response = client.post("/service/{}/suspend".format(sample_service.id),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 204
|
||||
assert sample_api_key.expiry_date.date() == datetime.utcnow().date()
|
||||
assert sample_api_key.expiry_date == datetime(2001, 1, 1, 23, 59, 00)
|
||||
|
||||
|
||||
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()
|
||||
with freeze_time('2001-10-22T11:59:00'):
|
||||
sample_api_key.expiry_date = datetime.utcnow()
|
||||
sample_service.active = False
|
||||
auth_header = create_authorization_header()
|
||||
client.post("/service/{}/resume".format(sample_service.id),
|
||||
headers=[auth_header])
|
||||
with freeze_time('2001-10-22T13:59:00'):
|
||||
auth_header = create_authorization_header()
|
||||
response = client.post("/service/{}/resume".format(sample_service.id),
|
||||
headers=[auth_header])
|
||||
assert response.status_code == 204
|
||||
assert sample_api_key.expiry_date == datetime(2001, 10, 22, 11, 59, 00)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("action, original_state", [("suspend", True), ("resume", False)])
|
||||
|
||||
Reference in New Issue
Block a user