mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
Ensure the relationship between Notification and ScheduledNotification is one-to-one.
Update db script with the right number
This commit is contained in:
@@ -709,7 +709,7 @@ class Notification(db.Model):
|
|||||||
foreign(template_version) == remote(TemplateHistory.version)
|
foreign(template_version) == remote(TemplateHistory.version)
|
||||||
))
|
))
|
||||||
|
|
||||||
scheduled_for = db.relationship('ScheduledNotification')
|
scheduled_notification = db.relationship('ScheduledNotification', uselist=False)
|
||||||
|
|
||||||
client_reference = db.Column(db.String, index=True, nullable=True)
|
client_reference = db.Column(db.String, index=True, nullable=True)
|
||||||
|
|
||||||
@@ -872,8 +872,8 @@ class Notification(db.Model):
|
|||||||
"created_at": self.created_at.strftime(DATETIME_FORMAT),
|
"created_at": self.created_at.strftime(DATETIME_FORMAT),
|
||||||
"sent_at": self.sent_at.strftime(DATETIME_FORMAT) if self.sent_at else None,
|
"sent_at": self.sent_at.strftime(DATETIME_FORMAT) if self.sent_at else None,
|
||||||
"completed_at": self.completed_at(),
|
"completed_at": self.completed_at(),
|
||||||
"scheduled_for": self.scheduled_for[0].scheduled_for.strftime(
|
"scheduled_for": self.scheduled_notification.scheduled_for.strftime(
|
||||||
DATETIME_FORMAT) if self.scheduled_for else None
|
DATETIME_FORMAT) if self.scheduled_notification else None
|
||||||
}
|
}
|
||||||
|
|
||||||
return serialized
|
return serialized
|
||||||
@@ -944,9 +944,8 @@ class ScheduledNotification(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())
|
||||||
notification_id = db.Column(UUID(as_uuid=True), db.ForeignKey('notifications.id'), index=True, nullable=False)
|
notification_id = db.Column(UUID(as_uuid=True), db.ForeignKey('notifications.id'), index=True, nullable=False)
|
||||||
notification = db.relationship('Notification')
|
notification = db.relationship('Notification', uselist=False)
|
||||||
scheduled_for = db.Column(db.DateTime, index=False, nullable=False)
|
scheduled_for = db.Column(db.DateTime, index=False, nullable=False)
|
||||||
pending = db.Column(db.Boolean, nullable=False, default=False)
|
|
||||||
|
|
||||||
|
|
||||||
class InvitedUser(db.Model):
|
class InvitedUser(db.Model):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""empty message
|
"""empty message
|
||||||
|
|
||||||
Revision ID: 0083_scheduled_notifications
|
Revision ID: 0084_scheduled_notifications
|
||||||
Revises: 0083_add_perm_types_and_svc_perm
|
Revises: 0083_add_perm_types_and_svc_perm
|
||||||
Create Date: 2017-05-15 12:50:20.041950
|
Create Date: 2017-05-15 12:50:20.041950
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ from alembic import op
|
|||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy.dialects import postgresql
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
revision = '0083_scheduled_notifications'
|
revision = '0084_scheduled_notifications'
|
||||||
down_revision = '0083_add_perm_types_and_svc_perm'
|
down_revision = '0083_add_perm_types_and_svc_perm'
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +18,6 @@ def upgrade():
|
|||||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.Column('scheduled_for', sa.DateTime(), nullable=False),
|
sa.Column('scheduled_for', sa.DateTime(), nullable=False),
|
||||||
sa.Column('pending', sa.Boolean(), nullable=False),
|
|
||||||
sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ),
|
sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id')
|
||||||
)
|
)
|
||||||
@@ -716,13 +716,18 @@ def test_save_notification_with_no_job(sample_template, mmg_provider):
|
|||||||
assert notification_from_db.status == 'created'
|
assert notification_from_db.status == 'created'
|
||||||
|
|
||||||
|
|
||||||
def test_get_notification_by_id(sample_notification):
|
def test_get_notification_by_id(notify_db, notify_db_session, client, sample_template):
|
||||||
|
notification = sample_notification(notify_db=notify_db, notify_db_session=notify_db_session,
|
||||||
|
template=sample_template,
|
||||||
|
scheduled_for='2017-05-05 14:00:00',
|
||||||
|
status='created')
|
||||||
notification_from_db = get_notification_with_personalisation(
|
notification_from_db = get_notification_with_personalisation(
|
||||||
sample_notification.service.id,
|
sample_template.service.id,
|
||||||
sample_notification.id,
|
notification.id,
|
||||||
key_type=None
|
key_type=None
|
||||||
)
|
)
|
||||||
assert sample_notification == notification_from_db
|
assert notification == notification_from_db
|
||||||
|
assert notification_from_db.scheduled_notification.scheduled_for == datetime(2017, 5, 5, 14, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_get_notifications_by_reference(notify_db, notify_db_session, sample_service):
|
def test_get_notifications_by_reference(notify_db, notify_db_session, sample_service):
|
||||||
|
|||||||
Reference in New Issue
Block a user