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_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_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_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_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_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')