forked from cds-snc/notification-api
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#190] db migration to make Notification "to" field nullable
if there is no "to" field, the notification can still be processed
- Loading branch information
1 parent
a6f11c9
commit c6aed2f
Showing
5 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
Revision ID: 0311_make_to_field_nullable | ||
Revises: 0310a_make_email_from_nullable | ||
Create Date: 2020-10-09 09:42:09.093272 | ||
""" | ||
from alembic import op | ||
|
||
revision = '0311_make_to_field_nullable' | ||
down_revision = '0310a_make_email_from_nullable' | ||
|
||
|
||
def upgrade(): | ||
op.alter_column('notifications', 'to', nullable=True) | ||
|
||
|
||
def downgrade(): | ||
op.alter_column('notifications', 'to', nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
SCHEDULE_NOTIFICATIONS, | ||
SMS_TYPE, | ||
UPLOAD_DOCUMENT, | ||
INTERNATIONAL_SMS_TYPE | ||
) | ||
INTERNATIONAL_SMS_TYPE, | ||
VA_PROFILE_ID) | ||
from flask import json, current_app | ||
|
||
from app.models import Notification | ||
|
@@ -368,6 +368,39 @@ def test_should_not_persist_or_send_notification_if_simulated_recipient( | |
assert Notification.query.count() == 0 | ||
|
||
|
||
@pytest.mark.parametrize('notification_type', [ | ||
(EMAIL_TYPE), | ||
(SMS_TYPE), | ||
]) | ||
def test_should_persist_notification_without_recipient( | ||
client, | ||
sample_template, | ||
sample_email_template, | ||
notification_type, | ||
sample_email_template_with_placeholders, | ||
mocker): | ||
apply_async = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type)) | ||
data = { | ||
"va_identifier": { | ||
"id_type": VA_PROFILE_ID, | ||
"value": "foo" | ||
}, | ||
"template_id": sample_template.id if notification_type == SMS_TYPE else sample_email_template.id, | ||
"personalisation": {"name": "Bob"} | ||
} | ||
|
||
auth_header = create_authorization_header(service_id=sample_email_template_with_placeholders.service_id) | ||
response = client.post( | ||
path='/v2/notifications/{}'.format(notification_type), | ||
data=json.dumps(data), | ||
headers=[('Content-Type', 'application/json'), auth_header]) | ||
|
||
assert response.status_code == 201 | ||
assert json.loads(response.get_data(as_text=True))["id"] | ||
assert Notification.query.count() == 1 | ||
apply_async.assert_called() | ||
|
||
|
||
@pytest.mark.parametrize("notification_type, key_send_to, send_to", | ||
[("sms", "phone_number", "6502532222"), | ||
("email", "email_address", "[email protected]")]) | ||
|