def test_bind_with_systemType_defined(self): "Testing for #64, systemType must be always string" # Test 1: systemType in string self.config.bindOperation = 'transmitter' self.config.systemType = '999999' client = SMPPClientFactory(self.config) # Connect and bind yield client.connectAndBind() smpp = client.smpp # Session state check self.assertEqual(SMPPSessionStates.BOUND_TX, smpp.sessionState) # Unbind & Disconnect yield client.disconnect() # Test 1: systemType in integer self.config.systemType = 999999 client = SMPPClientFactory(self.config) # Connect and bind yield client.connectAndBind() smpp = client.smpp # Session state check self.assertEqual(SMPPSessionStates.BIND_TX_PENDING, smpp.sessionState) # Unbind & Disconnect yield client.disconnect()
def test_bind_with_systemType_defined(self): "Testing for #64, systemType must be always string" # Test 1: systemType in string self.config.bindOperation = 'transmitter' self.config.systemType = '999999' client = SMPPClientFactory(self.config) # Connect and bind yield client.connectAndBind() smpp = client.smpp # Session state check self.assertEqual(SMPPSessionStates.BOUND_TX, smpp.sessionState) # Unbind & Disconnect yield client.disconnect() # Test 1: systemType in integer self.config.systemType = 999999 client = SMPPClientFactory(self.config) # Connect and bind yield client.connectAndBind() smpp = client.smpp # Session state check self.assertEqual(SMPPSessionStates.BIND_TX_PENDING, smpp.sessionState) # Unbind & Disconnect yield client.disconnect()
def test_multiple_clients(self): """Reference to #28: SMPP client's logging does not work correctly with multiple connectors """ args = self.configArgs.copy() args['id'] = 'test-id-2' args['port'] = self.testPort args['bindOperation'] = 'transmitter' args['log_level'] = self.configArgs.get('log_level', logging.DEBUG) self.config2 = SMPPClientConfig(**args) client1 = SMPPClientFactory(self.config) client2 = SMPPClientFactory(self.config2) lc1 = LogCapture("smpp.client.%s" % client1.config.id) lc2 = LogCapture("smpp.client.%s" % client2.config.id) # Connect and bind yield client1.connectAndBind() yield client2.connectAndBind() # Unbind & Disconnect yield client1.disconnect() yield client2.disconnect() # Assert logging of client1 bindRequestsCount = 0 for record in lc1.records: if record.getMessage()[:30] == 'Requesting bind as transceiver': bindRequestsCount+= 1 self.assertEqual(bindRequestsCount, 1) # Assert logging of client2 bindRequestsCount = 0 for record in lc2.records: if record.getMessage()[:30] == 'Requesting bind as transmitter': bindRequestsCount+= 1 self.assertEqual(bindRequestsCount, 1)
def test_multiple_clients(self): """Reference to #28: SMPP client's logging does not work correctly with multiple connectors """ args = self.configArgs.copy() args['id'] = 'test-id-2' args['port'] = self.testPort args['bindOperation'] = 'transmitter' args['log_level'] = self.configArgs.get('log_level', logging.DEBUG) self.config2 = SMPPClientConfig(**args) client1 = SMPPClientFactory(self.config) client2 = SMPPClientFactory(self.config2) lc1 = LogCapture("smpp.client.%s" % client1.config.id) lc2 = LogCapture("smpp.client.%s" % client2.config.id) # Connect and bind yield client1.connectAndBind() yield client2.connectAndBind() # Unbind & Disconnect yield client1.disconnect() yield client2.disconnect() # Assert logging of client1 bindRequestsCount = 0 for record in lc1.records: if record.getMessage()[:30] == 'Requesting bind as transceiver': bindRequestsCount += 1 self.assertEqual(bindRequestsCount, 1) # Assert logging of client2 bindRequestsCount = 0 for record in lc2.records: if record.getMessage()[:30] == 'Requesting bind as transmitter': bindRequestsCount += 1 self.assertEqual(bindRequestsCount, 1)
def test_reconnect_on_connection_failure(self): client = SMPPClientFactory(self.config) client.reConnect = mock.Mock(wraps=client.reConnect) # Connect and bind yield client.connectAndBind() smpp = client.smpp smpp.PDUReceived = mock.Mock(wraps=smpp.PDUReceived) smpp.sendPDU = mock.Mock(wraps=smpp.sendPDU) # Unbind & Disconnect yield client.disconnect() ############## # Assertions : # Protocol verification self.assertEquals(1, smpp.PDUReceived.call_count) self.assertEquals(1, smpp.sendPDU.call_count) self.assertNotEqual(0, client.reConnect.call_count)
def test_reconnect_on_connection_failure(self): client = SMPPClientFactory(self.config) client.reConnect = mock.Mock(wraps=client.reConnect) # Connect and bind yield client.connectAndBind() smpp = client.smpp smpp.PDUReceived = mock.Mock(wraps=smpp.PDUReceived) smpp.sendPDU = mock.Mock(wraps=smpp.sendPDU) # Unbind & Disconnect yield client.disconnect() ############## # Assertions : # Protocol verification self.assertEquals(1, smpp.PDUReceived.call_count) self.assertEquals(1, smpp.sendPDU.call_count) self.assertNotEqual(0, client.reConnect.call_count)
def test_bind_unbind_transceiver(self): client = SMPPClientFactory(self.config) # Connect and bind yield client.connectAndBind() smpp = client.smpp smpp.PDUReceived = mock.Mock(wraps=smpp.PDUReceived) smpp.sendPDU = mock.Mock(wraps=smpp.sendPDU) # Session state check self.assertEqual(SMPPSessionStates.BOUND_TRX, smpp.sessionState) # Unbind & Disconnect yield client.disconnect() ############## # Assertions : # Protocol verification recv1, sent1 = self.verify(smpp, UnbindResp) # Unbind successfull self.assertEqual(recv1.status, CommandStatus.ESME_ROK) # Session state check self.assertEqual(SMPPSessionStates.UNBOUND, smpp.sessionState)
def test_bind_unbind_transceiver(self): client = SMPPClientFactory(self.config) # Connect and bind yield client.connectAndBind() smpp = client.smpp smpp.PDUReceived = mock.Mock(wraps=smpp.PDUReceived) smpp.sendPDU = mock.Mock(wraps=smpp.sendPDU) # Session state check self.assertEqual(SMPPSessionStates.BOUND_TRX, smpp.sessionState) # Unbind & Disconnect yield client.disconnect() ############## # Assertions : # Protocol verification recv1, sent1 = self.verify(smpp, UnbindResp) # Unbind successfull self.assertEqual(recv1.status, CommandStatus.ESME_ROK) # Session state check self.assertEqual(SMPPSessionStates.UNBOUND, smpp.sessionState)