mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Added service and template relationship to notification model.
This makes it more consistent with other model classes with respect to marhmallow serialisation/deserialisation.
This commit is contained in:
@@ -6,8 +6,8 @@ def save_notification(notification, update_dict={}):
|
|||||||
if update_dict:
|
if update_dict:
|
||||||
update_dict.pop('id', None)
|
update_dict.pop('id', None)
|
||||||
update_dict.pop('job', None)
|
update_dict.pop('job', None)
|
||||||
update_dict.pop('service_id', None)
|
update_dict.pop('service', None)
|
||||||
update_dict.pop('template_id', None)
|
update_dict.pop('template', None)
|
||||||
Notification.query.filter_by(id=notification.id).update(update_dict)
|
Notification.query.filter_by(id=notification.id).update(update_dict)
|
||||||
else:
|
else:
|
||||||
db.session.add(notification)
|
db.session.add(notification)
|
||||||
|
|||||||
@@ -203,7 +203,9 @@ class Notification(db.Model):
|
|||||||
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, nullable=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')
|
||||||
template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False)
|
template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False)
|
||||||
|
template = db.relationship('Template')
|
||||||
created_at = db.Column(
|
created_at = db.Column(
|
||||||
db.DateTime,
|
db.DateTime,
|
||||||
index=False,
|
index=False,
|
||||||
|
|||||||
@@ -202,9 +202,9 @@ def sample_notification(notify_db,
|
|||||||
data = {
|
data = {
|
||||||
'id': notificaton_id,
|
'id': notificaton_id,
|
||||||
'to': to,
|
'to': to,
|
||||||
'job_id': job.id,
|
'job': job,
|
||||||
'service_id': service.id,
|
'service': service,
|
||||||
'template_id': template.id
|
'template': template
|
||||||
}
|
}
|
||||||
notification = Notification(**data)
|
notification = Notification(**data)
|
||||||
save_notification(notification)
|
save_notification(notification)
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ def test_save_notification(notify_db, notify_db_session, sample_template, sample
|
|||||||
|
|
||||||
notification_id = uuid.uuid4()
|
notification_id = uuid.uuid4()
|
||||||
to = '+44709123456'
|
to = '+44709123456'
|
||||||
job_id = sample_job.id
|
|
||||||
data = {
|
data = {
|
||||||
'id': notification_id,
|
'id': notification_id,
|
||||||
'to': to,
|
'to': to,
|
||||||
'job_id': job_id,
|
'job': sample_job,
|
||||||
'service_id': sample_template.service.id,
|
'service': sample_template.service,
|
||||||
'template_id': sample_template.id
|
'template': sample_template
|
||||||
}
|
}
|
||||||
|
|
||||||
notification = Notification(**data)
|
notification = Notification(**data)
|
||||||
@@ -33,9 +32,9 @@ def test_save_notification(notify_db, notify_db_session, sample_template, sample
|
|||||||
|
|
||||||
assert data['id'] == notification_from_db.id
|
assert data['id'] == notification_from_db.id
|
||||||
assert data['to'] == notification_from_db.to
|
assert data['to'] == notification_from_db.to
|
||||||
assert data['job_id'] == notification_from_db.job_id
|
assert data['job'] == notification_from_db.job
|
||||||
assert data['service_id'] == notification_from_db.service_id
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template_id'] == notification_from_db.template_id
|
assert data['template'] == notification_from_db.template
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sent' == notification_from_db.status
|
||||||
|
|
||||||
|
|
||||||
@@ -63,8 +62,8 @@ def test_update_notification(notify_db, notify_db_session, sample_notification):
|
|||||||
|
|
||||||
update_dict = {
|
update_dict = {
|
||||||
'id': sample_notification.id,
|
'id': sample_notification.id,
|
||||||
'service_id': sample_notification.service_id,
|
'service': sample_notification.service,
|
||||||
'template_id': sample_notification.template_id,
|
'template': sample_notification.template,
|
||||||
'job': sample_notification.job,
|
'job': sample_notification.job,
|
||||||
'status': 'failed'
|
'status': 'failed'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user