mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge pull request #163 from alphagov/default-stats-to-zero
Set default to 0 for the notification_statistics table.
This commit is contained in:
@@ -115,12 +115,12 @@ class NotificationStatistics(db.Model):
|
|||||||
day = db.Column(db.String(255), nullable=False)
|
day = db.Column(db.String(255), nullable=False)
|
||||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False)
|
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, nullable=False)
|
||||||
service = db.relationship('Service', backref=db.backref('service_notification_stats', lazy='dynamic'))
|
service = db.relationship('Service', backref=db.backref('service_notification_stats', lazy='dynamic'))
|
||||||
emails_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
emails_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
emails_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=True)
|
emails_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
emails_error = db.Column(db.BigInteger, index=False, unique=False, nullable=True)
|
emails_error = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
sms_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
sms_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
sms_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=True)
|
sms_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
sms_error = db.Column(db.BigInteger, index=False, unique=False, nullable=True)
|
sms_error = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
UniqueConstraint('service_id', 'day', name='uix_service_to_day'),
|
UniqueConstraint('service_id', 'day', name='uix_service_to_day'),
|
||||||
|
|||||||
45
migrations/versions/0042_default_stats_to_zero.py
Normal file
45
migrations/versions/0042_default_stats_to_zero.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 0042_default_stats_to_zero
|
||||||
|
Revises: 0041_platform_admin
|
||||||
|
Create Date: 2016-03-17 11:09:17.906910
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '0042_default_stats_to_zero'
|
||||||
|
down_revision = '0041_platform_admin'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.get_bind()
|
||||||
|
op.execute('update notification_statistics set emails_delivered = 0 where emails_delivered is Null')
|
||||||
|
op.execute('update notification_statistics set emails_error = 0 where emails_error is Null')
|
||||||
|
op.execute('update notification_statistics set sms_delivered = 0 where sms_delivered is Null')
|
||||||
|
op.execute('update notification_statistics set sms_error = 0 where sms_error is Null')
|
||||||
|
op.alter_column('notification_statistics', 'emails_requested', server_default='0')
|
||||||
|
op.alter_column('notification_statistics', 'emails_delivered', server_default='0', nullable=False)
|
||||||
|
op.alter_column('notification_statistics', 'emails_error', server_default='0', nullable=False)
|
||||||
|
op.alter_column('notification_statistics', 'sms_requested', server_default='0')
|
||||||
|
op.alter_column('notification_statistics', 'sms_delivered', server_default='0', nullable=False)
|
||||||
|
op.alter_column('notification_statistics', 'sms_error', server_default='0', nullable=False)
|
||||||
|
### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('notification_statistics', 'emails_requested', server_default=None)
|
||||||
|
op.alter_column('notification_statistics', 'emails_delivered', server_default=None, nullable=True)
|
||||||
|
op.alter_column('notification_statistics', 'emails_error', server_default=None, nullable=True)
|
||||||
|
op.alter_column('notification_statistics', 'sms_requested', server_default=None)
|
||||||
|
op.alter_column('notification_statistics', 'sms_delivered', server_default=None, nullable=True)
|
||||||
|
op.alter_column('notification_statistics', 'sms_error', server_default=None, nullable=True)
|
||||||
|
op.execute('update notification_statistics set emails_delivered = Null where emails_delivered = 0')
|
||||||
|
op.execute('update notification_statistics set emails_error = Null where emails_error = 0')
|
||||||
|
op.execute('update notification_statistics set sms_delivered = Null where sms_delivered = 0')
|
||||||
|
op.execute('update notification_statistics set sms_error = Null where sms_error = 0')
|
||||||
|
### end Alembic commands ###
|
||||||
@@ -70,8 +70,13 @@ def test_should_be_able_to_get_statistics_for_a_service(sample_template):
|
|||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].emails_requested == 0
|
assert stats[0].emails_requested == 0
|
||||||
assert stats[0].sms_requested == 1
|
assert stats[0].sms_requested == 1
|
||||||
|
assert stats[0].sms_delivered == 0
|
||||||
|
assert stats[0].sms_error == 0
|
||||||
assert stats[0].day == notification.created_at.strftime(DATE_FORMAT)
|
assert stats[0].day == notification.created_at.strftime(DATE_FORMAT)
|
||||||
assert stats[0].service_id == notification.service_id
|
assert stats[0].service_id == notification.service_id
|
||||||
|
assert stats[0].emails_requested == 0
|
||||||
|
assert stats[0].emails_delivered == 0
|
||||||
|
assert stats[0].emails_error == 0
|
||||||
|
|
||||||
|
|
||||||
def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_template):
|
def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_template):
|
||||||
@@ -90,7 +95,11 @@ def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_templat
|
|||||||
sample_template.service.id, now.strftime(DATE_FORMAT)
|
sample_template.service.id, now.strftime(DATE_FORMAT)
|
||||||
)
|
)
|
||||||
assert stat.emails_requested == 0
|
assert stat.emails_requested == 0
|
||||||
|
assert stat.emails_error == 0
|
||||||
|
assert stat.emails_delivered == 0
|
||||||
assert stat.sms_requested == 1
|
assert stat.sms_requested == 1
|
||||||
|
assert stat.sms_error == 0
|
||||||
|
assert stat.sms_delivered == 0
|
||||||
assert stat.day == notification.created_at.strftime(DATE_FORMAT)
|
assert stat.day == notification.created_at.strftime(DATE_FORMAT)
|
||||||
assert stat.service_id == notification.service_id
|
assert stat.service_id == notification.service_id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user