def test04_receiving_one_sms(self): url = "http://localhost:%s%s?sender=41791234567&code=9292&message=Hello+World" % (self.config['receive_port'], self.config['receive_path']) response = yield http_request_full(url, method='GET') [smsg] = self.get_dispatched('yo.inbound') self.assertEqual(response.code, http.OK) self.assertEqual('Hello World', TransportMessage.from_json(smsg.body)['content']) self.assertEqual('+41791234567', TransportMessage.from_json(smsg.body)['from_addr']) self.assertEqual('9292', TransportMessage.from_json(smsg.body)['to_addr'])
def test_send_sms_success(self): mocked_message_id = TransportMessage.generate_id() mocked_message = "Result_code: 00, Message OK" # open an HTTP resource that mocks the Vas2Nets response for the # duration of this test yield self.make_resource_worker(mocked_message_id, mocked_message) yield self.dispatch(self.mkmsg_out()) [smsg] = self.get_dispatched('vas2nets.event') self.assertEqual(self.mkmsg_ack(sent_message_id=mocked_message_id), TransportMessage.from_json(smsg.body))
def test_send_sms_reply_success(self): mocked_message_id = TransportMessage.generate_id() reply_to_msgid = TransportMessage.generate_id() mocked_message = "Result_code: 00, Message OK" # open an HTTP resource that mocks the Vas2Nets response for the # duration of this test yield self.start_mock_server(mocked_message_id, mocked_message, send_id=reply_to_msgid) sent_msg = yield self.make_dispatch_outbound( "hello", in_reply_to=reply_to_msgid) msg = self.tx_helper.make_ack( sent_msg, sent_message_id=mocked_message_id) [ack] = self.tx_helper.get_dispatched_events() self.assert_events_equal(msg, ack)
def test_send_sms_noconn(self): msg = self.mkmsg_out() d = self.dispatch(msg) yield d [fmsg] = self.get_dispatched('vas2nets.failures') fmsg = TransportMessage.from_json(fmsg.body) self.assertEqual(msg.payload, fmsg['message']) self.assertEqual(fmsg['failure_code'], FailureMessage.FC_TEMPORARY) self.assertTrue(fmsg['reason'].strip().endswith("connection refused"))
def test01_sending_one_sms_ok(self): #mocked_message_id = str(uuid4()) mocked_message = "" #HTTP response yield self.make_resource_worker(mocked_message) #Message to transport yield self.dispatch(self.mkmsg_out(to_addr='+41791234567')) [smsg] = self.get_dispatched('cm.event') self.assertEqual(self.mkmsg_delivery(user_message_id='1'), TransportMessage.from_json(smsg.body))
def test01_sending_one_sms_ok(self): #mocked_message_id = str(uuid4()) mocked_message = "ybs_autocreate_status%3DOK" #HTTP response yield self.make_resource_worker(mocked_message) #Message to transport yield self.dispatch(self.mkmsg_out()) [smsg] = self.get_dispatched('yo.event') self.assertEqual(self.mkmsg_delivery(user_message_id='1'), TransportMessage.from_json(smsg.body))
def test03_sending_one_sms_service_failure(self): mocked_message = "Error: ERROR Unknown error" #HTTP response yield self.make_resource_worker(mocked_message) yield self.dispatch(self.mkmsg_out(to_addr='788601462')) [smsg] = self.get_dispatched('cm.event') self.assertEqual( self.mkmsg_fail(failure_level='service', failure_reason="Error: ERROR Unknown error"), TransportMessage.from_json(smsg.body))
def test03_sending_one_sms_service_failure(self): mocked_message = "Error: ERROR Unknown error" #HTTP response yield self.make_resource_worker(mocked_message) yield self.dispatch(self.mkmsg_out(to_addr='788601462')) [smsg] = self.get_dispatched('cm.event') self.assertEqual(self.mkmsg_fail( failure_level='service', failure_reason="Error: ERROR Unknown error"), TransportMessage.from_json(smsg.body))
def test03_sending_one_sms_service_failure(self): mocked_message = "ybs_autocreate_status%3DERROR%26ybs_autocreate_message%3DYBS%2BAutoCreate%2BSubsystem%3A%2BAccess%2Bdenied%2Bdue%2Bto%2Bwrong%2Bauthorization%2Bcode" #HTTP response yield self.make_resource_worker(mocked_message) yield self.dispatch(self.mkmsg_out(to_addr='+788601462')) [smsg] = self.get_dispatched('yo.event') self.assertEqual(self.mkmsg_fail( failure_level='service', failure_code='ERROR', failure_reason="YBS AutoCreate Subsystem: Access denied due to wrong authorization code"), TransportMessage.from_json(smsg.body))
def test_send_sms_noconn(self): msg = self.mkmsg_out() d = self.dispatch(msg) yield d [twisted_failure] = self.flushLoggedErrors(TemporaryFailure) failure = twisted_failure.value self.assertTrue("connection refused" in str(failure)) [fmsg] = self.get_dispatched('vas2nets.failures') fmsg = TransportMessage.from_json(fmsg.body) self.assertEqual(msg.payload, fmsg['message']) self.assertEqual(fmsg['failure_code'], FailureMessage.FC_TEMPORARY) self.assertTrue(fmsg['reason'].strip().endswith("connection refused"))
def test_receive_sms(self): response = yield self.make_request('/receive', { 'messageid': 'abc', 'text': 'hello world', }) self.assertEqual('', response.delivered_body) self.assertEqual(response.headers.getRawHeaders('content-type'), ['text/plain']) self.assertEqual(response.code, http.OK) msg = self.mkmsg_in() [smsg] = self.get_dispatched('vas2nets.inbound') self.assertEqual(msg, TransportMessage.from_json(smsg.body))
def test02_sending_one_sms_http_failure(self): mocked_message = "timeout" mocked_error = http.REQUEST_TIMEOUT #HTTP response yield self.make_resource_worker(mocked_message, mocked_error) yield self.dispatch(self.mkmsg_out(to_addr='+256788601462')) [smsg] = self.get_dispatched('yo.event') self.assertEqual(self.mkmsg_fail( failure_level='http', failure_code=http.REQUEST_TIMEOUT, failure_reason='timeout'), TransportMessage.from_json(smsg.body))
def test_send_sms_not_OK(self): mocked_message = "Page not found." yield self.make_resource_worker(None, mocked_message, http.NOT_FOUND) msg = self.mkmsg_out() deferred = self.dispatch(msg) yield deferred [fmsg] = self.get_dispatched('vas2nets.failures') fmsg = TransportMessage.from_json(fmsg.body) self.assertEqual(msg.payload, fmsg['message']) self.assertEqual(fmsg['failure_code'], FailureMessage.FC_PERMANENT) self.assertTrue(fmsg['reason'].strip() .endswith("server error: HTTP 404: Page not found."))
def test_send_sms_fail(self): mocked_message_id = False mocked_message = ("Result_code: 04, Internal system error occurred " "while processing message") yield self.make_resource_worker(mocked_message_id, mocked_message) msg = self.mkmsg_out() d = self.dispatch(msg) yield d [fmsg] = self.get_dispatched('vas2nets.failures') fmsg = TransportMessage.from_json(fmsg.body) self.assertEqual(msg.payload, fmsg['message']) self.assertTrue( "Vas2NetsTransportError: No SmsId Header" in fmsg['reason'])
def test_delivery_receipt_delivered(self): response = yield self.make_request('/receipt', { 'smsid': '1', 'messageid': 'abc', 'sender': '+41791234567', 'status': '2', 'text': 'Message delivered to MSISDN.', }) self.assertEqual('', response.delivered_body) self.assertEqual(response.headers.getRawHeaders('content-type'), ['text/plain']) self.assertEqual(response.code, http.OK) msg = self.mkmsg_delivery( 'delivered', '2', 'Message delivered to MSISDN.') [smsg] = self.get_dispatched('vas2nets.event') self.assertEqual(msg, TransportMessage.from_json(smsg.body))
def test_delivery_receipt_delivered(self): response = yield self.make_request( '/receipt', { 'smsid': '1', 'messageid': 'abc', 'sender': '+41791234567', 'status': '2', 'text': 'Message delivered to MSISDN.', }) self.assertEqual('', response.delivered_body) self.assertEqual(response.headers.getRawHeaders('content-type'), ['text/plain']) self.assertEqual(response.code, http.OK) msg = self.mkmsg_delivery('delivered', '2', 'Message delivered to MSISDN.') [smsg] = self.get_dispatched('vas2nets.event') self.assertEqual(msg, TransportMessage.from_json(smsg.body))
def test_send_sms_not_OK(self): mocked_message = "Page not found." yield self.make_resource_worker(None, mocked_message, http.NOT_FOUND) msg = self.mkmsg_out() deferred = self.dispatch(msg) yield deferred [twisted_failure] = self.flushLoggedErrors(PermanentFailure) failure = twisted_failure.value self.assertTrue("server error: HTTP 404:" in str(failure)) [fmsg] = self.get_dispatched('vas2nets.failures') fmsg = TransportMessage.from_json(fmsg.body) self.assertEqual(msg.payload, fmsg['message']) self.assertEqual(fmsg['failure_code'], FailureMessage.FC_PERMANENT) self.assertTrue(fmsg['reason'].strip().endswith( "server error: HTTP 404: Page not found."))
def test_send_sms_fail(self): mocked_message_id = False mocked_message = ("Result_code: 04, Internal system error occurred " "while processing message") yield self.make_resource_worker(mocked_message_id, mocked_message) msg = self.mkmsg_out() d = self.dispatch(msg) yield d [twisted_failure] = self.flushLoggedErrors(Vas2NetsTransportError) failure = twisted_failure.value self.assertTrue("No SmsId Header" in str(failure)) [fmsg] = self.get_dispatched('vas2nets.failures') fmsg = TransportMessage.from_json(fmsg.body) self.assertEqual(msg.payload, fmsg['message']) self.assertTrue( "Vas2NetsTransportError: No SmsId Header" in fmsg['reason'])
def make_request(self, path, qparams): """ Builds a request URL with the appropriate params. """ args = { 'messageid': TransportMessage.generate_id(), 'time': self.today.strftime('%Y.%m.%d %H:%M:%S'), 'sender': '0041791234567', 'destination': '9292', 'provider': 'provider', 'keyword': '', 'header': '', 'text': '', 'keyword': '', } args.update(qparams) url = self.transport_url + path return http_request_full(url, urlencode(args), { 'Content-Type': ['application/x-www-form-urlencoded'], })
def make_message(self, **extra_fields): fields = dict(message_type='foo') fields.update(extra_fields) return TransportMessage(**fields)
def test_transport_message(self): msg = TransportMessage(message_type='foo', ) self.assertEqual('foo', msg['message_type']) self.assertEqual('20110921', msg['message_version']) self.assertEqual(UTCNearNow(), msg['timestamp'])
def test_transport_message(self): msg = TransportMessage(message_type='foo', ) self.assertEqual('foo', msg['message_type'])