예제 #1
0
    def testMsg(self):
        """
        msg dho blah blah : goes to fellow dho's at district
        msg all blah blah : goes to both dho's and clinic workers in district
        """

        dho = self.create_contact(name="dho",
                                  location=self.district,
                                  types=[get_district_worker_type()])
        dho2 = self.create_contact(name="dho2",
                                   location=self.district,
                                   types=[get_district_worker_type()])

        # control contacts
        dho3 = self.create_contact(name="dho3",
                                   location=self.district2,
                                   types=[get_district_worker_type()])
        clinic_worker3 = self.create_contact(name="clinic_worker3",
                                             location=self.clinic2,
                                             types=[get_clinic_worker_type()])

        script = """
        dho > msg my own way
        dho < To send a message to DHOs in your district, SEND: MSG DHO (your message). To send to both DHOs and clinic worker SEND: MSG ALL (your message)
        dho > msg
        dho < To send a message to DHOs in your district, SEND: MSG DHO (your message). To send to both DHOs and clinic worker SEND: MSG ALL (your message)
        """
        self.runScript(script)

        script = """
        dho > msg all testing dho blasting
        """
        self.runScript(script)

        msgs = self.receiveAllMessages()

        self.assertEqual(3, len(msgs))
        expected_recipients = ["dho2", "clinic_worker", "clinic_worker2"]
        actual_recipients = []

        for msg in msgs:
            self.assertEqual(msg.text,
                             "testing dho blasting [from dho to MSG]")
            actual_recipients.append(msg.contact.name)
        difference = list(
            set(actual_recipients).difference(set(expected_recipients)))
        self.assertEqual([], difference)

        script = """
        dho > msg dho testing dho blasting
        """

        self.runScript(script)
        msgs = self.receiveAllMessages()

        # no extra msgs sent
        self.assertEqual(1, len(msgs))
        self.assertEqual('dho2', msgs[0].contact.name)
        self.assertEqual(msgs[0].text,
                         'testing dho blasting [from dho to MSG]')
예제 #2
0
파일: tests.py 프로젝트: AndreLesa/mwana
    def testMsg(self):
        """
        msg dho blah blah : goes to fellow dho's at district
        msg all blah blah : goes to both dho's and clinic workers in district
        """

        dho = self.create_contact(name="dho", location=self.district,
                                            types=[get_district_worker_type()])
        dho2 = self.create_contact(name="dho2", location=self.district,
                                            types=[get_district_worker_type()])

        # control contacts
        dho3 = self.create_contact(name="dho3", location=self.district2,
                                            types=[get_district_worker_type()])
        clinic_worker3 = self.create_contact(name="clinic_worker3", location=self.clinic2,
                                             types=[get_clinic_worker_type()])

        script="""
        dho > msg my own way
        dho < To send a message to DHOs in your district, SEND: MSG DHO (your message). To send to both DHOs and clinic worker SEND: MSG ALL (your message)
        dho > msg
        dho < To send a message to DHOs in your district, SEND: MSG DHO (your message). To send to both DHOs and clinic worker SEND: MSG ALL (your message)
        """      
        self.runScript(script)

        script="""
        dho > msg all testing dho blasting
        """
        self.runScript(script)

        msgs=self.receiveAllMessages()
        
        self.assertEqual(3,len(msgs))
        expected_recipients = ["dho2","clinic_worker","clinic_worker2"]
        actual_recipients = []

        for msg in msgs:
            self.assertEqual(msg.text,"testing dho blasting [from dho to MSG]")
            actual_recipients.append(msg.contact.name)
        difference = list(set(actual_recipients).difference(set(expected_recipients)))
        self.assertEqual([], difference)

        script="""
        dho > msg dho testing dho blasting
        """

        self.runScript(script)
        msgs=self.receiveAllMessages()

        # no extra msgs sent
        self.assertEqual(1, len(msgs))
        self.assertEqual('dho2', msgs[0].contact.name)
        self.assertEqual(msgs[0].text, 'testing dho blasting [from dho to MSG]')
