def test_handler_bad_payload(self, mock_web): mock_queue = mock.MagicMock(asyncio.Queue) with mock.patch( 'bdssnmpadaptor.config.open', side_effect=[io.StringIO(self.CONFIG), io.StringIO(self.CONFIG), io.StringIO(self.CONFIG)]): rs = rest_server.AsyncioRestServer( mock.MagicMock(config={}), mock_queue) mock_web.json_response = asynctest.CoroutineMock() mock_request = mock.MagicMock() mock_request.method = 'PUT' mock_request.json.side_effect = Exception() self.my_loop.run_until_complete( rs.handler(mock_request)) self.assertFalse(mock_queue.put_nowait.called) mock_web.json_response.assert_called_once_with( status=500, text='Malformed request payload')
def test_handler(self, mock_web, mock_json): mock_queue = mock.MagicMock(asyncio.Queue) with mock.patch('bdssnmpadaptor.config.open', side_effect=[ io.StringIO(self.CONFIG), io.StringIO(self.CONFIG), io.StringIO(self.CONFIG) ]): rs = rest_server.AsyncioRestServer(mock.MagicMock(config={}), mock_queue) mock_web.json_response = asynctest.CoroutineMock() mock_request = mock.MagicMock() mock_request.text = asynctest.CoroutineMock() self.my_loop.run_until_complete(rs.handler(mock_request)) mock_json.loads.assert_called_once_with(mock.ANY) mock_queue.put_nowait.assert_called_once_with(mock.ANY) mock_web.json_response.assert_called_once_with(mock.ANY)
def test___init__(self): with mock.patch( 'bdssnmpadaptor.config.open', side_effect=[io.StringIO(self.CONFIG), io.StringIO(self.CONFIG), io.StringIO(self.CONFIG)]): mock_queue = mock.MagicMock() rs = rest_server.AsyncioRestServer( mock.MagicMock(config={}), mock_queue) self.assertEqual('0.0.0.0', rs.listeningIP) self.assertEqual(5000, rs.listeningPort)
def test_initialize(self, mock_web): mock_queue = mock.MagicMock(asyncio.Queue) with mock.patch( 'bdssnmpadaptor.config.open', side_effect=[io.StringIO(self.CONFIG), io.StringIO(self.CONFIG), io.StringIO(self.CONFIG)]): rs = rest_server.AsyncioRestServer( mock.MagicMock(config={}), mock_queue) self.my_loop.create_server = asynctest.CoroutineMock() self.my_loop.run_until_complete(rs.initialize()) mock_server = mock_web.Server mock_server.assert_called_once()