def test_inbound_new_continue(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': '*120*666#',
         }))
     d = http_request(url, '', method='GET')
     msg, = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['transport_type'], "ussd")
     self.assertEqual(msg['transport_metadata'], {
         "session_id": "123"
     })
     self.assertEqual(msg['session_event'],
         TransportUserMessage.SESSION_NEW)
     self.assertEqual(msg['from_addr'], '555')
     self.assertEqual(msg['to_addr'], '*120*666#')
     self.assertEqual(msg['content'], '*120*666#')
     self.tx_helper.make_dispatch_reply(msg, "OK")
     response = yield d
     correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
             '<options>\n\t\t<option command="1" order="1" ' \
             'callback="http://127.0.0.1/foo" display="False" >' \
             '</option>\n\t</options>\n</request>'
     self.assertEqual(response, correct_response)
Beispiel #2
0
    def make_request(self, session_type, session_id, reply=None,
                     continue_session=True, expect_msg=True,
                     defer_response=False, **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.transport_url + url_suffix,
                                    json.dumps(request_data), method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
            self.tx_helper.clear_all_dispatched()
            if reply is not None:
                yield self.tx_helper.make_dispatch_reply(
                    msg, reply, continue_session=continue_session)

        if defer_response:
            response = deferred_req
            # We need to make sure we wait for the response so we don't leave
            # the reactor dirty if the test runner wins the race with the HTTP
            # client.
            self.add_cleanup(lambda: deferred_req)
        else:
            response = yield deferred_req
        returnValue((msg, response))
Beispiel #3
0
    def test_receipt_processing(self):
        """it should be able to process an incoming XML receipt via HTTP"""

        identifier = '001efc31'
        message_id = '123456'
        # prime redis to match the incoming identifier to an
        # internal message id
        self.transport.set_message_id_for_identifier(identifier, message_id)

        xml_data = """
        <?xml version="1.0"?>
        <!DOCTYPE receipts>
        <receipts>
          <receipt>
            <msgid>26567958</msgid>
            <reference>%s</reference>
            <msisdn>+27123456789</msisdn>
            <status>D</status>
            <timestamp>20080831T15:59:24</timestamp>
            <billed>NO</billed>
          </receipt>
        </receipts>
        """.strip() % identifier
        yield http_request('%s/receipt.xml' % self.url, xml_data)
        self.assertEqual([], self.get_dispatched_failures())
        self.assertEqual([], self.get_dispatched_messages())
        [event] = self.get_dispatched_events()
        self.assertEqual(event['delivery_status'], 'delivered')
        self.assertEqual(event['message_type'], 'event')
        self.assertEqual(event['event_type'], 'delivery_report')
        self.assertEqual(event['user_message_id'], message_id)
Beispiel #4
0
 def handle_outbound_message(self, message):
     text = message['content']
     if text is None:
         text = ''
     flags = '0'
     if message['session_event'] == message.SESSION_CLOSE:
         flags = '1'
     session_id = message['transport_metadata']['session_id']
     response = yield http_request(self.integrat_url, hxg.build({
         'Flags': flags,
         'SessionID': session_id,
         'Type': 'USSReply',
         'USSText': text,
         'Password': self.integrat_password,
         'UserID': self.integrat_username,
     }), headers={
         'Content-Type': ['text/xml; charset=utf-8']
     }, agent_class=self.agent_factory)
     error = hxg.parse_response(response)
     if not error:
         yield self.publish_ack(user_message_id=message['message_id'],
                                sent_message_id=message['message_id'])
     else:
         yield self.publish_nack(
             user_message_id=message['message_id'],
             sent_message_id=message['message_id'],
             reason=', '.join([': '.join(ef.items()[0])
                               for ef in error['error_fields']]))
 def test_inbound_resume_close(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['transport_type'], "ussd")
     self.assertEqual(msg['transport_metadata'], {"session_id": "123"})
     self.assertEqual(
         msg['session_event'], TransportUserMessage.SESSION_RESUME)
     self.assertEqual(msg['from_addr'], '555')
     self.assertEqual(msg['to_addr'], '')
     self.assertEqual(msg['content'], '1')
     self.tx_helper.make_dispatch_reply(msg, "OK", continue_session=False)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK' + \
                         '</headertext>\n</request>'
     self.assertEqual(response, correct_response)
Beispiel #6
0
 def test_inbound(self):
     url = '%s%s?%s' % (
         self.transport_url,
         self.config['web_path'],
         urlencode([
             ('to_msisdn', 555),
             ('to_msisdn', 556),
             ('from_msisdn', 123),
             ('message', 'hello'),
         ])
     )
     response = yield http_request(url, '', method='GET')
     [msg1, msg2] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg1['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg1['to_addr'], "555")
     self.assertEqual(msg2['to_addr'], "556")
     self.assertEqual(msg1['from_addr'], "123")
     self.assertEqual(msg1['content'], "hello")
     self.assertEqual(json.loads(response), [
         {
             'id': msg1['message_id'],
             'message': msg1['content'],
             'from_msisdn': msg1['from_addr'],
             'to_msisdn': msg1['to_addr'],
         },
         {
             'id': msg2['message_id'],
             'message': msg2['content'],
             'from_msisdn': msg2['from_addr'],
             'to_msisdn': msg2['to_addr'],
         },
     ])
Beispiel #7
0
 def test_good_optional_parameter(self):
     url = self.mkurl('hello', group='#channel')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['group'], '#channel')
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #8
0
    def test_inbound(self):
        url = '%s%s?%s' % (self.transport_url, self.config['web_path'],
                           urlencode([
                               ('to_msisdn', 555),
                               ('to_msisdn', 556),
                               ('template_name', "Joe"),
                               ('template_name', "Foo"),
                               ('template_surname', "Smith"),
                               ('template_surname', "Bar"),
                               ('from_msisdn', 123),
                               ('template', 'hello {{ name }} {{surname}}'),
                           ]))

        response = yield http_request(url, '', method='GET')
        [msg1, msg2] = self.tx_helper.get_dispatched_inbound()
        self.assertEqual(msg1['transport_name'], self.tx_helper.transport_name)
        self.assertEqual(msg1['to_addr'], "555")
        self.assertEqual(msg1['from_addr'], "123")
        self.assertEqual(msg1['content'], "hello Joe Smith")
        self.assertEqual(msg2['content'], "hello Foo Bar")
        self.assertEqual(json.loads(response), [
            {
                'id': msg1['message_id'],
                'message': msg1['content'],
                'from_msisdn': msg1['from_addr'],
                'to_msisdn': msg1['to_addr'],
            },
            {
                'id': msg2['message_id'],
                'message': msg2['content'],
                'from_msisdn': msg2['from_addr'],
                'to_msisdn': msg2['to_addr'],
            },
        ])
Beispiel #9
0
    def make_request(self, session_type, session_id, reply=None,
                     continue_session=True, expect_msg=True,
                     defer_response=False, **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.worker_url + url_suffix,
                                    json.dumps(request_data), method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.broker.wait_messages("vumi",
                                                    "test_infobip.inbound",
                                                    1)
            self.broker.clear_messages("vumi", "test_infobip.inbound")
            msg = TransportUserMessage(**msg.payload)
            if reply is not None:
                reply_msg = msg.reply(reply, continue_session=continue_session)
                self.broker.publish_message("vumi", "test_infobip.outbound",
                                         reply_msg)

        if defer_response:
            response = deferred_req
        else:
            response = yield deferred_req
        returnValue((msg, response))
Beispiel #10
0
    def test_receipt_processing(self):
        """it should be able to process an incoming XML receipt via HTTP"""

        identifier = '001efc31'
        message_id = '123456'
        # prime redis to match the incoming identifier to an
        # internal message id
        yield self.transport.set_message_id_for_identifier(
            identifier, message_id)

        xml_data = """
        <?xml version="1.0"?>
        <!DOCTYPE receipts>
        <receipts>
          <receipt>
            <msgid>26567958</msgid>
            <reference>%s</reference>
            <msisdn>+27123456789</msisdn>
            <status>D</status>
            <timestamp>20080831T15:59:24</timestamp>
            <billed>NO</billed>
          </receipt>
        </receipts>
        """.strip() % identifier
        yield http_request(
            self.transport.get_transport_url('receipt.xml'), xml_data)
        self.assertEqual([], self.tx_helper.get_dispatched_failures())
        self.assertEqual([], self.tx_helper.get_dispatched_inbound())
        [event] = yield self.tx_helper.wait_for_dispatched_events(1)
        self.assertEqual(event['delivery_status'], 'delivered')
        self.assertEqual(event['message_type'], 'event')
        self.assertEqual(event['event_type'], 'delivery_report')
        self.assertEqual(event['user_message_id'], message_id)
 def test_inbound_resume_close(self):
     args = "/?ussdSessionId=123&msisdn=555&provider=web&request=1"
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.wait_for_dispatched_messages(1)
     payload = msg.payload
     self.assertEqual(payload['transport_name'], self.transport_name)
     self.assertEqual(payload['transport_type'], "ussd")
     self.assertEqual(payload['transport_metadata'],
                      {"session_id": "123"})
     self.assertEqual(payload['session_event'],
                      TransportUserMessage.SESSION_RESUME)
     self.assertEqual(payload['from_addr'], '555')
     self.assertEqual(payload['to_addr'], '')
     self.assertEqual(payload['content'], '1')
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK", False)
     self.dispatch(rep)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK' + \
                         '</headertext>\n</request>'
     self.assertEqual(response, correct_response)
Beispiel #12
0
    def test_http_request_err(self):
        def err(r):
            raise ValueError("Bad")

        self.set_render(err)
        data = yield http_request(self.url, '')
        self.assertEqual(data, "Bad")
Beispiel #13
0
 def test_inbound_resume_continue(self):
     url = "%s%s?%s" % (
         self.transport_url,
         self.config['web_path'],
         urlencode({
             'ussdSessionId': 123,
             'msisdn': 555,
             'provider': 'web',
             'request': 1,
         })
     )
     d = http_request(url, '', method='GET')
     msg, = yield self.wait_for_dispatched_messages(1)
     payload = msg.payload
     self.assertEqual(payload['transport_name'], self.transport_name)
     self.assertEqual(payload['transport_type'], "ussd")
     self.assertEqual(payload['transport_metadata'],
                      {"session_id": "123"})
     self.assertEqual(payload['session_event'],
                      TransportUserMessage.SESSION_RESUME)
     self.assertEqual(payload['from_addr'], '555')
     self.assertEqual(payload['to_addr'], '')
     self.assertEqual(payload['content'], '1')
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK")
     self.dispatch(rep)
     response = yield d
     correct_response = '<request>\n\t<headertext>OK</headertext>\n\t' \
             '<options>\n\t\t<option command="1" order="1" ' \
             'callback="http://localhost/foo" display="False" >' \
             '</option>\n\t</options>\n</request>'
     self.assertEqual(response, correct_response)
Beispiel #14
0
    def search(self, query, limit=10, namespace=0):
        """
        Perform a query and returns a list of dictionaries with results
        matching the query.

        Parameters
        ----------
        query : str
            The search term.
        limit : int, optional
            How many results to get back, defaults to 10
        namespace : int, optional
            The namespace of the OpenSearch Suggestions extention, defaults
            to 0
        """
        query_params = {
            'search': query.encode('utf-8'),
            'action': 'opensearch',
            'limit': str(limit),
            'namespace': str(namespace),
            'format': 'xml',
        }
        url = '%s?%s' % (self.URL, urlencode(query_params))
        response = yield http_request(url, '', {
            'User-Agent': 'Vumi HTTP Request',
        }, method='GET')
        returnValue(self.parse_xml(response))
Beispiel #15
0
 def test_good_optional_parameter(self):
     url = self.mkurl('hello', group='#channel')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['group'], '#channel')
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #16
0
 def test_inbound(self):
     url = '%s%s?%s' % (self.transport_url, self.config['web_path'],
                        urlencode([
                            ('to_msisdn', 555),
                            ('to_msisdn', 556),
                            ('from_msisdn', 123),
                            ('message', 'hello'),
                        ]))
     response = yield http_request(url, '', method='GET')
     [msg1, msg2] = self.get_dispatched_messages()
     payload1 = msg1.payload
     payload2 = msg2.payload
     self.assertEqual(payload1['transport_name'], self.transport_name)
     self.assertEqual(payload1['to_addr'], "555")
     self.assertEqual(payload2['to_addr'], "556")
     self.assertEqual(payload1['from_addr'], "123")
     self.assertEqual(payload1['content'], "hello")
     self.assertEqual(json.loads(response), [
         {
             'id': payload1['message_id'],
             'message': payload1['content'],
             'from_msisdn': payload1['from_addr'],
             'to_msisdn': payload1['to_addr'],
         },
         {
             'id': payload2['message_id'],
             'message': payload2['content'],
             'from_msisdn': payload2['from_addr'],
             'to_msisdn': payload2['to_addr'],
         },
     ])
Beispiel #17
0
 def test_health_resource(self):
     worker, proxy = yield self.get_api_worker()
     result = yield http_request("http://%s:%s/health" %
                                 (proxy.host, proxy.port),
                                 data=None,
                                 method='GET')
     self.assertEqual(result, "OK")
Beispiel #18
0
    def make_request(self,
                     session_type,
                     session_id,
                     reply=None,
                     continue_session=True,
                     expect_msg=True,
                     defer_response=False,
                     **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.worker_url + url_suffix,
                                    json.dumps(request_data),
                                    method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.broker.wait_messages("vumi",
                                                    "test_infobip.inbound", 1)
            self.broker.clear_messages("vumi", "test_infobip.inbound")
            msg = TransportUserMessage(**msg.payload)
            if reply is not None:
                reply_msg = msg.reply(reply, continue_session=continue_session)
                self.broker.publish_message("vumi", "test_infobip.outbound",
                                            reply_msg)

        if defer_response:
            response = deferred_req
        else:
            response = yield deferred_req
        returnValue((msg, response))
Beispiel #19
0
    def make_request(self,
                     session_type,
                     session_id,
                     reply=None,
                     continue_session=True,
                     expect_msg=True,
                     defer_response=False,
                     **kw):
        url_suffix = "session/%s/%s" % (session_id, session_type)
        method = self.SESSION_HTTP_METHOD.get(session_type, "POST")
        request_data = self.DEFAULT_SESSION_DATA[session_type].copy()
        request_data.update(kw)
        deferred_req = http_request(self.transport_url + url_suffix,
                                    json.dumps(request_data),
                                    method=method)
        if not expect_msg:
            msg = None
        else:
            [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
            self.tx_helper.clear_all_dispatched()
            if reply is not None:
                yield self.tx_helper.make_dispatch_reply(
                    msg, reply, continue_session=continue_session)

        if defer_response:
            response = deferred_req
            # We need to make sure we wait for the response so we don't leave
            # the reactor dirty if the test runner wins the race with the HTTP
            # client.
            self.add_cleanup(lambda: deferred_req)
        else:
            response = yield deferred_req
        returnValue((msg, response))
Beispiel #20
0
 def test_ignored_parameters(self):
     url = self.mkurl('hello', channelID='a', keyword='b', CHANNELID='c',
                      serviceID='d', SERVICEID='e', unsub='f')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #21
0
 def test_non_json_content(self):
     response = yield http_request(self.worker_url + "session/1/start",
                                   "not json at all", method="POST")
     correct_response = {
         'responseExitCode': 400,
         'responseMessage': 'Invalid JSON',
         }
     self.assertEqual(json.loads(response), correct_response)
Beispiel #22
0
 def test_ignored_parameters(self):
     url = self.mkurl('hello', channelID='a', keyword='b', CHANNELID='c',
                      serviceID='d', SERVICEID='e', unsub='f')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #23
0
 def test_inbound_with_failed_auth(self):
     headers = {
         'Authorization': basic_auth_string("user-1", "bad-pass")
     }
     d = http_request(self.transport_url + "foo", '',
                      headers=headers, method='GET')
     response = yield d
     self.assertEqual(response, 'Unauthorized')
Beispiel #24
0
 def test_inbound_with_failed_auth(self):
     headers = {'Authorization': basic_auth_string("user-1", "bad-pass")}
     d = http_request(self.transport_url + "foo",
                      '',
                      headers=headers,
                      method='GET')
     response = yield d
     self.assertEqual(response, 'Unauthorized')
Beispiel #25
0
 def _make_call(self, params):
     params.setdefault("format", "json")
     url = "%s?%s" % (self.URL, urlencode(params))
     headers = {"User-Agent": "Vumi HTTP Request"}
     if self.GZIP:
         headers["Accept-Encoding"] = "gzip"
     response = yield http_request(url, "", headers, method="GET")
     returnValue(json.loads(response))
Beispiel #26
0
    def test_incoming_sms_processing(self):
        """
        it should be able to process in incoming sms as XML delivered via HTTP
        """

        xml_data = """
        <?xml version="1.0"?>
        <!DOCTYPE bspostevent>
        <bspostevent>
          <field name="MOReference" type = "string">282341913</field>
          <field name="IsReceipt" type = "string">NO</field>
          <field name="RemoteNetwork" type = "string">mtn-za</field>
          <field name="BSDate-tomorrow" type = "string">20100605</field>
          <field name="BSDate-today" type = "string">20100604</field>
          <field name="ReceiveDate" type = "date">
                 2010-06-04 15:51:25 +0000</field>
          <field name="Local" type = "string">*32323</field>
          <field name="ClientID" type = "string">4</field>
          <field name="ChannelID" type = "string">111</field>
          <field name="MessageID" type = "string">373736741</field>
          <field name="ReceiptStatus" type = "string"></field>
          <field name="Prefix" type = "string"></field>
          <field name="ClientName" type = "string">Praekelt</field>
          <field name="MobileDevice" type = "string"></field>
          <field name="BSDate-yesterday" type = "string">20100603</field>
          <field name="Remote" type = "string">+27831234567</field>
          <field name="State" type = "string">5</field>
          <field name="MobileNetwork" type = "string">mtn-za</field>
          <field name="MobileNumber" type = "string">+27831234567</field>
          <field name="Text" type = "string">Hello World</field>
          <field name="ServiceID" type = "string">20222</field>
          <field name="RegType" type = "string">1</field>
          <field name="NewSubscriber" type = "string">NO</field>
          <field name="Subscriber" type = "string">+27831234567</field>
          <field name="Parsed" type = "string"></field>
          <field name="ServiceName" type = "string">Prktl Vumi</field>
          <field name="BSDate-thisweek" type = "string">20100531</field>
          <field name="ServiceEndDate" type = "string">
                 2010-06-30 07:47:00 +0200</field>
          <field name="Now" type = "date">2010-06-04 15:51:27 +0000</field>
        </bspostevent>
        """.strip()

        resp = yield http_request(
            self.transport.get_transport_url('receive.xml'), xml_data)

        self.assertEqual([], self.tx_helper.get_dispatched_failures())
        self.assertEqual([], self.tx_helper.get_dispatched_events())
        [msg] = self.tx_helper.get_dispatched_inbound()
        self.assertEqual(msg['message_id'], '373736741')
        self.assertEqual(msg['to_addr'], '32323')
        self.assertEqual(msg['from_addr'], '+27831234567')
        self.assertEqual(msg['content'], 'Hello World')
        self.assertEqual(msg['transport_metadata'], {
            'provider': 'mtn-za'
        })

        self.assertEqual(resp, xml_data)
Beispiel #27
0
 def test_status_for_inactive_session(self):
     response = yield http_request(self.worker_url + "session/1/status", "",
                                   method="GET")
     correct_response = {
         'responseExitCode': 200,
         'responseMessage': '',
         'sessionActive': False,
         }
     self.assertEqual(json.loads(response), correct_response)
Beispiel #28
0
 def test_http_request_to_localhost(self):
     """
     Make a request over the network (localhost) to check that we're getting
     a real agent by default.
     """
     url = yield self.make_real_webserver()
     self.set_render(lambda r: "Yay")
     data = yield http_request(url, '')
     self.assertEqual(data, "Yay")
Beispiel #29
0
 def test_non_json_content(self):
     response = yield http_request(self.transport_url + "session/1/start",
                                   "not json at all",
                                   method="POST")
     correct_response = {
         'responseExitCode': 400,
         'responseMessage': 'Invalid JSON',
     }
     self.assertEqual(json.loads(response), correct_response)
Beispiel #30
0
 def test_inbound(self):
     d = http_request(self.transport_url + "foo", '', method='GET')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     rep = yield self.tx_helper.make_dispatch_reply(msg, "OK")
     response = yield d
     self.assertEqual(response, 'OK')
     [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
     self.assertEqual(ack['user_message_id'], rep['message_id'])
     self.assertEqual(ack['sent_message_id'], rep['message_id'])
Beispiel #31
0
 def test_http_request_to_localhost(self):
     """
     Make a request over the network (localhost) to check that we're getting
     a real agent by default.
     """
     url = yield self.make_real_webserver()
     self.set_render(lambda r: "Yay")
     data = yield http_request(url, '')
     self.assertEqual(data, "Yay")
Beispiel #32
0
 def test_inbound(self):
     d = http_request(self.transport_url + "foo", '', method='GET')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     rep = yield self.tx_helper.make_dispatch_reply(msg, "OK")
     response = yield d
     self.assertEqual(response, 'OK')
     [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
     self.assertEqual(ack['user_message_id'], rep['message_id'])
     self.assertEqual(ack['sent_message_id'], rep['message_id'])
Beispiel #33
0
    def test_incoming_sms_processing(self):
        """
        it should be able to process in incoming sms as XML delivered via HTTP
        """

        xml_data = """
        <?xml version="1.0"?>
        <!DOCTYPE bspostevent>
        <bspostevent>
          <field name="MOReference" type = "string">282341913</field>
          <field name="IsReceipt" type = "string">NO</field>
          <field name="RemoteNetwork" type = "string">mtn-za</field>
          <field name="BSDate-tomorrow" type = "string">20100605</field>
          <field name="BSDate-today" type = "string">20100604</field>
          <field name="ReceiveDate" type = "date">
                 2010-06-04 15:51:25 +0000</field>
          <field name="Local" type = "string">*32323</field>
          <field name="ClientID" type = "string">4</field>
          <field name="ChannelID" type = "string">111</field>
          <field name="MessageID" type = "string">373736741</field>
          <field name="ReceiptStatus" type = "string"></field>
          <field name="Prefix" type = "string"></field>
          <field name="ClientName" type = "string">Praekelt</field>
          <field name="MobileDevice" type = "string"></field>
          <field name="BSDate-yesterday" type = "string">20100603</field>
          <field name="Remote" type = "string">+27831234567</field>
          <field name="State" type = "string">5</field>
          <field name="MobileNetwork" type = "string">mtn-za</field>
          <field name="MobileNumber" type = "string">+27831234567</field>
          <field name="Text" type = "string">Hello World</field>
          <field name="ServiceID" type = "string">20222</field>
          <field name="RegType" type = "string">1</field>
          <field name="NewSubscriber" type = "string">NO</field>
          <field name="Subscriber" type = "string">+27831234567</field>
          <field name="Parsed" type = "string"></field>
          <field name="ServiceName" type = "string">Prktl Vumi</field>
          <field name="BSDate-thisweek" type = "string">20100531</field>
          <field name="ServiceEndDate" type = "string">
                 2010-06-30 07:47:00 +0200</field>
          <field name="Now" type = "date">2010-06-04 15:51:27 +0000</field>
        </bspostevent>
        """.strip()

        resp = yield http_request(
            self.transport.get_transport_url('receive.xml'), xml_data)

        self.assertEqual([], self.tx_helper.get_dispatched_failures())
        self.assertEqual([], self.tx_helper.get_dispatched_events())
        [msg] = self.tx_helper.get_dispatched_inbound()
        self.assertEqual(msg['message_id'], '373736741')
        self.assertEqual(msg['to_addr'], '32323')
        self.assertEqual(msg['from_addr'], '+27831234567')
        self.assertEqual(msg['content'], 'Hello World')
        self.assertEqual(msg['transport_metadata'], {'provider': 'mtn-za'})

        self.assertEqual(resp, xml_data)
Beispiel #34
0
 def test_disallowed_default_parameters(self):
     url = self.mkurl_raw(content='hello', from_addr='123')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "555")
     self.assertEqual(msg['from_addr'], "123")
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #35
0
 def test_disallowed_default_parameters(self):
     url = self.mkurl_raw(content='hello', from_addr='123')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "555")
     self.assertEqual(msg['from_addr'], "123")
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #36
0
 def test_inbound(self):
     url = self.mkurl('hello')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "12345")
     self.assertEqual(msg['from_addr'], "2371234567")
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #37
0
 def test_status_for_inactive_session(self):
     response = yield http_request(self.transport_url + "session/1/status",
                                   "",
                                   method="GET")
     correct_response = {
         'responseExitCode': 200,
         'responseMessage': '',
         'sessionActive': False,
     }
     self.assertEqual(json.loads(response), correct_response)
Beispiel #38
0
 def test_handle_non_ascii_input(self):
     url = self.mkurl(u"öæł".encode("utf-8"))
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "12345")
     self.assertEqual(msg['from_addr'], "2371234567")
     self.assertEqual(msg['content'], u"öæł")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #39
0
 def test_inbound(self):
     url = self.mkurl('hello')
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "12345")
     self.assertEqual(msg['from_addr'], "2371234567")
     self.assertEqual(msg['content'], "hello")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #40
