@@ -53,18 +53,74 @@ def user_password_input(prompt):
5353 assert str (excinfo .value ) == 'An authentication token is required!'
5454
5555
56- def test_is_online ():
56+ def test_is_online (monkeypatch ):
57+ def mock_get (_self , path , * args , ** kwargs ):
58+ assert urljoin (_api_url , 'backends' ) == path
59+ mock_response = mock .MagicMock ()
60+ mock_response .json = mock .MagicMock (
61+ return_value = [
62+ {
63+ "backend" : "qpu.s11" ,
64+ "status" : "available" ,
65+ "qubits" : 11 ,
66+ "average_queue_time" : 3253287 ,
67+ "last_updated" : 1647863473555 ,
68+ "characterization_url" : "/characterizations/48ccd423-2913-45e0-a669-e0f676abeb82" ,
69+ },
70+ {
71+ "backend" : "simulator" ,
72+ "status" : "available" ,
73+ "qubits" : 19 ,
74+ "average_queue_time" : 1499 ,
75+ "last_updated" : 1627065490042 ,
76+ },
77+ ],
78+ )
79+ return mock_response
80+
81+ monkeypatch .setattr ('requests.sessions.Session.get' , mock_get )
82+
5783 ionq_session = _ionq_http_client .IonQ ()
5884 ionq_session .authenticate ('not none' )
5985 ionq_session .update_devices_list ()
6086 assert ionq_session .is_online ('ionq_simulator' )
6187 assert ionq_session .is_online ('ionq_qpu' )
88+ assert ionq_session .is_online ('qpu.s11' )
6289 assert not ionq_session .is_online ('ionq_unknown' )
6390
6491
65- def test_show_devices ():
66- device_list = _ionq_http_client .show_devices ()
92+ def test_show_devices (monkeypatch ):
93+ def mock_get (_self , path , * args , ** kwargs ):
94+ assert urljoin (_api_url , 'backends' ) == path
95+ mock_response = mock .MagicMock ()
96+ mock_response .json = mock .MagicMock (
97+ return_value = [
98+ {
99+ "backend" : "qpu.s11" ,
100+ "status" : "available" ,
101+ "qubits" : 11 ,
102+ "average_queue_time" : 3253287 ,
103+ "last_updated" : 1647863473555 ,
104+ "characterization_url" : "/characterizations/48ccd423-2913-45e0-a669-e0f676abeb82" ,
105+ },
106+ {
107+ "backend" : "simulator" ,
108+ "status" : "available" ,
109+ "qubits" : 19 ,
110+ "average_queue_time" : 1499 ,
111+ "last_updated" : 1627065490042 ,
112+ },
113+ ],
114+ )
115+ return mock_response
116+
117+ monkeypatch .setattr ('requests.sessions.Session.get' , mock_get )
118+
119+ ionq_session = _ionq_http_client .IonQ ()
120+ ionq_session .authenticate ('not none' )
121+ device_list = ionq_session .show_devices ()
67122 assert isinstance (device_list , dict )
123+ assert len (device_list ) == 4
68124 for info in device_list .values ():
69125 assert 'nq' in info
70126 assert 'target' in info
0 commit comments