Beispiel #1
0
 def test_drop_link(self):
     protocol = yield self.get_protocol()
     transport = yield connect_transport(protocol)
     [bind_pdu] = yield wait_for_pdus(transport, 1)
     self.assertCommand(bind_pdu, 'bind_transceiver')
     self.assertFalse(protocol.is_bound())
     self.assertEqual(protocol.state, EsmeTransceiver.OPEN_STATE)
     self.assertFalse(transport.disconnecting)
     self.clock.advance(protocol.config.smpp_bind_timeout + 1)
     [unbind_pdu] = yield wait_for_pdus(transport, 1)
     self.assertCommand(unbind_pdu, 'unbind')
     unbind_resp_pdu = UnbindResp(sequence_number=seq_no(unbind_pdu))
     yield protocol.on_pdu(unpack_pdu(unbind_resp_pdu.get_bin()))
     self.assertTrue(transport.disconnecting)
Beispiel #2
0
    def test_enquire_link_looping(self):
        transport, protocol = yield self.setup_bind(clear=False)
        enquire_link_resp = EnquireLinkResp(1)

        protocol.clock.advance(protocol.idle_timeout - 1)
        protocol.dataReceived(enquire_link_resp.get_bin())

        protocol.clock.advance(protocol.idle_timeout - 1)
        self.assertFalse(transport.disconnecting)
        protocol.clock.advance(1)

        [unbind_pdu] = yield wait_for_pdus(transport, 1)
        self.assertCommand(unbind_pdu, 'unbind')
        unbind_resp_pdu = UnbindResp(sequence_number=seq_no(unbind_pdu))
        yield protocol.on_pdu(unpack_pdu(unbind_resp_pdu.get_bin()))
        self.assertTrue(transport.disconnecting)
Beispiel #3
0
 def test_unbind(self):
     calls = []
     self.patch(EsmeTransceiver, 'handle_unbind_resp',
                lambda p, pdu: calls.append(pdu))
     transport, protocol = yield self.setup_bind()
     yield protocol.unbind()
     [unbind_pdu] = yield wait_for_pdus(transport, 1)
     protocol.dataReceived(UnbindResp(seq_no(unbind_pdu)).get_bin())
     [unbind_resp_pdu] = calls
     self.assertEqual(seq_no(unbind_resp_pdu), seq_no(unbind_pdu))
Beispiel #4
0
 def test_unbind(self):
     protocol = yield self.get_protocol()
     calls = []
     protocol.handle_unbind_resp = calls.append
     yield self.fake_smsc.bind()
     yield protocol.unbind()
     unbind_pdu = yield self.fake_smsc.await_pdu()
     protocol.dataReceived(UnbindResp(seq_no(unbind_pdu)).get_bin())
     [unbind_resp_pdu] = calls
     self.assertEqual(seq_no(unbind_resp_pdu), seq_no(unbind_pdu))
Beispiel #5
0
 def test_drop_link(self):
     protocol = yield self.get_protocol()
     bind_pdu = yield self.fake_smsc.await_pdu()
     self.assertCommand(bind_pdu, 'bind_transceiver')
     self.assertFalse(protocol.is_bound())
     self.assertEqual(protocol.state, EsmeProtocol.OPEN_STATE)
     self.clock.advance(protocol.config.smpp_bind_timeout + 1)
     unbind_pdu = yield self.fake_smsc.await_pdu()
     self.assertCommand(unbind_pdu, 'unbind')
     yield self.fake_smsc.send_pdu(UnbindResp(seq_no(unbind_pdu)))
     yield self.fake_smsc.await_disconnect()
Beispiel #6
0
    def test_auto_unbind(self):
        """
        FakeSMSC will automatically respond to an unbind request by default.
        The unbind PDU remains in the queue.
        """
        fake_smsc = FakeSMSC()
        client = self.successResultOf(self.connect(fake_smsc))
        self.assertEqual(client.received, b"")
        self.assertEqual(fake_smsc.waiting_pdu_count(), 0)

        yield client.write(Unbind(7).get_bin())
        self.assertEqual(client.received, UnbindResp(7).get_bin())
        self.assertEqual(fake_smsc.waiting_pdu_count(), 1)
Beispiel #7
0
    def test_enquire_link_looping(self):
        self.fake_smsc.auto_unbind = False
        protocol = yield self.get_protocol()
        yield self.fake_smsc.bind()
        self.assertEqual(self.fake_smsc.connected, True)

        # Respond to a few enquire_link cycles.
        for i in range(5):
            self.clock.advance(protocol.idle_timeout - 1)
            pdu = yield self.fake_smsc.await_pdu()
            self.assertCommand(pdu, 'enquire_link')
            yield self.fake_smsc.respond_to_enquire_link(pdu)

        # Fail to respond, so we disconnect.
        self.clock.advance(protocol.idle_timeout - 1)
        pdu = yield self.fake_smsc.await_pdu()
        self.assertCommand(pdu, 'enquire_link')
        self.clock.advance(1)
        unbind_pdu = yield self.fake_smsc.await_pdu()
        self.assertCommand(unbind_pdu, 'unbind')
        yield self.fake_smsc.send_pdu(
            UnbindResp(seq_no(unbind_pdu)))
        yield self.fake_smsc.await_disconnect()
Beispiel #8
0
 def handle_unbind(self, pdu):
     return self.send_pdu(UnbindResp(seq_no(pdu)))
Beispiel #9
0
 def pdu_received(self, pdu):
     self.pdu_queue.put(pdu)
     if self.auto_unbind and command_id(pdu) == 'unbind':
         self.send_pdu(UnbindResp(seq_no(pdu)))
Beispiel #10
0
 def handle_unbind(self, pdu):
     yield self.send_pdu(
         UnbindResp(sequence_number=pdu['header']['sequence_number']))
     self.transport.loseConnection()