Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit da21681

Browse files
committed
Init api instance
1 parent 27b3c0f commit da21681

3 files changed

Lines changed: 36 additions & 17 deletions

File tree

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/corellium/api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional
22

3+
import corellium_api
34
import requests
45

56
from .exceptions import CorelliumApiException
@@ -23,6 +24,10 @@ def __init__(self, host: str, token: str) -> None:
2324
self.session = None
2425
self.req = requests.Session()
2526

27+
configuration = corellium_api.Configuration(host=self.baseurl)
28+
configuration.access_token = self.token
29+
self.api = corellium_api.CorelliumApi(corellium_api.ApiClient(configuration))
30+
2631
@property
2732
def baseurl(self) -> str:
2833
"""

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/corellium/api_test.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from .exceptions import CorelliumApiException
77
from .types import Device, Instance, Project, Session
88

9+
pytestmark = pytest.mark.anyio
10+
11+
12+
@pytest.fixture
13+
def anyio_backend():
14+
return "asyncio"
15+
916

1017
def fixture(path):
1118
"""
@@ -18,7 +25,7 @@ def fixture(path):
1825
return f.read()
1926

2027

21-
def test_login_ok(requests_mock):
28+
async def test_login_ok(requests_mock):
2229
requests_mock.post("https://api-host/api/v1/auth/login", text=fixture("http/login-200.json"))
2330

2431
api = ApiClient("api-host", "api-token")
@@ -36,7 +43,7 @@ def test_login_ok(requests_mock):
3643
(200, fixture("http/json-error.json"), "Invalid control character at"),
3744
],
3845
)
39-
def test_login_error(requests_mock, status_code, data, msg):
46+
async def test_login_error(requests_mock, status_code, data, msg):
4047
requests_mock.post("https://api-host/api/v1/auth/login", status_code=status_code, text=data)
4148
api = ApiClient("api-host", "api-token")
4249

@@ -55,7 +62,7 @@ def test_login_error(requests_mock, status_code, data, msg):
5562
("notfound", fixture("http/get-projects-200.json"), False),
5663
],
5764
)
58-
def test_get_project_ok(requests_mock, project_name, data, has_results):
65+
async def test_get_project_ok(requests_mock, project_name, data, has_results):
5966
requests_mock.get("https://api-host/api/v1/projects", status_code=200, text=data)
6067
api = ApiClient("api-host", "api-token")
6168
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
@@ -79,7 +86,7 @@ def test_get_project_ok(requests_mock, project_name, data, has_results):
7986
(404, fixture("http/get-projects-404.json"), ""),
8087
],
8188
)
82-
def test_get_project_error(requests_mock, status_code, data, msg):
89+
async def test_get_project_error(requests_mock, status_code, data, msg):
8390
requests_mock.get("https://api-host/api/v1/projects", status_code=status_code, text=data)
8491
api = ApiClient("api-host", "api-token")
8592
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
@@ -94,7 +101,7 @@ def test_get_project_error(requests_mock, status_code, data, msg):
94101
"model,data,has_results",
95102
[("rpi4b", fixture("http/get-models-200.json"), True), ("notfound", fixture("http/get-models-200.json"), False)],
96103
)
97-
def test_get_device_ok(requests_mock, model, data, has_results):
104+
async def test_get_device_ok(requests_mock, model, data, has_results):
98105
requests_mock.get("https://api-host/api/v1/models", status_code=200, text=data)
99106
api = ApiClient("api-host", "api-token")
100107
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
@@ -114,7 +121,7 @@ def test_get_device_ok(requests_mock, model, data, has_results):
114121
(403, fixture("http/403.json"), "Invalid or missing authorization token"),
115122
],
116123
)
117-
def test_get_device_error(requests_mock, status_code, data, msg):
124+
async def test_get_device_error(requests_mock, status_code, data, msg):
118125
requests_mock.get("https://api-host/api/v1/models", status_code=status_code, text=data)
119126
api = ApiClient("api-host", "api-token")
120127
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
@@ -125,7 +132,7 @@ def test_get_device_error(requests_mock, status_code, data, msg):
125132
assert msg in str(e.value)
126133

127134

128-
def test_create_instance_ok(requests_mock):
135+
async def test_create_instance_ok(requests_mock):
129136
data = fixture("http/create-instance-200.json")
130137
requests_mock.post("https://api-host/api/v1/instances", status_code=200, text=data)
131138
api = ApiClient("api-host", "api-token")
@@ -153,7 +160,7 @@ def test_create_instance_ok(requests_mock):
153160
(400, fixture("http/create-instance-400.json"), "Unsupported device model"),
154161
],
155162
)
156-
def test_create_instance_error(requests_mock, status_code, data, msg):
163+
async def test_create_instance_error(requests_mock, status_code, data, msg):
157164
requests_mock.post("https://api-host/api/v1/instances", status_code=status_code, text=data)
158165
api = ApiClient("api-host", "api-token")
159166
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
@@ -173,7 +180,7 @@ def test_create_instance_error(requests_mock, status_code, data, msg):
173180
assert msg in str(e.value)
174181

