예제 #1
0
파일: tests.py 프로젝트: AndreLesa/mwana
    def testRemindersSentOnlyOnce(self):
        """
        tests that notification messages are sent only sent once
        """
        birth = reminders.Event.objects.create(name="Birth", slug="birth")
        birth.appointments.create(name='1 day', num_days=2)
        patient1 = Contact.objects.create(name='patient 1')
        
        # this gets the backend and connection in the db
        self.runScript("""cba > hello world""")
        # take a break to allow the router thread to catch up; otherwise we
        # get some bogus messages when they're retrieved below
        time.sleep(.1)
        cba_conn = Connection.objects.get(identity="cba")
        birth.patient_events.create(patient=patient1, cba_conn=cba_conn,
                                    date=datetime.datetime.today())
        self.startRouter()
        tasks.send_notifications(self.router)
        # just the 1 and two day notifications should go out;
        # 3 patients x 2 notifications = 6 messages
        messages = self.receiveAllMessages()
        self.assertEqual(len(messages), 1)
        sent_notifications = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notifications.count(), 1)

        # make sure no new messages go out if the method is called again
        tasks.send_notifications(self.router)
        messages = self.receiveAllMessages()
        self.assertEqual(len(messages), 0)
        sent_notifications = reminders.SentNotification.objects.all()
        # number of sent notifications should still be 1 (not 2)
        self.assertEqual(sent_notifications.count(), 1)
        
        self.stopRouter()
예제 #2
0
파일: tests.py 프로젝트: AndreLesa/mwana
 def testRemindersRegistered(self):
     birth = reminders.Event.objects.create(name="Birth", slug="birth")
     birth.appointments.create(name='1 day', num_days=2)
     clinic = LocationType.objects.create(singular='Clinic',
                                          plural='Clinics', slug='clinic')
     central = Location.objects.create(name='Central Clinic', type=clinic)
     patient1 = Contact.objects.create(name='Henry', location=central)
     
     # this gets the backend and connection in the db
     self.runScript("""cba > hello world""")
     # take a break to allow the router thread to catch up; otherwise we
     # get some bogus messages when they're retrieved below
     time.sleep(.1)
     cba_conn = Connection.objects.get(identity="cba")
     cba = Contact.objects.create(name='cba', location=central)
     cba_type = ContactType.objects.create(name='CBA', slug='cba')
     cba.types.add(cba_type)
     cba_conn.contact = cba
     cba_conn.save()
     birth.patient_events.create(patient=patient1, cba_conn=cba_conn,
                                 date=datetime.datetime.today())
     self.startRouter()
     tasks.send_notifications(self.router)
     # just the 1 and two day notifications should go out;
     # 3 patients x 2 notifications = 6 messages
     messages = self.receiveAllMessages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "Hello cba. Henry is due for "
                      "their 1 day clinic appointment. Please "
                      "remind this person and ensure they visit "
                      "Central Clinic within 3 days.")
     sent_notifications = reminders.SentNotification.objects.all()
     self.assertEqual(sent_notifications.count(), 1)
예제 #3
0
파일: tests.py 프로젝트: kaofelix/mwana
 def testRemindersNoLocation(self):
     birth = reminders.Event.objects.create(name="Birth", slug="birth")
     birth.appointments.create(name='1 day', num_days=2)
     patient1 = Contact.objects.create(name='Henry')
     
     # this gets the backend and connection in the db
     self.runScript("""cba > hello world""")
     # take a break to allow the router thread to catch up; otherwise we
     # get some bogus messages when they're retrieved below
     time.sleep(.1)
     cba_conn = Connection.objects.get(identity="cba")
     cba = Contact.objects.create(name='Rupiah Banda')
     cba_conn.contact = cba
     cba_conn.save()
     birth.patient_events.create(patient=patient1, cba_conn=cba_conn,
                                 date=datetime.datetime.today())
     self.startRouter()
     tasks.send_notifications(self.router)
     # just the 1 and two day notifications should go out;
     # 3 patients x 2 notifications = 6 messages
     messages = self.receiveAllMessages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "Hello Rupiah Banda. Henry is due "
                      "for their next clinic appointment. Please deliver a "
                      "reminder to this person and ensure they visit "
                      "the clinic within 3 days.")
     sent_notifications = reminders.SentNotification.objects.all()
     self.assertEqual(sent_notifications.count(), 1)
