mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Merge branch 'master' into template_queryies
This commit is contained in:
@@ -197,7 +197,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
|
||||
sender=None
|
||||
)
|
||||
|
||||
persisted_notification = notifications_dao.get_notification(sample_template.service_id, db_notification.id)
|
||||
persisted_notification = notifications_dao.get_notification_by_id(db_notification.id)
|
||||
assert persisted_notification.to == db_notification.to
|
||||
assert persisted_notification.template_id == sample_template.id
|
||||
assert persisted_notification.template_version == version_on_notification
|
||||
@@ -232,7 +232,7 @@ def test_should_call_send_sms_response_task_if_research_mode(notify_db, sample_s
|
||||
('mmg', str(sample_notification.id), sample_notification.to), queue='research-mode'
|
||||
)
|
||||
|
||||
persisted_notification = notifications_dao.get_notification(sample_service.id, sample_notification.id)
|
||||
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
|
||||
assert persisted_notification.to == sample_notification.to
|
||||
assert persisted_notification.template_id == sample_notification.template_id
|
||||
assert persisted_notification.status == 'sending'
|
||||
@@ -508,7 +508,7 @@ def test_should_not_set_billable_units_if_research_mode(notify_db, sample_servic
|
||||
sample_notification.id
|
||||
)
|
||||
|
||||
persisted_notification = notifications_dao.get_notification(sample_service.id, sample_notification.id)
|
||||
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
|
||||
assert persisted_notification.billable_units == 0
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from app.models import (
|
||||
from app.dao.notifications_dao import (
|
||||
dao_create_notification,
|
||||
dao_update_notification,
|
||||
get_notification,
|
||||
get_notification_with_personalisation,
|
||||
get_notification_for_job,
|
||||
get_notifications_for_job,
|
||||
dao_get_notification_statistics_for_service,
|
||||
@@ -58,7 +58,7 @@ def test_should_have_decorated_notifications_dao_functions():
|
||||
assert update_notification_status_by_reference.__wrapped__.__name__ == 'update_notification_status_by_reference' # noqa
|
||||
assert get_notification_for_job.__wrapped__.__name__ == 'get_notification_for_job' # noqa
|
||||
assert get_notifications_for_job.__wrapped__.__name__ == 'get_notifications_for_job' # noqa
|
||||
assert get_notification.__wrapped__.__name__ == 'get_notification' # noqa
|
||||
assert get_notification_with_personalisation.__wrapped__.__name__ == 'get_notification_with_personalisation' # noqa
|
||||
assert get_notifications_for_service.__wrapped__.__name__ == 'get_notifications_for_service' # noqa
|
||||
assert get_notification_by_id.__wrapped__.__name__ == 'get_notification_by_id' # noqa
|
||||
assert delete_notifications_created_more_than_a_week_ago.__wrapped__.__name__ == 'delete_notifications_created_more_than_a_week_ago' # noqa
|
||||
@@ -769,9 +769,11 @@ def test_save_notification_with_no_job(sample_template, mmg_provider):
|
||||
|
||||
|
||||
def test_get_notification(sample_notification):
|
||||
notification_from_db = get_notification(
|
||||
notification_from_db = get_notification_with_personalisation(
|
||||
sample_notification.service.id,
|
||||
sample_notification.id)
|
||||
sample_notification.id,
|
||||
key_type=None
|
||||
)
|
||||
assert sample_notification == notification_from_db
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ from app.models import (
|
||||
VerifyCode,
|
||||
ApiKey,
|
||||
Template,
|
||||
TemplateHistory,
|
||||
Job,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
@@ -331,7 +332,7 @@ def test_delete_service_and_associated_objects(notify_db,
|
||||
assert ApiKey.query.count() == 0
|
||||
assert ApiKey.get_history_model().query.count() == 0
|
||||
assert Template.query.count() == 0
|
||||
assert Template.get_history_model().query.count() == 0
|
||||
assert TemplateHistory.query.count() == 0
|
||||
assert Job.query.count() == 0
|
||||
assert Notification.query.count() == 0
|
||||
assert Permission.query.count() == 0
|
||||
|
||||
@@ -6,7 +6,7 @@ from app.dao.templates_dao import (
|
||||
dao_update_template,
|
||||
dao_get_template_versions)
|
||||
from tests.app.conftest import sample_template as create_sample_template
|
||||
from app.models import Template
|
||||
from app.models import Template, TemplateHistory
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ def test_get_template_by_id_and_service_returns_none_if_no_template(sample_servi
|
||||
|
||||
def test_create_template_creates_a_history_record_with_current_data(sample_service, sample_user):
|
||||
assert Template.query.count() == 0
|
||||
assert Template.get_history_model().query.count() == 0
|
||||
assert TemplateHistory.query.count() == 0
|
||||
data = {
|
||||
'name': 'Sample Template',
|
||||
'template_type': "email",
|
||||
@@ -200,7 +200,7 @@ def test_create_template_creates_a_history_record_with_current_data(sample_servi
|
||||
assert Template.query.count() == 1
|
||||
|
||||
template_from_db = Template.query.first()
|
||||
template_history = Template.get_history_model().query.first()
|
||||
template_history = TemplateHistory.query.first()
|
||||
|
||||
assert template_from_db.id == template_history.id
|
||||
assert template_from_db.name == template_history.name
|
||||
@@ -212,7 +212,7 @@ def test_create_template_creates_a_history_record_with_current_data(sample_servi
|
||||
|
||||
def test_update_template_creates_a_history_record_with_current_data(sample_service, sample_user):
|
||||
assert Template.query.count() == 0
|
||||
assert Template.get_history_model().query.count() == 0
|
||||
assert TemplateHistory.query.count() == 0
|
||||
data = {
|
||||
'name': 'Sample Template',
|
||||
'template_type': "email",
|
||||
@@ -228,20 +228,20 @@ def test_update_template_creates_a_history_record_with_current_data(sample_servi
|
||||
assert created.name == 'Sample Template'
|
||||
assert Template.query.count() == 1
|
||||
assert Template.query.first().version == 1
|
||||
assert Template.get_history_model().query.count() == 1
|
||||
assert TemplateHistory.query.count() == 1
|
||||
|
||||
created.name = 'new name'
|
||||
dao_update_template(created)
|
||||
|
||||
assert Template.query.count() == 1
|
||||
assert Template.get_history_model().query.count() == 2
|
||||
assert TemplateHistory.query.count() == 2
|
||||
|
||||
template_from_db = Template.query.first()
|
||||
|
||||
assert template_from_db.version == 2
|
||||
|
||||
assert Template.get_history_model().query.filter_by(name='Sample Template').one().version == 1
|
||||
assert Template.get_history_model().query.filter_by(name='new name').one().version == 2
|
||||
assert TemplateHistory.query.filter_by(name='Sample Template').one().version == 1
|
||||
assert TemplateHistory.query.filter_by(name='new name').one().version == 2
|
||||
|
||||
|
||||
def test_get_template_history_version(sample_user, sample_service, sample_template):
|
||||
@@ -261,12 +261,16 @@ def test_get_template_versions(sample_template):
|
||||
sample_template.content = 'new version'
|
||||
dao_update_template(sample_template)
|
||||
versions = dao_get_template_versions(service_id=sample_template.service_id, template_id=sample_template.id)
|
||||
assert versions.__len__() == 2
|
||||
for x in versions:
|
||||
if x.version == 2:
|
||||
assert x.content == 'new version'
|
||||
else:
|
||||
assert x.content == original_content
|
||||
assert len(versions) == 2
|
||||
versions = sorted(versions, key=lambda x: x.version)
|
||||
assert versions[0].content == original_content
|
||||
assert versions[1].content == 'new version'
|
||||
|
||||
assert versions[0].created_at == versions[1].created_at
|
||||
|
||||
assert versions[0].updated_at is None
|
||||
assert versions[1].updated_at is not None
|
||||
|
||||
from app.schemas import template_history_schema
|
||||
v = template_history_schema.load(versions, many=True)
|
||||
assert v.__len__() == 2
|
||||
assert len(v) == 2
|
||||
|
||||
@@ -8,6 +8,7 @@ from freezegun import freeze_time
|
||||
|
||||
from app.dao.notifications_dao import dao_update_notification
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
from app.dao.templates_dao import dao_update_template
|
||||
from app.models import ApiKey, KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import sample_notification as create_sample_notification
|
||||
@@ -29,7 +30,9 @@ def test_get_sms_notification_by_id(notify_api, sample_notification):
|
||||
assert notification['template'] == {
|
||||
'id': str(sample_notification.template.id),
|
||||
'name': sample_notification.template.name,
|
||||
'template_type': sample_notification.template.template_type}
|
||||
'template_type': sample_notification.template.template_type,
|
||||
'version': 1
|
||||
}
|
||||
assert notification['job'] == {
|
||||
'id': str(sample_notification.job.id),
|
||||
'original_file_name': sample_notification.job.original_file_name
|
||||
@@ -62,7 +65,9 @@ def test_get_email_notification_by_id(notify_api, notify_db, notify_db_session,
|
||||
assert notification['template'] == {
|
||||
'id': str(email_notification.template.id),
|
||||
'name': email_notification.template.name,
|
||||
'template_type': email_notification.template.template_type}
|
||||
'template_type': email_notification.template.template_type,
|
||||
'version': 1
|
||||
}
|
||||
assert notification['job'] == {
|
||||
'id': str(email_notification.job.id),
|
||||
'original_file_name': email_notification.job.original_file_name
|
||||
@@ -166,7 +171,9 @@ def test_get_all_notifications(notify_api, sample_notification):
|
||||
assert notifications['notifications'][0]['template'] == {
|
||||
'id': str(sample_notification.template.id),
|
||||
'name': sample_notification.template.name,
|
||||
'template_type': sample_notification.template.template_type}
|
||||
'template_type': sample_notification.template.template_type,
|
||||
'version': 1
|
||||
}
|
||||
assert notifications['notifications'][0]['job'] == {
|
||||
'id': str(sample_notification.job.id),
|
||||
'original_file_name': sample_notification.job.original_file_name
|
||||
@@ -656,7 +663,6 @@ def test_get_notification_public_api_format_is_not_changed(notify_api, sample_no
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True, raises=NeededByTemplateError)
|
||||
def test_get_notification_selects_correct_template_for_personalisation(notify_api,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
@@ -666,8 +672,9 @@ def test_get_notification_selects_correct_template_for_personalisation(notify_ap
|
||||
notify_db_session,
|
||||
service=sample_template.service,
|
||||
template=sample_template)
|
||||
|
||||
original_content = sample_template.content
|
||||
sample_template.content = '((name))'
|
||||
dao_update_template(sample_template)
|
||||
notify_db.session.commit()
|
||||
|
||||
create_sample_notification(notify_db,
|
||||
@@ -680,14 +687,19 @@ def test_get_notification_selects_correct_template_for_personalisation(notify_ap
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.get(path='/notifications', headers=[auth_header])
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
resp = json.loads(response.get_data(as_text=True))
|
||||
assert len(resp['notifications']) == 2
|
||||
assert resp['notifications'][0]['template_version'] == 1
|
||||
assert resp['notifications'][0]['body'] == 'This is a template'
|
||||
assert resp['notifications'][1]['template_version'] == 2
|
||||
assert resp['notifications'][1]['body'] == 'foo'
|
||||
notis = sorted(resp['notifications'], key=lambda x: x['template_version'])
|
||||
assert len(notis) == 2
|
||||
assert notis[0]['template_version'] == 1
|
||||
assert notis[0]['body'] == original_content
|
||||
assert notis[1]['template_version'] == 2
|
||||
assert notis[1]['body'] == 'foo'
|
||||
|
||||
assert notis[0]['template_version'] == notis[0]['template']['version']
|
||||
assert notis[1]['template_version'] == notis[1]['template']['version']
|
||||
|
||||
|
||||
def _create_auth_header_from_key(api_key):
|
||||
|
||||
Reference in New Issue
Block a user