Ejemplo n.º 1
0
 def fake_incoming(self, message, connection=None):
     if connection is None:
         connection = self.connection
     router = get_router()
     router.handle_incoming(connection.backend.name, connection.identity, message)
     form = XForm.find_form(message)
     if form:
         return XFormSubmission.objects.all().order_by('-created')[0]
Ejemplo n.º 2
0
    def fake_error_submission(self, message, connection=None):
        form = XForm.find_form(message)

        if connection is None:
            connection = Connection.objects.all()[0]
        # if so, process it
        incomingmessage = IncomingMessage(connection, message)
        incomingmessage.db_message = Message.objects.create(direction='I', connection=Connection.objects.all()[0], text=message)
        if form:
            submission = form.process_sms_submission(incomingmessage)
            self.failUnless(submission.has_errors)
        return
Ejemplo n.º 3
0
 def fake_submission(self, message, connection=None):
     form = XForm.find_form(message)
     if connection is None:
         try:
             connection = Connection.objects.all()[0]
         except IndexError:
             backend, created = Backend.objects.get_or_create(name='test')
             connection, created = Connection.objects.get_or_create(identity='8675309',
                                                                    backend=backend)
     # if so, process it
     incomingmessage = IncomingMessage(connection, message)
     incomingmessage.db_message = Message.objects.create(direction='I', connection=connection, text=message)
     if form:
         submission = form.process_sms_submission(incomingmessage)
         return submission
     return None
Ejemplo n.º 4
0
    def sms(self, number, text, success=True, response=None, backend=None):
        form = XForm.find_form(text)
        self.assertTrue(form)

        if not backend:
            backend, created = Backend.objects.get_or_create(name='tns')
        connection, created = Connection.objects.get_or_create(backend=backend,
                                                               identity=number)

        message = IncomingMessage(connection, text)
        submission = form.process_sms_submission(message)

        if success:
            self.assertFalse(submission.has_errors,
                             "SMS had errors: %s" % submission.response)
        else:
            self.assertTrue(
                submission.has_errors,
                "SMS did not have any errors: %s" % submission.response)

        if response:
            self.assertEquals(response, submission.response)

        return submission