0
 def test_handle_non_ascii_input(self):
     url = self.mkurl(u"öæł".encode("utf-8"))
     response = yield http_request(url, '', method='GET')
     [msg] = self.tx_helper.get_dispatched_inbound()
     self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
     self.assertEqual(msg['to_addr'], "12345")
     self.assertEqual(msg['from_addr'], "2371234567")
     self.assertEqual(msg['content'], u"öæł")
     self.assertEqual(json.loads(response),
                      {'message_id': msg['message_id']})
Beispiel #41
0
def call_request(msisdn, headers):
    default_headers = {
        'Content-Type': ['application/x-www-form-urlencoded'],
    }
    default_headers.update(headers)

    response = yield http_request(REQUEST_CALL_URL, urlencode({
        'msisdn': msisdn,
    }), headers=default_headers, method='POST')
    print 'response', response
    returnValue(response)
Beispiel #42
0
 def test_inbound(self):
     d = http_request(self.worker_url + "foo", '', method='GET')
     msg, = yield self.broker.wait_messages("vumi",
         "test_ok_transport.inbound", 1)
     payload = msg.payload
     tum = TransportUserMessage(**payload)
     rep = tum.reply("OK")
     self.broker.publish_message("vumi", "test_ok_transport.outbound",
             rep)
     response = yield d
     self.assertEqual(response, 'OK')