예제 #4
0
파일: tests.py 프로젝트: makandok/mwana
    def testRemindersNoLocation(self):
        birth = reminders.Event.objects.create(name="Birth", slug="birth")
        birth.appointments.create(name='1 day', num_days=2)
        patient1 = Contact.objects.create(name='Henry')

        # this gets the backend and connection in the db
        self.runScript("""cba > hello world""")
        # take a break to allow the router thread to catch up; otherwise we
        # get some bogus messages when they're retrieved below
        time.sleep(.1)
        cba_conn = Connection.objects.get(identity="cba")
        cba = Contact.objects.create(name='Rupiah Banda')
        cba_conn.contact = cba
        cba_conn.save()
        birth.patient_events.create(patient=patient1,
                                    cba_conn=cba_conn,
                                    date=datetime.datetime.today())
        self.startRouter()
        tasks.send_notifications(self.router)
        # just the 1 and two day notifications should go out;
        # 3 patients x 2 notifications = 6 messages
        messages = self.receiveAllMessages()
        self.assertEqual(len(messages), 1)
        self.assertEqual(
            messages[0].text, "Hello Rupiah Banda. Henry is due "
            "for their 1 day clinic appointment. Please "
            "remind this person and ensure they visit "
            "the clinic within 3 days.")
        sent_notifications = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notifications.count(), 1)
예제 #5
0
파일: tests.py 프로젝트: makandok/mwana
    def testRemindersSentOnlyOnce(self):
        """
        tests that notification messages are sent only sent once
        """
        birth = reminders.Event.objects.create(name="Birth", slug="birth")
        birth.appointments.create(name='1 day', num_days=2)
        patient1 = Contact.objects.create(name='patient 1')

        # this gets the backend and connection in the db
        self.runScript("""cba > hello world""")
        # take a break to allow the router thread to catch up; otherwise we
        # get some bogus messages when they're retrieved below
        time.sleep(.1)
        cba_conn = Connection.objects.get(identity="cba")
        birth.patient_events.create(patient=patient1,
                                    cba_conn=cba_conn,
                                    date=datetime.datetime.today())
        self.startRouter()
        tasks.send_notifications(self.router)
        # just the 1 and two day notifications should go out;
        # 3 patients x 2 notifications = 6 messages
        messages = self.receiveAllMessages()
        self.assertEqual(len(messages), 1)
        sent_notifications = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notifications.count(), 1)

        # make sure no new messages go out if the method is called again
        tasks.send_notifications(self.router)
        messages = self.receiveAllMessages()
        self.assertEqual(len(messages), 0)
        sent_notifications = reminders.SentNotification.objects.all()
        # number of sent notifications should still be 1 (not 2)
        self.assertEqual(sent_notifications.count(), 1)

        self.stopRouter()
예제 #6
0
파일: tests.py 프로젝트: AndreLesa/mwana
 def testSendReminders(self):
     birth = reminders.Event.objects.create(name="Birth", slug="birth",
                                            gender="f")
     birth.appointments.create(name='2 day', num_days=2)
     birth.appointments.create(name='3 day', num_days=3)
     birth.appointments.create(name='4 day', num_days=4)
     clinic = LocationType.objects.create(slug=const.CLINIC_SLUGS[0])
     zone = const.get_zone_type()
     central = Location.objects.create(name='Central Clinic', type=clinic)
     zone1 = Location.objects.create(name='Zone 1', type=zone,
                                     parent=central, slug='zone1')
     zone2 = Location.objects.create(name='Zone 2', type=zone,
                                     parent=central, slug='zone2')
     patient1 = Contact.objects.create(name='patient 1', location=zone1)
     patient2 = Contact.objects.create(name='patient 2', location=zone1)
     patient3 = Contact.objects.create(name='patient 3', location=zone2)
     
     # this gets the backend and connection in the db
     self.runScript("""
     cba1 > hello world
     cba2 > hello world
     """)
     # take a break to allow the router thread to catch up; otherwise we
     # get some bogus messages when they're retrieved below
     time.sleep(.1)
     cba_t = const.get_cba_type()
     cba1_conn = Connection.objects.get(identity="cba1")
     cba1 = Contact.objects.create(name='cba1', location=zone1)
     cba1.types.add(cba_t)
     cba1_conn.contact = cba1
     cba1_conn.save()
     cba2_conn = Connection.objects.get(identity="cba2")
     cba2 = Contact.objects.create(name='cba2', location=zone2)
     cba2.types.add(cba_t)
     cba2_conn.contact = cba2
     cba2_conn.save()
     birth.patient_events.create(patient=patient1, cba_conn=cba1_conn,
                                 date=datetime.datetime.today())
     birth.patient_events.create(patient=patient2, cba_conn=cba1_conn,
                                 date=datetime.datetime.today())
     birth.patient_events.create(patient=patient3, cba_conn=cba2_conn,
                                 date=datetime.datetime.today())
     self.startRouter()
     tasks.send_notifications(self.router)
     # just the 1 and two day notifications should go out;
     # 3 patients x 2 notifications = 6 messages
     messages = self.receiveAllMessages()
     expected_messages =\
         ['Hello cba1. patient 1 is due for their 2 day clinic appointment. '
          'Please remind this person and ensure they '
          'visit Central Clinic within 3 days.',
          'Hello cba1. patient 2 is due for their 2 day clinic appointment. '
          'Please remind this person and ensure they '
          'visit Central Clinic within 3 days.',
          'Hello cba2. patient 3 is due for their 2 day clinic appointment. '
          'Please remind this person and ensure they '
          'visit Central Clinic within 3 days.']
     self.assertEqual(len(messages), len(expected_messages))
     for msg in messages:
         self.assertTrue(msg.text in expected_messages, msg)
     sent_notifications = reminders.SentNotification.objects.all()
     self.assertEqual(sent_notifications.count(), len(expected_messages))