예제 #3
0
    def handle(self, text):
        '''
        Sends to all other contacts in the same district
        '''
        if self.msg.contact is None or \
           self.msg.contact.location is None:
            self.respond(UNREGISTERED)
            return

        location = get_clinic_or_default(self.msg.contact)

        contacts = Contact.active.location(location)\
                        .exclude(id=self.msg.contact.id)\
                        .filter(types=get_district_worker_type())
        return self.broadcast(text, contacts)
예제 #4
0
파일: locations.py 프로젝트: makandok/mwana
    def get_worker_type(self):
        '''
        Returns the worker_type based on the location_code
        Expects code of format PPDDFF exactly.
        '''
        PP = self.slug[0:2]
        DD = self.slug[2:4]
        FF = self.slug[4:6]

        if FF == '00':
            if DD == '00':
                return const.get_province_worker_type()
            else:
                return const.get_district_worker_type()
        else:
            return const.get_clinic_worker_type()
예제 #5
0
파일: msg.py 프로젝트: AndreLesa/mwana
 def handle(self, text):
     '''
     Sends to all other contacts in the same district
     '''
     if self.msg.contact is None or \
        self.msg.contact.location is None:
         self.respond(UNREGISTERED)
         return
     location = get_clinic_or_default(self.msg.contact)        
     
     
     tokens = text.strip().lower().split(' ')
     if tokens[0] == 'example':
         self.respond(self.EXAMPLE_MESSAGE_ONE)
         self.respond(self.EXAMPLE_MESSAGE_TWO)
         return True
     
     group = self.PATTERN.search(text.strip())
     if not group:
         self.respond(self.MALFORMED_MESSAGE)
         return True
     
     tokens = group.groups()
     
     msg_part=text[len(tokens[0]):].strip()
     if tokens[0].lower() == 'dho':
         contacts = Contact.active.location(location)\
                         .exclude(id=self.msg.contact.id)\
                         .filter(types=get_district_worker_type())
         return self.broadcast(msg_part, contacts)
     elif tokens[0].lower() == 'all':
         contacts = \
         Contact.active.filter(location__slug__startswith=location.slug[:4]).\
         exclude(id=self.msg.contact.id)
         return self.broadcast(msg_part, contacts)
     else:
         self.help()
         
         
         
         
예제 #6
0
    def handle(self, text):
        '''
        Sends to all other contacts in the same district
        '''
        if self.msg.contact is None or \
           self.msg.contact.location is None:
            self.respond(UNREGISTERED)
            return
        location = get_clinic_or_default(self.msg.contact)

        tokens = text.strip().lower().split(' ')
        if tokens[0] == 'example':
            self.respond(self.EXAMPLE_MESSAGE_ONE)
            self.respond(self.EXAMPLE_MESSAGE_TWO)
            return True

        group = self.PATTERN.search(text.strip())
        if not group:
            self.respond(self.MALFORMED_MESSAGE)
            return True

        tokens = group.groups()

        msg_part = text[len(tokens[0]):].strip()
        if tokens[0].lower() == 'dho':
            contacts = Contact.active.location(location)\
                            .exclude(id=self.msg.contact.id)\
                            .filter(types=get_district_worker_type())
            return self.broadcast(msg_part, contacts)
        elif tokens[0].lower() == 'all':
            contacts = \
            Contact.active.filter(location__slug__startswith=location.slug[:4]).\
            exclude(id=self.msg.contact.id)
            return self.broadcast(msg_part, contacts)
        else:
            self.help()
예제 #7
0
    def handle(self, text):
        """
        Sends to all other contacts in the same district
        """
        if self.msg.contact is None or self.msg.contact.location is None:
            self.respond(UNREGISTERED)
            return

        location = get_clinic_or_default(self.msg.contact)

        contacts = (
            Contact.active.location(location).exclude(id=self.msg.contact.id).filter(types=get_district_worker_type())
        )
        return self.broadcast(text, contacts)