Exemplo n.º 1
0
 def setUp(self):
     self.contact = self.create_contact()
     self.backend = self.create_backend(data={'name': 'mockbackend'})
     self.unreg_conn = self.create_connection({'backend': self.backend})
     self.reg_conn = self.create_connection({
         'contact': self.contact,
         'backend': self.backend
     })
     self.router = MockRouter()
     self.app = RemindersApp(router=self.router)
Exemplo n.º 2
0
 def setUp(self):
     self.contact = self.create_contact()
     self.backend = self.create_backend(data={'name': 'mockbackend'})
     self.unreg_conn = self.create_connection({'backend': self.backend})
     self.reg_conn = self.create_connection({'contact': self.contact,
                                             'backend': self.backend})
     self.router = MockRouter()
     self.app = RemindersApp(router=self.router)
Exemplo n.º 3
0
def messages(request):
    
    try:
        days = Notification.objects.order_by('?')[0].num_days
    except IndexError:
        days = 2
    date = datetime.date.today() + datetime.timedelta(days=days)
    msg = RemindersApp._notification_msg(date)
    return {
        'reminder_message': msg,
    }
Exemplo n.º 4
0
class RemindersConfirmHandlerTest(RemindersCreateDataTest):

    def setUp(self):
        self.contact = self.create_contact()
        self.backend = self.create_backend(data={'name': 'mockbackend'})
        self.unreg_conn = self.create_connection({'backend': self.backend})
        self.reg_conn = self.create_connection({'contact': self.contact,
                                                'backend': self.backend})
        self.router = MockRouter()
        self.app = RemindersApp(router=self.router)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.handle(msg)
        return msg

    def test_unregistered(self):
        """ test the response from an unregistered user """
        msg = self._send(self.unreg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.not_registered)

    def test_registered_no_notifications(self):
        """
        test the response from a registered user without any notifications
        """
        msg = self._send(self.reg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.no_reminders)

    def test_registered_pin_required(self):
        """
        test the response from a registered user without any notifications
        """
        self.contact.pin = '1234'
        self.contact.save()
        msg = self._send(self.reg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.pin_required)

    def test_registered_incorrect_pin(self):
        """
        test the response from a registered user without any notifications
        """
        self.contact.pin = '1234'
        self.contact.save()
        msg = self._send(self.reg_conn, '4444')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.incorrect_pin)

    def test_registered_with_notification(self):
        """ test the response from a user with a pending notification """
        now = datetime.datetime.now()
        notification = reminders.Notification.objects.create(num_days=1,
                                                             time_of_day=now)
        reminders.SentNotification.objects.create(notification=notification,
                                                  recipient=self.contact,
                                                  status='sent',
                                                  message='abc',
                                                  appt_date=now,
                                                  date_to_send=now,
                                                  date_queued=now)
        msg = self._send(self.reg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.thank_you)
        sent_notif = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notif.count(), 1)
        self.assertEqual(sent_notif[0].status, 'confirmed')

    def test_registered_with_notification_and_pin(self):
        """ test the response from a user with a pending notification """
        now = datetime.datetime.now()
        self.contact.pin = '1234'
        self.contact.save()
        notification = reminders.Notification.objects.create(num_days=1,
                                                             time_of_day=now)
        reminders.SentNotification.objects.create(notification=notification,
                                                  recipient=self.contact,
                                                  status='sent',
                                                  message='abc',
                                                  appt_date=now,
                                                  date_to_send=now,
                                                  date_queued=now)
        msg = self._send(self.reg_conn, '1234')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text,
                         self.app.thank_you)
        sent_notif = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notif.count(), 1)
        self.assertEqual(sent_notif[0].status, 'confirmed')

    def test_forward_broadcast(self):
        """Confirmations should be forwarded to
        DEFAULT_CONFIRMATIONS_GROUP_NAME"""
        now = datetime.datetime.now()
        notification = reminders.Notification.objects.create(num_days=1,
                                                             time_of_day=now)
        reminders.SentNotification.objects.create(notification=notification,
                                                  recipient=self.contact,
                                                  status='sent',
                                                  message='abc',
                                                  appt_date=now,
                                                  date_to_send=now,
                                                  date_queued=now)
        self._send(self.reg_conn, '1')
        group = Group.objects.get(name=settings.
                                  DEFAULT_CONFIRMATIONS_GROUP_NAME)
        broadcasts = group.broadcasts.filter(schedule_frequency='one-time')
        self.assertEqual(broadcasts.count(), 1)
