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:
Adam Shimali
2016-02-09 12:48:27 +00:00
parent d24a356205
commit e5e049d735
4 changed files with 15 additions and 14 deletions

View File

@@ -6,8 +6,8 @@ def save_notification(notification, update_dict={}):
if update_dict:
update_dict.pop('id', None)
update_dict.pop('job', None)
update_dict.pop('service_id', None)
update_dict.pop('template_id', None)
update_dict.pop('service', None)
update_dict.pop('template', None)
Notification.query.filter_by(id=notification.id).update(update_dict)
else:
db.session.add(notification)

View File

@@ -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 = 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')
template_id = db.Column(db.BigInteger, db.ForeignKey('templates.id'), index=True, unique=False)
template = db.relationship('Template')
created_at = db.Column(
db.DateTime,
index=False,

View File

@@ -202,9 +202,9 @@ def sample_notification(notify_db,
data = {
'id': notificaton_id,
'to': to,
'job_id': job.id,
'service_id': service.id,
'template_id': template.id
'job': job,
'service': service,
'template': template
}
notification = Notification(**data)
save_notification(notification)

View File

@@ -15,13 +15,12 @@ def test_save_notification(notify_db, notify_db_session, sample_template, sample
notification_id = uuid.uuid4()
to = '+44709123456'
job_id = sample_job.id
data = {
'id': notification_id,
'to': to,
'job_id': job_id,
'service_id': sample_template.service.id,
'template_id': sample_template.id
'job': sample_job,
'service': sample_template.service,
'template': sample_template
}
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['to'] == notification_from_db.to
assert data['job_id'] == notification_from_db.job_id
assert data['service_id'] == notification_from_db.service_id
assert data['template_id'] == notification_from_db.template_id
assert data['job'] == notification_from_db.job
assert data['service'] == notification_from_db.service
assert data['template'] == notification_from_db.template
assert 'sent' == notification_from_db.status
@@ -63,8 +62,8 @@ def test_update_notification(notify_db, notify_db_session, sample_notification):
update_dict = {
'id': sample_notification.id,
'service_id': sample_notification.service_id,
'template_id': sample_notification.template_id,
'service': sample_notification.service,
'template': sample_notification.template,
'job': sample_notification.job,
'status': 'failed'
}