From 3a2cfc96e6be261ec8133f1f63589da00bb6705a Mon Sep 17 00:00:00 2001 From: Adam Shimali Date: Wed, 10 Feb 2016 11:08:24 +0000 Subject: [PATCH] job on notification now nullable. --- app/models.py | 2 +- migrations/versions/0014_job_id_nullable.py | 30 +++++++++++++++++++++ tests/app/dao/test_notification_dao.py | 22 +++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/0014_job_id_nullable.py diff --git a/app/models.py b/app/models.py index 1282a2ac0..4b53483dc 100644 --- a/app/models.py +++ b/app/models.py @@ -200,7 +200,7 @@ class Notification(db.Model): id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) to = db.Column(db.String, nullable=False) - job_id = db.Column(UUID(as_uuid=True), db.ForeignKey('jobs.id'), index=True, unique=False, nullable=False) + job_id = db.Column(UUID(as_uuid=True), db.ForeignKey('jobs.id'), index=True, unique=False) job = db.relationship('Job', backref=db.backref('notifications', lazy='dynamic')) service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False) service = db.relationship('Service') diff --git a/migrations/versions/0014_job_id_nullable.py b/migrations/versions/0014_job_id_nullable.py new file mode 100644 index 000000000..8c27b3ce1 --- /dev/null +++ b/migrations/versions/0014_job_id_nullable.py @@ -0,0 +1,30 @@ +"""empty message + +Revision ID: 0014_job_id_nullable +Revises: 0013_add_notifications +Create Date: 2016-02-10 10:57:39.414061 + +""" + +# revision identifiers, used by Alembic. +revision = '0014_job_id_nullable' +down_revision = '0013_add_notifications' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.alter_column('notifications', 'job_id', + existing_type=postgresql.UUID(), + nullable=True) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.alter_column('notifications', 'job_id', + existing_type=postgresql.UUID(), + nullable=False) + ### end Alembic commands ### diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index 9cbf6b6d9..a28851520 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -31,6 +31,28 @@ def test_save_notification(notify_db, notify_db_session, sample_template, sample assert 'sent' == notification_from_db.status +def test_save_notification_no_job_id(notify_db, notify_db_session, sample_template): + + assert Notification.query.count() == 0 + to = '+44709123456' + data = { + 'to': to, + 'service': sample_template.service, + 'template': sample_template + } + + notification = Notification(**data) + save_notification(notification) + + assert Notification.query.count() == 1 + notification_from_db = Notification.query.all()[0] + assert notification_from_db.id + assert data['to'] == notification_from_db.to + assert data['service'] == notification_from_db.service + assert data['template'] == notification_from_db.template + assert 'sent' == notification_from_db.status + + def test_get_notification_for_job(notify_db, notify_db_session, sample_notification): notifcation_from_db = get_notification(sample_notification.service.id, sample_notification.job_id,