def test_can_get_template_then_redacted_returns_right_values(sample_template): template = dao_get_template_by_id_and_service_id( template_id=sample_template.id, service_id=sample_template.service_id) assert not template.redact_personalisation dao_redact_template(template=template, user_id=sample_template.created_by_id) assert template.redact_personalisation
def redact_template(template, data): # we also don't need to check what was passed in redact_personalisation - its presence in the dict is enough. if 'created_by' not in data: message = 'Field is required' errors = {'created_by': [message]} raise InvalidRequest(errors, status_code=400) # if it's already redacted, then just return 200 straight away. if not template.redact_personalisation: dao_redact_template(template, data['created_by']) return 'null', 200
def test_redact_template(sample_template): redacted = TemplateRedacted.query.one() assert redacted.template_id == sample_template.id assert redacted.redact_personalisation is False time = datetime.now() with freeze_time(time): dao_redact_template(sample_template, sample_template.created_by_id) assert redacted.redact_personalisation is True assert redacted.updated_at == time assert redacted.updated_by_id == sample_template.created_by_id
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, 'created_by': 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