175182

176-
def test_destroy_instance_state_ok(requests_mock):
183+
async def test_destroy_instance_state_ok(requests_mock):
177184
instance = Instance(id="d59db33d-27bd-4b22-878d-49e4758a648e")
178185

179186
requests_mock.delete(f"https://api-host/api/v1/instances/{instance.id}", status_code=204, text="")
@@ -189,7 +196,7 @@ def test_destroy_instance_state_ok(requests_mock):
189196
(404, fixture("http/get-instance-state-404.json"), "No instance associated with this value"),
190197
],
191198
)
192-
def test_destroy_instance_error(requests_mock, status_code, data, msg):
199+
async def test_destroy_instance_error(requests_mock, status_code, data, msg):
193200
instance = Instance(id="d59db33d-27bd-4b22-878d-49e4758a648e")
194201

195202
requests_mock.delete(f"https://api-host/api/v1/instances/{instance.id}", status_code=status_code, text=data)

packages/jumpstarter-driver-corellium/jumpstarter_driver_corellium/driver_test.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
from .driver import Corellium, CorelliumPower
88
from jumpstarter.common import exceptions as jmp_exceptions
99

10+
pytestmark = pytest.mark.anyio
1011

11-
def test_driver_corellium_init_ok(monkeypatch):
12+
13+
@pytest.fixture
14+
def anyio_backend():
15+
return "asyncio"
16+
17+
18+
async def test_driver_corellium_init_ok(monkeypatch):
1219
monkeypatch.setenv("CORELLIUM_API_HOST", "api-host")
1320
monkeypatch.setenv("CORELLIUM_API_TOKEN", "api-token")
1421

@@ -40,7 +47,7 @@ def test_driver_corellium_init_ok(monkeypatch):
4047
),
4148
],
4249
)
43-
def test_driver_corellium_init_error(monkeypatch, env, err):
50+
async def test_driver_corellium_init_error(monkeypatch, env, err):
4451
monkeypatch.delenv("CORELLIUM_API_HOST", raising=False)
4552
monkeypatch.delenv("CORELLIUM_API_TOKEN", raising=False)
4653

@@ -53,7 +60,7 @@ def test_driver_corellium_init_error(monkeypatch, env, err):
5360
assert str(err) == str(e.value)
5461

5562

56-
def test_driver_api_client_ok(monkeypatch, requests_mock):
63+
async def test_driver_api_client_ok(monkeypatch, requests_mock):
5764
requests_mock.post(
5865
"https://api-host/api/v1/auth/login", text='{"token": "token", "expiration": "2022-03-20T01:50:10.000Z"}'
5966
)
@@ -65,7 +72,7 @@ def test_driver_api_client_ok(monkeypatch, requests_mock):
6572
assert Session("token", "2022-03-20T01:50:10.000Z") == c.api.session
6673

6774

68-
def test_driver_power_on_ok(monkeypatch):
75+
async def test_driver_power_on_ok(monkeypatch):
6976
monkeypatch.setenv("CORELLIUM_API_HOST", "api-host")
7077
monkeypatch.setenv("CORELLIUM_API_TOKEN", "api-token")
7178

@@ -101,7 +108,7 @@ def test_driver_power_on_ok(monkeypatch):
101108
({"create_instance": {"side_effect": CorelliumApiException("create error")}}),
102109
],
103110
)
104-
def test_driver_power_on_error(monkeypatch, mock_data):
111+
async def test_driver_power_on_error(monkeypatch, mock_data):
105112
monkeypatch.setenv("CORELLIUM_API_HOST", "api-host")
106113
monkeypatch.setenv("CORELLIUM_API_TOKEN", "api-token")
107114

@@ -120,7 +127,7 @@ def test_driver_power_on_error(monkeypatch, mock_data):
120127
power.off()
121128

122129

123-
def test_driver_power_off_ok(monkeypatch):
130+
async def test_driver_power_off_ok(monkeypatch):
124131
monkeypatch.setenv("CORELLIUM_API_HOST", "api-host")
125132
monkeypatch.setenv("CORELLIUM_API_TOKEN", "api-token")
126133

@@ -147,7 +154,7 @@ def test_driver_power_off_ok(monkeypatch):
147154
({"destroy_instance": {"side_effect": CorelliumApiException("destroy error")}}),
148155
],
149156
)
150-
def test_driver_power_off_error(monkeypatch, mock_data):
157+
async def test_driver_power_off_error(monkeypatch, mock_data):
151158
monkeypatch.setenv("CORELLIUM_API_HOST", "api-host")
152159
monkeypatch.setenv("CORELLIUM_API_TOKEN", "api-token")
153160

0 commit comments

Comments
 (0)