예제 #7
0
파일: tests.py 프로젝트: makandok/mwana
    def testSendReminders(self):
        birth = reminders.Event.objects.create(name="Birth",
                                               slug="birth",
                                               gender="f")
        birth.appointments.create(name='2 day', num_days=2)
        birth.appointments.create(name='3 day', num_days=3)
        birth.appointments.create(name='4 day', num_days=4)
        clinic = LocationType.objects.create(slug=const.CLINIC_SLUGS[0])
        zone = const.get_zone_type()
        central = Location.objects.create(name='Central Clinic', type=clinic)
        zone1 = Location.objects.create(name='Zone 1',
                                        type=zone,
                                        parent=central,
                                        slug='zone1')
        zone2 = Location.objects.create(name='Zone 2',
                                        type=zone,
                                        parent=central,
                                        slug='zone2')
        patient1 = Contact.objects.create(name='patient 1', location=zone1)
        patient2 = Contact.objects.create(name='patient 2', location=zone1)
        patient3 = Contact.objects.create(name='patient 3', location=zone2)

        # this gets the backend and connection in the db
        self.runScript("""
        cba1 > hello world
        cba2 > hello world
        """)
        # take a break to allow the router thread to catch up; otherwise we
        # get some bogus messages when they're retrieved below
        time.sleep(.1)
        cba_t = const.get_cba_type()
        cba1_conn = Connection.objects.get(identity="cba1")
        cba1 = Contact.objects.create(name='cba1', location=zone1)
        cba1.types.add(cba_t)
        cba1_conn.contact = cba1
        cba1_conn.save()
        cba2_conn = Connection.objects.get(identity="cba2")
        cba2 = Contact.objects.create(name='cba2', location=zone2)
        cba2.types.add(cba_t)
        cba2_conn.contact = cba2
        cba2_conn.save()
        birth.patient_events.create(patient=patient1,
                                    cba_conn=cba1_conn,
                                    date=datetime.datetime.today())
        birth.patient_events.create(patient=patient2,
                                    cba_conn=cba1_conn,
                                    date=datetime.datetime.today())
        birth.patient_events.create(patient=patient3,
                                    cba_conn=cba2_conn,
                                    date=datetime.datetime.today())
        self.startRouter()
        tasks.send_notifications(self.router)
        # just the 1 and two day notifications should go out;
        # 3 patients x 2 notifications = 6 messages
        messages = self.receiveAllMessages()
        expected_messages =\
            ['Hello cba1. patient 1 is due for their 2 day clinic appointment. '
             'Please remind this person and ensure they '
             'visit Central Clinic within 3 days.',
             'Hello cba1. patient 2 is due for their 2 day clinic appointment. '
             'Please remind this person and ensure they '
             'visit Central Clinic within 3 days.',
             'Hello cba2. patient 3 is due for their 2 day clinic appointment. '
             'Please remind this person and ensure they '
             'visit Central Clinic within 3 days.']
        self.assertEqual(len(messages), len(expected_messages))
        for msg in messages:
            self.assertTrue(msg.text in expected_messages, msg)
        sent_notifications = reminders.SentNotification.objects.all()
        self.assertEqual(sent_notifications.count(), len(expected_messages))