Merge pull request #922 from alphagov/sent-status

Sent status
This commit is contained in:
Leo Hemsted
2017-04-27 12:30:16 +01:00
committed by GitHub
6 changed files with 70 additions and 7 deletions

View File

@@ -187,7 +187,6 @@ class Development(Config):
NOTIFY_ENVIRONMENT = 'development'
NOTIFICATION_QUEUE_PREFIX = 'development'
DEBUG = True
SQLALCHEMY_ECHO = False
CELERY_QUEUES = Config.CELERY_QUEUES + [
Queue('db-sms', Exchange('default'), routing_key='db-sms'),
Queue('priority', Exchange('default'), routing_key='priority'),

View File

@@ -574,6 +574,7 @@ class VerifyCode(db.Model):
NOTIFICATION_CREATED = 'created'
NOTIFICATION_SENDING = 'sending'
NOTIFICATION_SENT = 'sent'
NOTIFICATION_DELIVERED = 'delivered'
NOTIFICATION_PENDING = 'pending'
NOTIFICATION_FAILED = 'failed'
@@ -588,6 +589,7 @@ NOTIFICATION_STATUS_TYPES_FAILED = [
]
NOTIFICATION_STATUS_TYPES_COMPLETED = [
NOTIFICATION_SENT,
NOTIFICATION_DELIVERED,
NOTIFICATION_FAILED,
NOTIFICATION_TECHNICAL_FAILURE,
@@ -597,6 +599,7 @@ NOTIFICATION_STATUS_TYPES_COMPLETED = [
NOTIFICATION_STATUS_TYPES_BILLABLE = [
NOTIFICATION_SENDING,
NOTIFICATION_SENT,
NOTIFICATION_DELIVERED,
NOTIFICATION_FAILED,
NOTIFICATION_TECHNICAL_FAILURE,
@@ -607,6 +610,7 @@ NOTIFICATION_STATUS_TYPES_BILLABLE = [
NOTIFICATION_STATUS_TYPES = [
NOTIFICATION_CREATED,
NOTIFICATION_SENDING,
NOTIFICATION_SENT,
NOTIFICATION_DELIVERED,
NOTIFICATION_PENDING,
NOTIFICATION_FAILED,

View File

@@ -0,0 +1,60 @@
"""empty message
Revision ID: 0078_sent_notification_status
Revises: 0077_add_intl_notification
Create Date: 2017-04-24 16:55:20.731069
"""
# revision identifiers, used by Alembic.
revision = '0078_sent_notification_status'
down_revision = '0077_add_intl_notification'
from alembic import op
import sqlalchemy as sa
enum_name = 'notify_status_type'
tmp_name = 'tmp_' + enum_name
old_options = (
'created',
'sending',
'delivered',
'pending',
'failed',
'technical-failure',
'temporary-failure',
'permanent-failure'
)
new_options = old_options + ('sent',)
old_type = sa.Enum(*old_options, name=enum_name)
new_type = sa.Enum(*new_options, name=enum_name)
alter_str = 'ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type '
def upgrade():
op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name))
new_type.create(op.get_bind())
op.execute(alter_str.format(table='notifications', enum=enum_name))
op.execute(alter_str.format(table='notification_history', enum=enum_name))
op.execute('DROP TYPE ' + tmp_name)
def downgrade():
op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name))
# Convert 'sent' template into 'sending'
update_str = "UPDATE {table} SET status='sending' where status='sent'"
op.execute(update_str.format(table='notifications'))
op.execute(update_str.format(table='notification_history'))
old_type.create(op.get_bind())
op.execute(alter_str.format(table='notifications', enum=enum_name))
op.execute(alter_str.format(table='notification_history', enum=enum_name))
op.execute('DROP TYPE ' + tmp_name)

View File

@@ -26,8 +26,8 @@ def test_get_fragment_count_separates_sms_and_email(notify_db, sample_template,
def test_get_fragment_count_filters_on_status(notify_db, sample_template):
for status in NOTIFICATION_STATUS_TYPES:
noti_hist(notify_db, sample_template, status=status)
# sending, delivered, failed, technical-failure, temporary-failure, permanent-failure
assert get_fragment_count(sample_template.service_id)['sms_count'] == 6
# sending, sent, delivered, failed, technical-failure, temporary-failure, permanent-failure
assert get_fragment_count(sample_template.service_id)['sms_count'] == 7
def test_get_fragment_count_filters_on_service_id(notify_db, sample_template, service_factory):

View File

@@ -307,8 +307,8 @@ def test_get_all_notifications_filter_by_status_invalid_status(client, sample_no
assert json_response['status_code'] == 400
assert len(json_response['errors']) == 1
assert json_response['errors'][0]['message'] == "status elephant is not one of [created, sending, delivered, " \
"pending, failed, technical-failure, temporary-failure, permanent-failure]"
assert json_response['errors'][0]['message'] == "status elephant is not one of [created, sending, sent, " \
"delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"
def test_get_all_notifications_filter_by_multiple_statuses(client, notify_db, notify_db_session):

View File

@@ -27,7 +27,7 @@ def test_get_notifications_request_invalid_statuses(
invalid_statuses, valid_statuses
):
partial_error_status = "is not one of " \
"[created, sending, delivered, pending, failed, " \
"[created, sending, sent, delivered, pending, failed, " \
"technical-failure, temporary-failure, permanent-failure]"
with pytest.raises(ValidationError) as e:
@@ -74,7 +74,7 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
error_messages = [error['message'] for error in errors]
for invalid_status in ["elephant", "giraffe"]:
assert "status {} is not one of [created, sending, delivered, " \
assert "status {} is not one of [created, sending, sent, delivered, " \
"pending, failed, technical-failure, temporary-failure, permanent-failure]".format(
invalid_status
) in error_messages