|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from pytest_mock import MockerFixture |
| 8 | +from requests import Response |
| 9 | +from requests.exceptions import HTTPError |
8 | 10 |
|
9 | 11 | from graphdatascience.session.algorithm_category import AlgorithmCategory |
10 | 12 | from graphdatascience.session.aura_api import AuraApi |
@@ -102,6 +104,14 @@ def delete_instance(self, instance_id: str) -> InstanceSpecificDetails: |
102 | 104 | return self._instances.pop(instance_id) |
103 | 105 |
|
104 | 106 | def list_sessions(self, dbid: str) -> List[SessionDetails]: |
| 107 | + # mimic aura behaviour of paused instances not being in an orchestra |
| 108 | + db = self.list_instance(dbid) |
| 109 | + if db and db.status == "paused": |
| 110 | + response = Response() |
| 111 | + response.status_code = 404 |
| 112 | + response._content = b"database not found" |
| 113 | + raise HTTPError(request=None, response=response) |
| 114 | + |
105 | 115 | return [v for _, v in self._sessions.items() if v.instance_id == dbid] |
106 | 116 |
|
107 | 117 | def list_instances(self) -> List[InstanceDetails]: |
@@ -180,6 +190,35 @@ def test_list_session(aura_api: AuraApi) -> None: |
180 | 190 | assert sessions.list() == [SessionInfo.from_session_details(session)] |
181 | 191 |
|
182 | 192 |
|
| 193 | +def test_list_session_paused_instance(aura_api: AuraApi) -> None: |
| 194 | + db = aura_api.create_instance("test", SessionMemory.m_8GB.value, "aws", "leipzig-1") |
| 195 | + fake_aura_api = cast(FakeAuraApi, aura_api) |
| 196 | + |
| 197 | + fake_aura_api.id_counter += 1 |
| 198 | + paused_db = InstanceSpecificDetails( |
| 199 | + id="4242", |
| 200 | + status="paused", |
| 201 | + connection_url="foo.bar", |
| 202 | + memory=SessionMemory.m_16GB.value, |
| 203 | + type="", |
| 204 | + region="dresden", |
| 205 | + name="paused-db", |
| 206 | + tenant_id=fake_aura_api._tenant_id, |
| 207 | + cloud_provider="aws", |
| 208 | + ) |
| 209 | + fake_aura_api._instances[paused_db.id] = paused_db |
| 210 | + |
| 211 | + session = aura_api.create_session( |
| 212 | + name="gds-session-my-session-name", |
| 213 | + dbid=db.id, |
| 214 | + pwd="some_pwd", |
| 215 | + memory=SessionMemory.m_8GB.value, |
| 216 | + ) |
| 217 | + sessions = DedicatedSessions(aura_api) |
| 218 | + |
| 219 | + assert sessions.list() == [SessionInfo.from_session_details(session)] |
| 220 | + |
| 221 | + |
183 | 222 | def test_create_session(mocker: MockerFixture, aura_api: AuraApi) -> None: |
184 | 223 | _setup_db_instance(aura_api) |
185 | 224 |
|
|
0 commit comments