Skip to content

Commit 4821c98

Browse files
authored
Merge pull request #699 from FlorentinD/gds-api-resp-data-wrapped
Expect data key in Aura API response
2 parents bd36cae + a35b45d commit 4821c98

File tree

2 files changed

+77
-67
lines changed

2 files changed

+77
-67
lines changed

graphdatascience/session/aura_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def create_session(self, name: str, dbid: str, pwd: str, memory: SessionMemoryVa
6969

7070
self._check_resp(response)
7171

72-
return SessionDetails.fromJson(response.json())
72+
return SessionDetails.fromJson(response.json()["data"])
7373

7474
def list_session(self, session_id: str, dbid: str) -> Optional[SessionDetails]:
7575
response = self._request_session.get(
@@ -81,7 +81,7 @@ def list_session(self, session_id: str, dbid: str) -> Optional[SessionDetails]:
8181

8282
self._check_resp(response)
8383

84-
return SessionDetails.fromJson(response.json())
84+
return SessionDetails.fromJson(response.json()["data"])
8585

8686
def list_sessions(self, dbid: str) -> List[SessionDetails]:
8787
response = self._request_session.get(
@@ -90,7 +90,7 @@ def list_sessions(self, dbid: str) -> List[SessionDetails]:
9090

9191
self._check_resp(response)
9292

93-
return [SessionDetails.fromJson(s) for s in response.json()]
93+
return [SessionDetails.fromJson(s) for s in response.json()["data"]]
9494

9595
def wait_for_session_running(
9696
self,

graphdatascience/tests/unit/test_aura_api.py

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ def test_create_session(requests_mock: Mocker) -> None:
3535
requests_mock.post(
3636
"https://api.neo4j.io/v1beta5/data-science/sessions",
3737
json={
38-
"id": "id0",
39-
"name": "name-0",
40-
"status": "Creating",
41-
"instance_id": "dbid-1",
42-
"created_at": "1970-01-01T00:00:00Z",
43-
"host": "1.2.3.4",
44-
"memory": "4Gi",
45-
"tenant_id": "tenant-0",
46-
"user_id": "user-0",
38+
"data": {
39+
"id": "id0",
40+
"name": "name-0",
41+
"status": "Creating",
42+
"instance_id": "dbid-1",
43+
"created_at": "1970-01-01T00:00:00Z",
44+
"host": "1.2.3.4",
45+
"memory": "4Gi",
46+
"tenant_id": "tenant-0",
47+
"user_id": "user-0",
48+
}
4749
},
4850
)
4951

@@ -73,16 +75,18 @@ def test_list_session(requests_mock: Mocker) -> None:
7375
requests_mock.get(
7476
"https://api.neo4j.io/v1beta5/data-science/sessions/id0?instanceId=dbid-1",
7577
json={
76-
"id": "id0",
77-
"name": "name-0",
78-
"status": "Ready",
79-
"instance_id": "dbid-1",
80-
"created_at": "1970-01-01T00:00:00Z",
81-
"host": "1.2.3.4",
82-
"memory": "4Gi",
83-
"expiry_date": "1977-01-01T00:00:00Z",
84-
"tenant_id": "tenant-0",
85-
"user_id": "user-0",
78+
"data": {
79+
"id": "id0",
80+
"name": "name-0",
81+
"status": "Ready",
82+
"instance_id": "dbid-1",
83+
"created_at": "1970-01-01T00:00:00Z",
84+
"host": "1.2.3.4",
85+
"memory": "4Gi",
86+
"expiry_date": "1977-01-01T00:00:00Z",
87+
"tenant_id": "tenant-0",
88+
"user_id": "user-0",
89+
}
8690
},
8791
)
8892

@@ -109,31 +113,33 @@ def test_list_sessions(requests_mock: Mocker) -> None:
109113

110114
requests_mock.get(
111115
"https://api.neo4j.io/v1beta5/data-science/sessions?instanceId=dbid-1",
112-
json=[
113-
{
114-
"id": "id0",
115-
"name": "name-0",
116-
"status": "Ready",
117-
"instance_id": "dbid-1",
118-
"created_at": "1970-01-01T00:00:00Z",
119-
"host": "1.2.3.4",
120-
"memory": "4Gi",
121-
"expiry_date": "1977-01-01T00:00:00Z",
122-
"tenant_id": "tenant-1",
123-
"user_id": "user-1",
124-
},
125-
{
126-
"id": "id1",
127-
"name": "name-2",
128-
"status": "Creating",
129-
"instance_id": "dbid-3",
130-
"created_at": "2012-01-01T00:00:00Z",
131-
"memory": "8Gi",
132-
"host": "foo.bar",
133-
"tenant_id": "tenant-2",
134-
"user_id": "user-2",
135-
},
136-
],
116+
json={
117+
"data": [
118+
{
119+
"id": "id0",
120+
"name": "name-0",
121+
"status": "Ready",
122+
"instance_id": "dbid-1",
123+
"created_at": "1970-01-01T00:00:00Z",
124+
"host": "1.2.3.4",
125+
"memory": "4Gi",
126+
"expiry_date": "1977-01-01T00:00:00Z",
127+
"tenant_id": "tenant-1",
128+
"user_id": "user-1",
129+
},
130+
{
131+
"id": "id1",
132+
"name": "name-2",
133+
"status": "Creating",
134+
"instance_id": "dbid-3",
135+
"created_at": "2012-01-01T00:00:00Z",
136+
"memory": "8Gi",
137+
"host": "foo.bar",
138+
"tenant_id": "tenant-2",
139+
"user_id": "user-2",
140+
},
141+
]
142+
},
137143
)
138144

139145
result = api.list_sessions("dbid-1")
@@ -218,16 +224,18 @@ def test_dont_wait_forever_for_session(requests_mock: Mocker, caplog: LogCapture
218224
requests_mock.get(
219225
"https://api.neo4j.io/v1beta5/data-science/sessions/id0?instanceId=dbid-1",
220226
json={
221-
"id": "id0",
222-
"name": "name-0",
223-
"status": "Creating",
224-
"instance_id": "dbid-1",
225-
"created_at": "1970-01-01T00:00:00Z",
226-
"host": "foo.bar",
227-
"memory": "4Gi",
228-
"expiry_date": "1977-01-01T00:00:00Z",
229-
"tenant_id": "tenant-1",
230-
"user_id": "user-1",
227+
"data": {
228+
"id": "id0",
229+
"name": "name-0",
230+
"status": "Creating",
231+
"instance_id": "dbid-1",
232+
"created_at": "1970-01-01T00:00:00Z",
233+
"host": "foo.bar",
234+
"memory": "4Gi",
235+
"expiry_date": "1977-01-01T00:00:00Z",
236+
"tenant_id": "tenant-1",
237+
"user_id": "user-1",
238+
}
231239
},
232240
)
233241

@@ -247,16 +255,18 @@ def test_wait_for_session_running(requests_mock: Mocker) -> None:
247255
requests_mock.get(
248256
"https://api.neo4j.io/v1beta5/data-science/sessions/id0?instanceId=db2",
249257
json={
250-
"id": "id0",
251-
"name": "name-0",
252-
"status": "Ready",
253-
"instance_id": "dbid-1",
254-
"created_at": "1970-01-01T00:00:00Z",
255-
"host": "foo.bar",
256-
"memory": "4Gi",
257-
"expiry_date": "1977-01-01T00:00:00Z",
258-
"tenant_id": "tenant-1",
259-
"user_id": "user-1",
258+
"data": {
259+
"id": "id0",
260+
"name": "name-0",
261+
"status": "Ready",
262+
"instance_id": "dbid-1",
263+
"created_at": "1970-01-01T00:00:00Z",
264+
"host": "foo.bar",
265+
"memory": "4Gi",
266+
"expiry_date": "1977-01-01T00:00:00Z",
267+
"tenant_id": "tenant-1",
268+
"user_id": "user-1",
269+
}
260270
},
261271
)
262272

0 commit comments

Comments
 (0)