示例#1
0
 def test_deletes_notification_by_id(self):
     notification_id = self.notifications_controller.create(
         self.notification).id
     self.notifications_controller.delete(notification_id)
     self.assertEqual(
         Notification.select().where(
             Notification.id == notification_id).count(), 0)
示例#2
0
 def test_deletes_notification_by_id(self):
     notification_id = self.notification_storage.create(
         self.notification).id
     self.notification_storage.delete_by_id(notification_id)
     self.assertEqual(
         Notification.select().where(
             Notification.id == notification_id).count(), 0)
示例#3
0
 def test_sets_notification_status_as_shown(self):
     notification_with_id = self.notifications_controller.create(
         self.notification)
     self.notifications_controller.set_as_shown(notification_with_id.id)
     notification_from_db = Notification.get(
         Notification.id == notification_with_id.id)
     self.assertEqual(notification_from_db.status,
                      NotificationStatus.SHOWN.value)
示例#4
0
 def test_updates_notification(self):
     new_title = "Updated title"
     notification_with_id = self.notification_storage.create(
         self.notification)
     notification_with_id.title = new_title
     self.notification_storage.update(notification_with_id)
     notification_from_db = Notification.get(
         Notification.id == notification_with_id.id)
     self.assertEqual(notification_from_db.title, new_title)
    def shown(self, user_id):
        """Returns notifications with SHOWN status for user with ID == user_id"""

        return list(
            map(
                self.to_notification_instance,
                list(Notification.select().where(
                    Notification.user_id == user_id,
                    Notification.status == NotificationStatus.SHOWN.value))))
 def create(self, notification):
     return self.to_notification_instance(
         Notification.create(
             id=notification.id,
             title=notification.title,
             user_id=notification.user_id,
             task_id=notification.task_id,
             status=notification.status,
             relative_start_time=notification.relative_start_time))
    def created(self, user_id):
        """Returns notifications with CREATED status for user with ID == user_id"""

        return list(
            map(
                self.to_notification_instance,
                list(Notification.select().where(
                    Notification.user_id == user_id,
                    Notification.status == NotificationStatus.CREATED.value))))
    def pending(self, user_id):
        """Returns notifications with PENDING status for user with ID == user_id"""

        return list(
            map(
                self.to_notification_instance,
                list(Notification.select().where(
                    Notification.user_id == user_id,
                    Notification.status == NotificationStatus.PENDING.value))))
    def process_notifications(self):
        """Changes notification status from CREATED to PENDING if it's time to show notification"""

        for notification in Notification.select().where(
                Notification.status == NotificationStatus.CREATED.value).join(
                    Task).where(Task.id == Notification.task_id):
            task = Task.get(Task.id == notification.task_id)
            if (task.start_time - datetime.timedelta(
                    seconds=notification.relative_start_time)
                ) < datetime.datetime.now():
                notification.status = NotificationStatus.PENDING.value
                notification.save()
示例#10
0
 def test_creates_notification(self):
     before_notifications_count = Notification.select().count()
     self.notification_storage.create(self.notification)
     after_notifications_count = Notification.select().count()
     self.assertEqual(before_notifications_count + 1,
                      after_notifications_count)
 def all_user_notifications(self, user_id):
     return list(
         map(
             self.to_notification_instance,
             list(Notification.select().where(
                 Notification.user_id == user_id))))
 def get_by_id(self, notification_id):
     try:
         return self.to_notification_instance(
             Notification.get(Notification.id == notification_id))
     except DoesNotExist:
         return None
 def update(self, notification):
     Notification.update(
         title=notification.title,
         status=notification.status,
         relative_start_time=notification.relative_start_time).where(
             Notification.id == notification.id).execute()
 def delete_by_id(self, notification_id):
     Notification.delete().where(
         Notification.id == notification_id).execute()