Пример #1
0
class MinimalLowerLayerProtocolTest(TestCase):
    def setUp(self):
        self.receiver = CaptureReceiver()

        self.protocol = MinimalLowerLayerProtocol()
        self.protocol.factory = MLLPFactory(self.receiver)
        self.protocol.transport = Mock()

    def testParseMessage(self):
        self.protocol.dataReceived('\x0b' + HL7_MESSAGE + '\x1c\x0d')

        self.assertEqual(self.receiver.messages, [HL7_MESSAGE])
        self.assertEqual(self.protocol.transport.write.call_args[0][0],
                         '\x0b' + EXPECTED_ACK.format('AA') + '\x1c\x0d')

    def testUncaughtError(self):
        # throw a random exception, make sure Errback is used
        self.receiver.handleMessage = Mock()
        self.receiver.handleMessage.side_effect = Exception

        self.protocol.dataReceived('\x0b' + HL7_MESSAGE + '\x1c\x0d')

        self.assertEqual(self.protocol.transport.write.call_args[0][0],
                         '\x0b' + EXPECTED_ACK.format('AR') + '\x1c\x0d')

    def testParseMessageUnicode(self):
        message = HL7_MESSAGE.replace('BLDG4', 'x\x82y')
        self.protocol.dataReceived('\x0b' + message + '\x1c\x0d')

        expected_message = unicode(HL7_MESSAGE).replace(u'BLDG4', u'x\u201ay')
        self.assertEqual(self.receiver.messages, [expected_message])

        expected_ack = EXPECTED_ACK.replace('BLDG4', 'x\x82y')
        self.assertEqual(self.protocol.transport.write.call_args[0][0],
                         '\x0b' + expected_ack.format('AA') + '\x1c\x0d')
Пример #2
0
def create_protocol(receiver):
    protocol = MinimalLowerLayerProtocol()
    protocol.factory = MLLPFactory(receiver)
    protocol.transport = Mock()
    return protocol
Пример #3
0
    def setUp(self):
        self.receiver = CaptureReceiver()

        self.protocol = MinimalLowerLayerProtocol()
        self.protocol.factory = MLLPFactory(self.receiver)
        self.protocol.transport = Mock()
Пример #4
0
def create_protocol(receiver):
    protocol = MinimalLowerLayerProtocol()
    protocol.factory = MLLPFactory(receiver)
    protocol.transport = Mock()
    return protocol