Example #1
0
    def setUp(self):
        self.router = MockRouter()

        self.backend = self.router.add_backend(u'MockBackend',
                                               'rapidsms.tests.harness')
        self.assertIsNotNone(self.backend)
        self.assertEquals(self.router.backends[u'MockBackend'], self.backend)

        backend_in_db = Backend.objects.create(name=u'MockBackend')
        backend_in_db.save()

        self.contact = Contact.objects.create(first_name='John',
                                              last_name='Doe')
        self.connection = Connection.objects.create(contact=self.contact,
                                                    backend=backend_in_db,
                                                    identity='1112223333')
        self.patient = self.create_patient(data={'contact': self.contact})

        self.app = DecisionApp(router=self.router)
        self.router.add_app(self.app)
        self.tree = get_tree()
        self.backend.start()
        self.app.start()
        self.survey = PatientSurvey.objects.create(patient=self.patient,
                                                   query_type=QUERY_TYPE_SMS)
        super(TreeTest, self).setUp()
Example #2
0
    def setUp(self):
        self.router = MockRouter()

        self.backend = self.router.add_backend(u'MockBackend', 'rapidsms.tests.harness')
        self.assertIsNotNone(self.backend)
        self.assertEquals(self.router.backends[u'MockBackend'], self.backend)

        backend_in_db = Backend.objects.create(name=u'MockBackend')
        backend_in_db.save()

        self.contact = Contact.objects.create(first_name='John',
                                              last_name='Doe')
        self.connection = Connection.objects.create(contact=self.contact,
                                                    backend=backend_in_db,
                                                    identity='1112223333')
        self.patient = self.create_patient(data={'contact': self.contact })

        self.app = DecisionApp(router=self.router)
        self.router.add_app(self.app)
        self.tree =  get_tree()
        self.backend.start()
        self.app.start()
        self.survey = PatientSurvey.objects.create(patient=self.patient,
                                                   query_type=QUERY_TYPE_SMS)
        super(TreeTest,self).setUp()
Example #3
0
def test_handle_bad_request():
    """ handle_request must return a HttpResponse """
    router = MockRouter()
    backend = RapidHttpBackend(name='test', 
                              router=router)
    response = backend.handle_request(HttpRequest())
    assert_true(isinstance(response, HttpResponseBadRequest))
Example #4
0
 def setUp(self):
     self.source_contact = self.create_contact(data={
         'first_name': 'John',
         'last_name': 'Smith'
     })
     self.dest_contact = self.create_contact(data={
         'first_name': 'John',
         'last_name': 'Smith'
     })
     self.backend = self.create_backend(data={'name': 'mockbackend'})
     self.unreg_conn = self.create_connection({'backend': self.backend})
     self.source_conn = self.create_connection({
         'contact': self.source_contact,
         'backend': self.backend,
         'identity': '5678'
     })
     self.dest_conn = self.create_connection({
         'contact': self.dest_contact,
         'backend': self.backend,
         'identity': '1234'
     })
     self.router = MockRouter()
     self.app = BroadcastApp(router=self.router)
     self.rule = self.create_forwarding_rule(data={'keyword': 'abc'})
     self.rule.source.contacts.add(self.source_contact)
Example #5
0
def test_bad_config():
    """ Test bad configuration """
    router = MockRouter()
    assert_raises(Exception, RapidHttpBackend, router=router, 
                                  username='******', 
                                  gateway_url = 'http://smsgateway.com',
                                  params_outgoing = "user=my_username&password=my_password&id=%(params_incoming)s&text=%(message)s",
                                  params_incoming = "id=%(foo)s&text=%(blargh)s")
Example #6
0
def test_handle_good_request():
    """ handle_request must return a HttpResponse """
    router = MockRouter()
    backend = RapidHttpBackend(name='test', 
                              router=router)
    http_request = HttpRequest()
    http_request.GET = {'id':'123','text':'message'}
    response = backend.handle_request(http_request)
    assert_true(isinstance(response, HttpResponse))
Example #7
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)
Example #8
0
def test_config():
    """ Allow custom configuration """
    router = MockRouter()
    backend = RapidHttpBackend(router=router, name="test_http_backend")
    backend.configure("localhost", 8080,
                      gateway_url='http://smsgateway.com',
                      params_outgoing = 'user=my_username&password=my_password&id=%(params_incoming)s&text=%(message)s',
                      params_incoming = "id=%(phone_number)s&text=%(message)s")
    assert_equals('http://smsgateway.com', backend.gateway_url)
    assert_equals('user=my_username&password=my_password&id=%(params_incoming)s&text=%(message)s', backend.http_params_outgoing)
    assert_equals('id', backend.incoming_phone_number_param)
    assert_equals('text', backend.incoming_message_param)
 def setUp(self):
     super(DecisionTreeTestCase, self).setUp()
     self.tenant = mommy.make('multitenancy.Tenant')
     self.backend = mommy.make('rapidsms.Backend')
     self.backend_link = mommy.make('multitenancy.BackendLink',
                                    backend=self.backend, tenant=self.tenant)
     self.contact = mommy.make('rapidsms.Contact')
     self.contact_link = mommy.make('multitenancy.ContactLink',
                                    contact=self.contact, tenant=self.tenant)
     self.connection = mommy.make('rapidsms.Connection',
                                  contact=self.contact, backend=self.backend,
                                  identity='1112223333')
     self.router = MockRouter()
     self.app = DecisionApp(router=self.router)