Beispiel #43
0
 def mk_request(self, **params):
     defaults = {
         'MSISDN': '27761234567',
         'INPUT': '',
         'opCode': 'BEG',
         'ABORT': '0',
         'sessionID': '1',
     }
     defaults.update(params)
     return http_request('%s?%s' % (self.transport_url,
         urlencode(defaults)), data='', method='GET')
Beispiel #44
0
 def test_status_for_active_session(self):
     msg, response = yield self.make_request("start", 1, text="Hi",
                                             reply="Boop")
     response = yield http_request(self.worker_url + "session/1/status", "",
                                   method="GET")
     correct_response = {
         'responseExitCode': 200,
         'responseMessage': '',
         'sessionActive': True,
         }
     self.assertEqual(json.loads(response), correct_response)
Beispiel #45
0
    def test_inbound(self):
        url = self.mkurl('hello')
        deferred = http_request(url, '', method='GET')
        [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
        self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
        self.assertEqual(msg['to_addr'], "12345")
        self.assertEqual(msg['from_addr'], "2371234567")
        self.assertEqual(msg['content'], "hello")

        yield self.tx_helper.make_dispatch_reply(msg, 'message received')
        response = yield deferred
        self.assertEqual(response, 'message received')
Beispiel #46
0
    def random_word(self):
        log.msg('Fetching random word from %s' % (self.random_word_url,))
        d = http_request(self.random_word_url, None, method='GET')

        def _decode(word):
            # result from http_request should always be bytes
            # convert to unicode, strip BOMs and whitespace
            word = word.decode("utf-8", "ignore")
            word = word.lstrip(u'\ufeff\ufffe')
            word = word.strip()
            return word
        return d.addCallback(_decode)
Beispiel #47
0
 def test_inbound_non_ascii(self):
     xml = (XML_TEMPLATE % {
         'ussd_type': 'Request',
         'sid': 'sess1234',
         'network_sid': "netsid12345",
         'msisdn': '27345',
         'connstr': '*120*99#',
         'text': u'öæł',
         }).encode("utf-8")
     yield http_request(self.transport_url + "foo", xml, method='GET')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['content'], u'öæł')
