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

Commit 9896633

Browse files
committed
Use new get_project
1 parent da21681 commit 9896633

6 files changed

Lines changed: 36 additions & 62 deletions

File tree

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,15 @@ def login(self) -> None:
5656
self.session = Session(**data)
5757
self.req.headers.update(self.session.as_header())
5858

59-
def get_project(self, project_ref: str = "Default Project") -> Optional[Project]:
59+
async def get_project(self, project_ref: str = "Default Project") -> Optional[Project]:
6060
"""
6161
Retrieve a project based on project_ref, which is either its id or name.
6262
"""
63-
try:
64-
res = self.req.get(f"{self.baseurl}/v1/projects")
65-
data = res.json()
66-
res.raise_for_status()
67-
except requests.exceptions.RequestException as e:
68-
raise CorelliumApiException(data.get("error", str(e))) from e
6963

70-
for project in data:
71-
if project["name"] == project_ref or project["id"] == project_ref:
72-
return Project(id=project["id"], name=project["name"])
64+
projects = await self.api.v1_get_projects()
65+
for project in projects:
66+
if project.name == project_ref or project.id == project_ref:
67+
return project
7368

7469
return None
7570

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,49 +54,6 @@ async def test_login_error(requests_mock, status_code, data, msg):
5454
assert api.session is None
5555

5656

57-
@pytest.mark.parametrize(
58-
"project_name,data,has_results",
59-
[
60-
("OtherProject", fixture("http/get-projects-200.json"), True),
61-
(None, fixture("http/get-projects-200.json"), True),
62-
("notfound", fixture("http/get-projects-200.json"), False),
63-
],
64-
)
65-
async def test_get_project_ok(requests_mock, project_name, data, has_results):
66-
requests_mock.get("https://api-host/api/v1/projects", status_code=200, text=data)
67-
api = ApiClient("api-host", "api-token")
68-
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
69-
70-
args = []
71-
if project_name:
72-
args.append(project_name)
73-
project = api.get_project(*args)
74-
75-
if has_results:
76-
assert project is not None
77-
assert project.name == project_name if project_name is not None else "Default Project"
78-
else:
79-
assert project is None
80-
81-
82-
@pytest.mark.parametrize(
83-
"status_code,data,msg",
84-
[
85-
(403, fixture("http/403.json"), "Invalid or missing authorization token"),
86-
(404, fixture("http/get-projects-404.json"), ""),
87-
],
88-
)
89-
async def test_get_project_error(requests_mock, status_code, data, msg):
90-
requests_mock.get("https://api-host/api/v1/projects", status_code=status_code, text=data)
91-
api = ApiClient("api-host", "api-token")
92-
api.session = Session("session-token", "2022-03-20T01:50:10.000Z")
93-
94-
with pytest.raises(CorelliumApiException) as e:
95-
api.get_project()
96-
97-
assert msg in str(e.value)
98-
99-
10057
@pytest.mark.parametrize(
10158
"model,data,has_results",
10259
[("rpi4b", fixture("http/get-models-200.json"), True), ("notfound", fixture("http/get-models-200.json"), False)],

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def wait_instance(self, current: Instance, desired: Optional[Instance]):
142142
time.sleep(opts["interval"])
143143

144144
@export
145-
def on(self) -> None:
145+
async def on(self) -> None:
146146
"""
147147
Power a Corellium virtual device on.
148148
@@ -153,7 +153,7 @@ def on(self) -> None:
153153
self.logger.info(f"\tDevice Flavor: {self.parent.device_flavor}")
154154
self.logger.info(f"\tDevice OS Version: {self.parent.device_os}")
155155

156-
project = self.parent.api.get_project(self.parent.project_id)
156+
project = await self.parent.api.get_project(self.parent.project_id)
157157
if project is None:
158158
raise ValueError(f"Unable to fetch project: {self.parent.project_id}")
159159
self.logger.info(f"Using project: {project.name}")
@@ -180,12 +180,12 @@ def on(self) -> None:
180180
self.wait_instance(instance, Instance(id=instance.id, state="on"))
181181

182182
@export
183-
def off(self, destroy: bool = False) -> None:
183+
async def off(self, destroy: bool = False) -> None:
184184
"""
185185
Destroy a Corellium virtual device/instance.
186186
"""
187187
# fail if project does not exist
188-
project = self.parent.api.get_project(self.parent.project_id)
188+
project = await self.parent.api.get_project(self.parent.project_id)
189189
if project is None:
190190
raise ValueError(f"Unable to fetch project: {self.parent.project_id}")
191191

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def test_driver_power_on_ok(monkeypatch):
9696
patch.object(root._api, "get_instance", side_effect=[None, instance]),
9797
patch.object(root._api, "create_instance", return_value=instance),
9898
):
99-
power.on()
99+
await power.on()
100100

101101

102102
@pytest.mark.parametrize(
@@ -124,7 +124,7 @@ async def test_driver_power_on_error(monkeypatch, mock_data):
124124
patch.object(root._api, "get_instance", **mock_data.get("get_instance", {"return_value": instance})),
125125
patch.object(root._api, "create_instance", **mock_data.get("create_instance", {"return_value": instance})),
126126
):
127-
power.off()
127+
await power.off()
128128

129129

130130
async def test_driver_power_off_ok(monkeypatch):
@@ -142,7 +142,7 @@ async def test_driver_power_off_ok(monkeypatch):
142142
patch.object(root._api, "set_instance_state", return_value=None),
143143
patch.object(root._api, "get_instance", side_effect=[instance, Instance(id=instance.id, state="off")]),
144144
):
145-
power.off()
145+
await power.off()
146146

147147

148148
@pytest.mark.parametrize(
@@ -172,4 +172,4 @@ async def test_driver_power_off_error(monkeypatch, mock_data):
172172
root._api, "destroy_instance", **mock_data.get("destroy_instance", {"return_value": instance})
173173
),
174174
):
175-
power.off()
175+
await power.off()

packages/jumpstarter-driver-corellium/pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ dependencies = [
1919
Corellium = "jumpstarter_driver_corellium.driver:Corellium"
2020

2121
[dependency-groups]
22-
dev = ["pytest>=8.3.2", "pytest-cov>=5.0.0", "trio>=0.28.0", "requests_mock"]
22+
dev = [
23+
"pytest>=8.3.2",
24+
"pytest-cov>=5.0.0",
25+
"trio>=0.28.0",
26+
"requests_mock",
27+
"pytest-aiohttp>=1.1.0",
28+
]
2329

2430
[tool.hatch.metadata.hooks.vcs.urls]
2531
Homepage = "https://jumpstarter.dev"

uv.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)