Example #10
0
class TreeTest(PatientsCreateDataTest):
    """Test that our decisiontree works the way we want"""
    
    def setUp(self):
        self.router = MockRouter()

        self.backend = self.router.add_backend(u'MockBackend', 'rapidsms.tests.harness')
        self.assertIsNotNone(self.backend)
        self.assertEquals(self.router.backends[u'MockBackend'], self.backend)

        backend_in_db = Backend.objects.create(name=u'MockBackend')
        backend_in_db.save()

        self.contact = Contact.objects.create(first_name='John',
                                              last_name='Doe')
        self.connection = Connection.objects.create(contact=self.contact,
                                                    backend=backend_in_db,
                                                    identity='1112223333')
        self.patient = self.create_patient(data={'contact': self.contact })

        self.app = DecisionApp(router=self.router)
        self.router.add_app(self.app)
        self.tree =  get_tree()
        self.backend.start()
        self.app.start()
        self.survey = PatientSurvey.objects.create(patient=self.patient,
                                                   query_type=QUERY_TYPE_SMS)
        super(TreeTest,self).setUp()

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

    def test_start(self):
        msg = self._send(self.tree.trigger)
        # this is kind of pointless but gets the ball rolling
        self.assertEqual(msg.responses[0].text, 
                         "How many pills did you miss in the last four days?")

    def test_invalid_response(self):
        self._send(self.tree.trigger)
        msg = self._send("Foo!  Bar!  Baz!")
        rsp = msg.responses[0].text
        self.assertTrue(rsp.startswith("Sorry, please respond with a number. "))

    def test_valid_response(self):
        self._send(self.tree.trigger)
        self.survey.status = PatientSurvey.STATUS_STARTED
        self.survey.save()
        msg = self._send("6")
        print "len(responses)=%d" % len(msg.responses)
        rsp = msg.responses[0].text
        self.assertTrue(rsp.startswith("Thank you. Your adherence is"))

    def test_noisy_response(self):
        """Test response that has spaces and punctuation in it"""
        self._send(self.tree.trigger)
        self.survey.status = PatientSurvey.STATUS_STARTED
        self.survey.save()
        msg = self._send(" 6.")
        print "len(responses)=%d" % len(msg.responses)
        rsp = msg.responses[0].text
        self.assertTrue(rsp.startswith("Thank you. Your adherence is"))
Example #11
0
def test_extra_config():
    """ Allow custom configuration """
    router = MockRouter()
    backend = NewBackend(name='test', router=router, username='******')
    assert_equals('rapidsms', backend.username)
Example #12
0
 def setUp(self):
     self.backend = self.create_backend(data={'name': 'test-backend'})
     self.router = MockRouter()
     self.app = GroupsApp(router=self.router)
 def __init__(self):
     router = MockRouter()
Example #14
0
 def setUp(self):
     self.router = MockRouter()
     self.backend = Backend.objects.create(name='Clickatell')
     self.contact = Contact.objects.create(name='Test Contact')
     self.connection = Connection.objects.create(contact=self.contact, backend=self.backend)
Example #15
0
class TreeTest(PatientsCreateDataTest):
    """Test that our decisiontree works the way we want"""
    def setUp(self):
        self.router = MockRouter()

        self.backend = self.router.add_backend(u'MockBackend',
                                               'rapidsms.tests.harness')
        self.assertIsNotNone(self.backend)
        self.assertEquals(self.router.backends[u'MockBackend'], self.backend)

        backend_in_db = Backend.objects.create(name=u'MockBackend')
        backend_in_db.save()

        self.contact = Contact.objects.create(first_name='John',
                                              last_name='Doe')
        self.connection = Connection.objects.create(contact=self.contact,
                                                    backend=backend_in_db,
                                                    identity='1112223333')
        self.patient = self.create_patient(data={'contact': self.contact})

        self.app = DecisionApp(router=self.router)
        self.router.add_app(self.app)
        self.tree = get_tree()
        self.backend.start()
        self.app.start()
        self.survey = PatientSurvey.objects.create(patient=self.patient,
                                                   query_type=QUERY_TYPE_SMS)
        super(TreeTest, self).setUp()

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

    def test_start(self):
        msg = self._send(self.tree.trigger)
        # this is kind of pointless but gets the ball rolling
        self.assertEqual(msg.responses[0].text,
                         "How many pills did you miss in the last four days?")

    def test_invalid_response(self):
        self._send(self.tree.trigger)
        msg = self._send("Foo!  Bar!  Baz!")
        rsp = msg.responses[0].text
        self.assertTrue(
            rsp.startswith("Sorry, please respond with a number. "))

    def test_valid_response(self):
        self._send(self.tree.trigger)
        self.survey.status = PatientSurvey.STATUS_STARTED
        self.survey.save()
        msg = self._send("6")
        print "len(responses)=%d" % len(msg.responses)
        rsp = msg.responses[0].text
        self.assertTrue(rsp.startswith("Thank you. Your adherence is"))

    def test_noisy_response(self):
        """Test response that has spaces and punctuation in it"""
        self._send(self.tree.trigger)
        self.survey.status = PatientSurvey.STATUS_STARTED
        self.survey.save()
        msg = self._send(" 6.")
        print "len(responses)=%d" % len(msg.responses)
        rsp = msg.responses[0].text
        self.assertTrue(rsp.startswith("Thank you. Your adherence is"))