Beispiel #1
0
 def testTlsServerServeForever(self):
     ''' Test StartTcpServer serve_forever() method '''
     with patch('asyncio.base_events.Server.serve_forever', new_callable=asynctest.CoroutineMock) as serve:
         with patch.object(ssl.SSLContext, 'load_cert_chain') as mock_method:
             server = yield from StartTlsServer(context=self.context,address=("127.0.0.1", 0), loop=self.loop)
             yield from server.serve_forever()
             serve.assert_awaited()
Beispiel #2
0
 def testStartTlsServer(self):
     ''' Test that the modbus tls asyncio server starts correctly '''
     with patch.object(ssl.SSLContext, 'load_cert_chain') as mock_method:
         identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
         self.loop = asynctest.Mock(self.loop)
         server = yield from StartTlsServer(context=self.context,loop=self.loop,identity=identity)
         self.assertEqual(server.control.Identity.VendorName, 'VendorName')
         self.assertIsNotNone(server.sslctx)
         if PYTHON_VERSION >= (3, 6):
             self.loop.create_server.assert_called_once()
 def testTlsServerServeNoDefer(self):
     ''' Test StartTcpServer without deferred start (immediate execution of server) '''
     with patch('asyncio.base_events.Server.serve_forever',
                new_callable=asynctest.CoroutineMock) as serve:
         with patch.object(ssl.SSLContext,
                           'load_cert_chain') as mock_method:
             server = yield from StartTlsServer(context=self.context,
                                                address=("127.0.0.1", 0),
                                                loop=self.loop,
                                                defer_start=False)
             serve.assert_awaited()
Beispiel #4
0
 def testTlsServerServeForeverTwice(self):
     ''' Call on serve_forever() twice should result in a runtime error '''
     with patch.object(ssl.SSLContext, 'load_cert_chain') as mock_method:
         server = yield from StartTlsServer(context=self.context,address=("127.0.0.1", 0), loop=self.loop)
         if PYTHON_VERSION >= (3, 7):
             server_task = asyncio.create_task(server.serve_forever())
         else:
             server_task = asyncio.ensure_future(server.serve_forever())
         yield from server.serving
         with self.assertRaises(RuntimeError):
             yield from server.serve_forever()
         server.server_close()