mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Added new endpoints to get service data retention for a service.
This commit is contained in:
@@ -4,8 +4,63 @@ from datetime import datetime
|
||||
import pytest
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.dao.service_data_retention_dao import insert_service_data_retention, update_service_data_retention
|
||||
from app.dao.service_data_retention_dao import (
|
||||
fetch_service_data_retention,
|
||||
insert_service_data_retention,
|
||||
update_service_data_retention,
|
||||
fetch_service_data_retention_by_id
|
||||
)
|
||||
from app.models import ServiceDataRetention
|
||||
from tests.app.db import create_service
|
||||
|
||||
|
||||
def test_fetch_service_data_retention(sample_service):
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, 'email', 3)
|
||||
letter_data_retention = insert_service_data_retention(sample_service.id, 'letter', 30)
|
||||
sms_data_retention = insert_service_data_retention(sample_service.id, 'sms', 5)
|
||||
|
||||
list_of_data_retention = fetch_service_data_retention(sample_service.id)
|
||||
|
||||
assert len(list_of_data_retention) == 3
|
||||
assert list_of_data_retention[0] == email_data_retention
|
||||
assert list_of_data_retention[1] == sms_data_retention
|
||||
assert list_of_data_retention[2] == letter_data_retention
|
||||
|
||||
|
||||
def test_fetch_service_data_retention_only_returns_row_for_service(sample_service):
|
||||
another_service = create_service(service_name="Another service")
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, 'email', 3)
|
||||
letter_data_retention = insert_service_data_retention(sample_service.id, 'letter', 30)
|
||||
insert_service_data_retention(another_service.id, 'sms', 5)
|
||||
|
||||
list_of_data_retention = fetch_service_data_retention(sample_service.id)
|
||||
assert len(list_of_data_retention) == 2
|
||||
assert list_of_data_retention[0] == email_data_retention
|
||||
assert list_of_data_retention[1] == letter_data_retention
|
||||
|
||||
|
||||
def test_fetch_service_data_retention_returns_empty_list_when_no_rows_for_service(sample_service):
|
||||
empty_list = fetch_service_data_retention(sample_service.id)
|
||||
assert not empty_list
|
||||
|
||||
|
||||
def test_fetch_service_data_retention_by_id(sample_service):
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, 'email', 3)
|
||||
insert_service_data_retention(sample_service.id, 'sms', 13)
|
||||
result = fetch_service_data_retention_by_id(sample_service.id, email_data_retention.id)
|
||||
assert result == email_data_retention
|
||||
|
||||
|
||||
def test_fetch_service_data_retention_by_id_returns_none_if_not_found(sample_service):
|
||||
result = fetch_service_data_retention_by_id(sample_service.id, uuid.uuid4())
|
||||
assert not result
|
||||
|
||||
|
||||
def test_fetch_service_data_retention_by_id_returns_none_if_id_not_for_service(sample_service):
|
||||
another_service = create_service(service_name="Another service")
|
||||
email_data_retention = insert_service_data_retention(sample_service.id, 'email', 3)
|
||||
result = fetch_service_data_retention_by_id(another_service.id, email_data_retention.id)
|
||||
assert not result
|
||||
|
||||
|
||||
def test_insert_service_data_retention(sample_service):
|
||||
|
||||
@@ -6,6 +6,58 @@ from tests import create_authorization_header
|
||||
from tests.app.db import create_service_data_retention
|
||||
|
||||
|
||||
def test_get_service_data_retention(client, sample_service):
|
||||
sms_data_retention = create_service_data_retention(service_id=sample_service.id)
|
||||
email_data_retention = create_service_data_retention(service_id=sample_service.id, notification_type='email',
|
||||
days_of_retention=10)
|
||||
letter_data_retention = create_service_data_retention(service_id=sample_service.id, notification_type='letter',
|
||||
days_of_retention=30)
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/data-retention'.format(str(sample_service.id)),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
assert len(json_response) == 3
|
||||
assert json_response[0] == email_data_retention.serialize()
|
||||
assert json_response[1] == sms_data_retention.serialize()
|
||||
assert json_response[2] == letter_data_retention.serialize()
|
||||
|
||||
|
||||
def test_get_service_data_retention_returns_empty_list(client, sample_service):
|
||||
response = client.get(
|
||||
'/service/{}/data-retention'.format(str(sample_service.id)),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert len(json.loads(response.get_data(as_text=True))) == 0
|
||||
|
||||
|
||||
def test_get_service_data_retention_by_id(client, sample_service):
|
||||
sms_data_retention = create_service_data_retention(service_id=sample_service.id)
|
||||
create_service_data_retention(service_id=sample_service.id, notification_type='email',
|
||||
days_of_retention=10)
|
||||
create_service_data_retention(service_id=sample_service.id, notification_type='letter',
|
||||
days_of_retention=30)
|
||||
response = client.get(
|
||||
'/service/{}/data-retention/{}'.format(str(sample_service.id), sms_data_retention.id),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.get_data(as_text=True)) == sms_data_retention.serialize()
|
||||
|
||||
|
||||
def test_get_service_data_retention_by_id_returns_none_when_no_data_retention_exists(client, sample_service):
|
||||
response = client.get(
|
||||
'/service/{}/data-retention/{}'.format(str(sample_service.id), uuid.uuid4()),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()],
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.get_data(as_text=True)) == {}
|
||||
|
||||
|
||||
def test_create_service_data_retention(client, sample_service):
|
||||
data = {
|
||||
"notification_type": 'sms',
|
||||
|
||||
Reference in New Issue
Block a user