Exemplo n.º 1
0
 def test_patient_reminder_time(self):
     contact = self.create_contact({'pin': '1234'})
     backend = self.create_backend(data={'name': 'mockbackend'})
     self.create_connection({'contact': contact,
                                          'backend': backend})
     now = datetime.datetime.now()
     reminders.Notification.objects.create(num_days=1,
                                                          time_of_day=now)
     tomorrow = datetime.date.today() + datetime.timedelta(days=1)
     next_hour = now + + datetime.timedelta(hours=1)
     patient = Patient.objects.create(contact=contact,
                                      date_enrolled=datetime.date.today(),
                                      subject_number='1234',
                                      mobile_number='tester',
                                      next_visit=tomorrow,
                                      reminder_time=next_hour.time())
     # run cronjob
     scheduler_callback(self.router)
     queued = contact.sent_notifications.filter(status='queued').count()
     sent = contact.sent_notifications.filter(status='sent').count()
     # patient message should be queued since they have
     # asked for a later time
     self.assertEqual(queued, 1)
     # no messages ready to be sent
     self.assertEqual(sent, 0)
     message = contact.sent_notifications.filter(status='queued')[0]
     self.assertTrue(message.date_sent is None)
     self.assertEqual(message.date_to_send,
                      datetime.datetime.combine(now, patient.reminder_time))
Exemplo n.º 2
0
 def test_patient_reminder_time(self):
     contact = self.create_contact({'pin': '1234'})
     backend = self.create_backend(data={'name': 'mockbackend'})
     self.create_connection({'contact': contact, 'backend': backend})
     now = datetime.datetime.now()
     reminders.Notification.objects.create(num_days=1, time_of_day=now)
     tomorrow = datetime.date.today() + datetime.timedelta(days=1)
     next_hour = now + +datetime.timedelta(hours=1)
     patient = Patient.objects.create(contact=contact,
                                      date_enrolled=datetime.date.today(),
                                      subject_number='1234',
                                      mobile_number='tester',
                                      next_visit=tomorrow,
                                      reminder_time=next_hour.time())
     # run cronjob
     scheduler_callback(self.router)
     queued = contact.sent_notifications.filter(status='queued').count()
     sent = contact.sent_notifications.filter(status='sent').count()
     # patient message should be queued since they have
     # asked for a later time
     self.assertEqual(queued, 1)
     # no messages ready to be sent
     self.assertEqual(sent, 0)
     message = contact.sent_notifications.filter(status='queued')[0]
     self.assertTrue(message.date_sent is None)
     self.assertEqual(message.date_to_send,
                      datetime.datetime.combine(now, patient.reminder_time))
Exemplo n.º 3
0
 def test_scheduler(self):
     contact = self.create_contact({'pin': '1234'})
     backend = self.create_backend(data={'name': 'mockbackend'})
     self.create_connection({'contact': contact, 'backend': backend})
     now = datetime.datetime.now()
     reminders.Notification.objects.create(num_days=1, time_of_day=now)
     tomorrow = datetime.date.today() + datetime.timedelta(days=1)
     Patient.objects.create(contact=contact,
                            date_enrolled=datetime.date.today(),
                            subject_number='1234',
                            mobile_number='tester',
                            next_visit=tomorrow)
     # run cronjob
     scheduler_callback(self.router)
     queued = contact.sent_notifications.filter(status='queued').count()
     sent = contact.sent_notifications.filter(status='sent').count()
     # nothing should be queued (future broadcast isn't ready)
     self.assertEqual(queued, 0)
     # only one message should be sent
     self.assertEqual(sent, 1)
     message = contact.sent_notifications.filter(status='sent')[0]
     self.assertTrue(message.date_sent is not None)
Exemplo n.º 4
0
 def test_scheduler(self):
     contact = self.create_contact({'pin': '1234'})
     backend = self.create_backend(data={'name': 'mockbackend'})
     self.create_connection({'contact': contact,
                                          'backend': backend})
     now = datetime.datetime.now()
     reminders.Notification.objects.create(num_days=1,
                                           time_of_day=now)
     tomorrow = datetime.date.today() + datetime.timedelta(days=1)
     Patient.objects.create(contact=contact,
                                      date_enrolled=datetime.date.today(),
                                      subject_number='1234',
                                      mobile_number='tester',
                                      next_visit=tomorrow)
     # run cronjob
     scheduler_callback(self.router)
     queued = contact.sent_notifications.filter(status='queued').count()
     sent = contact.sent_notifications.filter(status='sent').count()
     # nothing should be queued (future broadcast isn't ready)
     self.assertEqual(queued, 0)
     # only one message should be sent
     self.assertEqual(sent, 1)
     message = contact.sent_notifications.filter(status='sent')[0]
     self.assertTrue(message.date_sent is not None)
Exemplo n.º 5
0
 def run(self):
     router = Router()
     scheduler_callback(router)