def test_invalid_url(self): """Test connecting to an invalid URL.""" client = WebsocketClient('wss://{}:{}'.format(TEST_IP_ADDRESS, INVALID_PORT), None) with self.assertRaises(WebsocketError): asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id'))
def test_timeout(self): """Test timeout during retrieving a job status.""" client = WebsocketClient( 'ws://{}:{}'.format(TEST_IP_ADDRESS, VALID_PORT), TOKEN_TIMEOUT) with self.assertRaises(WebsocketTimeoutError): _ = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id', timeout=2))
def test_websocket_retry_failure(self): """Test exceeding the retry limit for retrieving a job status.""" client = WebsocketClient('ws://{}:{}'.format( TEST_IP_ADDRESS, VALID_PORT), TOKEN_WEBSOCKET_RETRY_FAILURE) with self.assertRaises(WebsocketError): _ = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id'))
def test_websocket_job_not_found(self): """Test retrieving a job status for an non existent id.""" client = WebsocketClient('ws://{}:{}'.format( TEST_IP_ADDRESS, VALID_PORT), TOKEN_WEBSOCKET_JOB_NOT_FOUND) with self.assertRaises(WebsocketError): _ = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id'))
def test_invalid_response(self): """Test unparseable response from the server.""" client = WebsocketClient('ws://{}:{}'.format( TEST_IP_ADDRESS, VALID_PORT), TOKEN_WRONG_FORMAT) with self.assertRaises(WebsocketIBMQProtocolError): _ = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id'))
def test_invalid_url(self): """Test connecting to an invalid URL.""" ws_url = f"wss://{MockWsServer.WS_IP_ADDRESS}:{MockWsServer.WS_INVALID_PORT}" cred = Credentials(token="my_token", url="", websockets_url=ws_url) client = WebsocketClient(ws_url, cred, "job_id") with self.assertRaises(WebsocketError): client.get_job_status()
def test_websocket_status_queue(self): """Test status queue used by websocket client.""" status_queue = RefreshQueue(maxsize=10) cred = Credentials(token="", url="", websockets_url=MockWsServer.VALID_WS_URL, access_token=TOKEN_JOB_TRANSITION) client = WebsocketClient(MockWsServer.VALID_WS_URL, cred, "job_id", status_queue) client.get_job_status() self.assertEqual(status_queue.qsize(), 2)
def test_websocket_retry_success(self): """Test retrieving a job status during a retry attempt.""" client = WebsocketClient('ws://{}:{}'.format( TEST_IP_ADDRESS, VALID_PORT), TOKEN_WEBSOCKET_RETRY_SUCCESS) response = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id')) self.assertIsInstance(response, dict) self.assertIn('status', response) self.assertEqual(response['status'], 'COMPLETED')
def test_job_transition(self): """Test retrieving a job that transitions to final status.""" client = WebsocketClient('ws://{}:{}'.format( TEST_IP_ADDRESS, VALID_PORT), TOKEN_JOB_TRANSITION) response = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id')) self.assertIsInstance(response, dict) self.assertIn('status', response) self.assertEqual(response['status'], 'COMPLETED')
def test_websocket_status_queue(self): """Test status queue used by websocket client.""" client = WebsocketClient( 'ws://{}:{}'.format(TEST_IP_ADDRESS, VALID_PORT), TOKEN_JOB_TRANSITION) status_queue = RefreshQueue(maxsize=10) _ = asyncio.get_event_loop().run_until_complete( client.get_job_status('job_id', status_queue=status_queue)) self.assertEqual(status_queue.qsize(), 2)
def _get_ws_client(self, token=TOKEN_JOB_COMPLETED, url=MockWsServer.VALID_WS_URL): cred = Credentials(token="", url="", websockets_url=url, access_token=token) return WebsocketClient(url, cred, "job_id")