Exemplo n.º 5
0
class RemindersConfirmHandlerTest(RemindersCreateDataTest):
    def setUp(self):
        self.contact = self.create_contact()
        self.backend = self.create_backend(data={'name': 'mockbackend'})
        self.unreg_conn = self.create_connection({'backend': self.backend})
        self.reg_conn = self.create_connection({
            'contact': self.contact,
            'backend': self.backend
        })
        self.router = MockRouter()
        self.app = RemindersApp(router=self.router)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.handle(msg)
        return msg

    def test_unregistered(self):
        """ test the response from an unregistered user """
        msg = self._send(self.unreg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.not_registered)

    def test_registered_no_notifications(self):
        """
        test the response from a registered user without any notifications
        """
        msg = self._send(self.reg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.no_reminders)

    def test_registered_pin_required(self):
        """
        test the response from a registered user without any notifications
        """
        self.contact.pin = '1234'
        self.contact.save()
        msg = self._send(self.reg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.pin_required)

    def test_registered_incorrect_pin(self):
        """
        test the response from a registered user without any notifications
        """
        self.contact.pin = '1234'
        self.contact.save()
        msg = self._send(self.reg_conn, '4444')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.incorrect_pin)

    def test_registered_with_notification(self):
        """ test the response from a user with a pending notification """
        now = datetime.datetime.now()
        notification = reminders.Notification.objects.create(num_days=1,
                                                             time_of_day=now)
        reminders.SentNotification.objects.create(notification=notification,
                                                  recipient=self.contact,
                                                  status='sent',
                                                  message='abc',
                                                  appt_date=now,
                                                  date_to_send=now,
                                                  date_queued=now)
        msg = self._send(self.reg_conn, '1')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.thank_you)
        sent_notif = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notif.count(), 1)
        self.assertEqual(sent_notif[0].status, 'confirmed')

    def test_registered_with_notification_and_pin(self):
        """ test the response from a user with a pending notification """
        now = datetime.datetime.now()
        self.contact.pin = '1234'
        self.contact.save()
        notification = reminders.Notification.objects.create(num_days=1,
                                                             time_of_day=now)
        reminders.SentNotification.objects.create(notification=notification,
                                                  recipient=self.contact,
                                                  status='sent',
                                                  message='abc',
                                                  appt_date=now,
                                                  date_to_send=now,
                                                  date_queued=now)
        msg = self._send(self.reg_conn, '1234')
        self.assertEqual(len(msg.responses), 1)
        self.assertEqual(msg.responses[0].text, self.app.thank_you)
        sent_notif = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notif.count(), 1)
        self.assertEqual(sent_notif[0].status, 'confirmed')

    def test_forward_broadcast(self):
        """Confirmations should be forwarded to
        DEFAULT_CONFIRMATIONS_GROUP_NAME"""
        now = datetime.datetime.now()
        notification = reminders.Notification.objects.create(num_days=1,
                                                             time_of_day=now)
        reminders.SentNotification.objects.create(notification=notification,
                                                  recipient=self.contact,
                                                  status='sent',
                                                  message='abc',
                                                  appt_date=now,
                                                  date_to_send=now,
                                                  date_queued=now)
        self._send(self.reg_conn, '1')
        group = Group.objects.get(
            name=settings.DEFAULT_CONFIRMATIONS_GROUP_NAME)
        broadcasts = group.broadcasts.filter(schedule_frequency='one-time')
        self.assertEqual(broadcasts.count(), 1)