Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
    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))))
Ejemplo n.º 6
0
 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))
Ejemplo n.º 7
0
    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))))
Ejemplo n.º 8
0
    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))))
Ejemplo n.º 9
0
    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()
Ejemplo n.º 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)
Ejemplo n.º 11
0
 def all_user_notifications(self, user_id):
     return list(
         map(
             self.to_notification_instance,
             list(Notification.select().where(
                 Notification.user_id == user_id))))
Ejemplo n.º 12
0
 def get_by_id(self, notification_id):
     try:
         return self.to_notification_instance(
             Notification.get(Notification.id == notification_id))
     except DoesNotExist:
         return None
Ejemplo n.º 13
0
 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()
Ejemplo n.º 14
0
 def delete_by_id(self, notification_id):
     Notification.delete().where(
         Notification.id == notification_id).execute()