Beispiel #48
0
def request_change(visit_id, change_type, headers):
    default_headers = {
        'Content-Type': ['application/x-www-form-urlencoded'],
    }
    default_headers.update(headers)

    response = yield http_request(REQUEST_CHANGE_URL, urlencode({
        'visit_id': visit_id,
        'when': change_type,
    }), headers=default_headers, method='POST')
    print 'response', response
    returnValue(response)
Beispiel #49
0
 def test_inbound_non_ascii(self):
     xml = (XML_TEMPLATE % {
         'ussd_type': 'Request',
         'sid': 'sess1234',
         'network_sid': "netsid12345",
         'msisdn': '27345',
         'connstr': '*120*99#',
         'text': u'öæł',
     }).encode("utf-8")
     yield http_request(self.transport_url + "foo", xml, method='GET')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['content'], u'öæł')
Beispiel #50
0
 def handle_outbound_message(self, message):
     data = message.payload
     yield http_request(self.config['url'], hxg.build({
         'Flags': data.get('close', '0'),
         'SessionID': data['transport_session_id'],
         'Type': 'USSReply',
         'USSText': data['message'],
         'Password': self.config.get('password'),
         'UserID': self.config.get('username')
     }), headers={
         'Content-Type': ['text/xml; charset=utf-8']
     })
