mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Merge pull request #67 from alphagov/notfication-job-nullable
job on notification now nullable.
This commit is contained in:
@@ -200,7 +200,7 @@ class Notification(db.Model):
|
|||||||
|
|
||||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||||
to = db.Column(db.String, nullable=False)
|
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'))
|
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_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False)
|
||||||
service = db.relationship('Service')
|
service = db.relationship('Service')
|
||||||
|
|||||||
30
migrations/versions/0014_job_id_nullable.py
Normal file
30
migrations/versions/0014_job_id_nullable.py
Normal file
@@ -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 ###
|
||||||
@@ -31,6 +31,28 @@ def test_save_notification(notify_db, notify_db_session, sample_template, sample
|
|||||||
assert 'sent' == notification_from_db.status
|
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):
|
def test_get_notification_for_job(notify_db, notify_db_session, sample_notification):
|
||||||
notifcation_from_db = get_notification(sample_notification.service.id,
|
notifcation_from_db = get_notification(sample_notification.service.id,
|
||||||
sample_notification.job_id,
|
sample_notification.job_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user