mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
add tests for redact_template rest
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import uuid
|
||||
import json
|
||||
import random
|
||||
import string
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.models import Template
|
||||
from app.dao.templates_dao import dao_get_template_by_id, dao_redact_template
|
||||
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import sample_template as create_sample_template
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
|
||||
|
||||
@pytest.mark.parametrize('template_type, subject', [
|
||||
@@ -539,3 +545,87 @@ def test_update_set_process_type_on_template(client, sample_template):
|
||||
|
||||
template = dao_get_template_by_id(sample_template.id)
|
||||
assert template.process_type == 'priority'
|
||||
|
||||
|
||||
def test_update_redact_template(admin_request, sample_template):
|
||||
assert sample_template.redact_personalisation is False
|
||||
|
||||
data = {
|
||||
'redact_personalisation': True,
|
||||
'updated_by_id': str(sample_template.created_by_id)
|
||||
}
|
||||
|
||||
dt = datetime.now()
|
||||
|
||||
with freeze_time(dt):
|
||||
resp = admin_request.post(
|
||||
'template.update_template',
|
||||
service_id=sample_template.service_id,
|
||||
template_id=sample_template.id,
|
||||
_data=data
|
||||
)
|
||||
|
||||
assert resp is None
|
||||
|
||||
assert sample_template.redact_personalisation is True
|
||||
assert sample_template.template_redacted.updated_by_id == sample_template.created_by_id
|
||||
assert sample_template.template_redacted.updated_at == dt
|
||||
|
||||
assert sample_template.version == 1
|
||||
|
||||
|
||||
def test_update_redact_template_ignores_other_properties(admin_request, sample_template):
|
||||
data = {
|
||||
'name': 'Foo',
|
||||
'redact_personalisation': True,
|
||||
'updated_by_id': str(sample_template.created_by_id)
|
||||
}
|
||||
|
||||
admin_request.post(
|
||||
'template.update_template',
|
||||
service_id=sample_template.service_id,
|
||||
template_id=sample_template.id,
|
||||
_data=data
|
||||
)
|
||||
|
||||
assert sample_template.redact_personalisation is True
|
||||
assert sample_template.name != 'Foo'
|
||||
|
||||
|
||||
def test_update_redact_template_does_nothing_if_already_redacted(admin_request, sample_template):
|
||||
dt = datetime.now()
|
||||
with freeze_time(dt):
|
||||
dao_redact_template(sample_template, sample_template.created_by_id)
|
||||
|
||||
data = {
|
||||
'redact_personalisation': True,
|
||||
'updated_by_id': str(sample_template.created_by_id)
|
||||
}
|
||||
|
||||
with freeze_time(dt + timedelta(days=1)):
|
||||
resp = admin_request.post(
|
||||
'template.update_template',
|
||||
service_id=sample_template.service_id,
|
||||
template_id=sample_template.id,
|
||||
_data=data
|
||||
)
|
||||
|
||||
assert resp is None
|
||||
|
||||
assert sample_template.redact_personalisation is True
|
||||
# make sure that it hasn't been updated
|
||||
assert sample_template.template_redacted.updated_at == dt
|
||||
|
||||
|
||||
|
||||
def test_update_redact_template_does_nothing_if_no_updated_by(admin_request, sample_template):
|
||||
original_updated_time = sample_template.template_redacted.updated_at
|
||||
admin_request.post(
|
||||
'template.update_template',
|
||||
service_id=sample_template.service_id,
|
||||
template_id=sample_template.id,
|
||||
_data={'redact_personalisation': True}
|
||||
)
|
||||
|
||||
assert sample_template.redact_personalisation is False
|
||||
assert sample_template.template_redacted.updated_at == original_updated_time
|
||||
|
||||
Reference in New Issue
Block a user