Beispiel #51
0
 def test_start_without_msisdn(self):
     json_dict = {
         'text': 'Oops. No msisdn.',
         }
     response = yield http_request(self.worker_url + "session/1/start",
                                   json.dumps(json_dict), method='POST')
     correct_response = {
         'responseExitCode': 400,
         'responseMessage': "Missing required JSON field:"
                            " KeyError('msisdn',)",
         }
     self.assertEqual(json.loads(response), correct_response)
Beispiel #52
0
 def test_inbound_non_ascii(self):
     xml = (XML_TEMPLATE % {
         'ussd_type': 'Request',
         'sid': 'sess1234',
         'network_sid': "netsid12345",
         'msisdn': '27345',
         'connstr': '*120*99#',
         'text': u'öæł',
         }).encode("utf-8")
     yield http_request(self.worker_url + "foo", xml, method='GET')
     msg, = yield self.broker.wait_messages("vumi", "testgrat.inbound", 1)
     payload = msg.payload
     self.assertEqual(payload['content'], u'öæł')
Beispiel #53
0
 def test_inbound(self):
     d = http_request(self.transport_url + "foo", '{"content": "hello",'
                      ' "to_addr": "the_app",'
                      ' "from_addr": "some_msisdn"'
                      '}',
                      method='POST')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     self.assertEqual(msg['content'], 'hello')
     self.assertEqual(msg['to_addr'], 'the_app')
     self.assertEqual(msg['from_addr'], 'some_msisdn')
     yield self.tx_helper.make_dispatch_reply(msg, '{"content": "bye"}')
     response = yield d
     self.assertEqual(response, '{"content": "bye"}')
Beispiel #54
0
 def mk_request(self, **params):
     defaults = {
         'MSISDN': '27761234567',
         'INPUT': '',
         'opCode': 'BEG',
         'ABORT': '0',
         'sessionID': '1',
     }
     defaults.update(params)
     return http_request('%s?%s' %
                         (self.transport_url, urlencode(defaults)),
                         data='',
                         method='GET')
Beispiel #55
0
 def test_inbound_with_successful_auth(self):
     headers = {'Authorization': basic_auth_string("user-1", "pass-secret")}
     d = http_request(self.transport_url + "foo",
                      '',
                      headers=headers,
                      method='GET')
     [msg] = yield self.tx_helper.wait_for_dispatched_inbound(1)
     rep = yield self.tx_helper.make_dispatch_reply(msg, "OK")
     response = yield d
     self.assertEqual(response, 'OK')
     [ack] = yield self.tx_helper.wait_for_dispatched_events(1)
     self.assertEqual(ack['user_message_id'], rep['message_id'])
     self.assertEqual(ack['sent_message_id'], rep['message_id'])