Skip to content

Commit fd76c5c

Browse files
Merge pull request #689 from FlorentinD/session-user-creator-id
Return tenant and user in session endpoints
2 parents d42480b + a276aac commit fd76c5c

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

graphdatascience/session/aura_api_responses.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SessionDetails:
2323
created_at: datetime
2424
expiry_date: Optional[datetime]
2525
ttl: Optional[timedelta]
26+
user_id: str
27+
tenant_id: str
2628

2729
@classmethod
2830
def fromJson(cls, json: Dict[str, Any]) -> SessionDetails:
@@ -38,7 +40,9 @@ def fromJson(cls, json: Dict[str, Any]) -> SessionDetails:
3840
host=json["host"],
3941
expiry_date=TimeParser.fromisoformat(expiry_date) if expiry_date else None,
4042
created_at=TimeParser.fromisoformat(json["created_at"]),
41-
ttl=Timedelta(ttl).to_pytimedelta() if ttl else None, # datetime has no support for parsing timedetla
43+
ttl=Timedelta(ttl).to_pytimedelta() if ttl else None, # datetime has no support for parsing timedelta
44+
tenant_id=json["tenant_id"],
45+
user_id=json["user_id"],
4246
)
4347

4448
def bolt_connection_url(self) -> str:

graphdatascience/tests/unit/test_aura_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def test_create_session(requests_mock: Mocker) -> None:
3535
"created_at": "1970-01-01T00:00:00Z",
3636
"host": "1.2.3.4",
3737
"memory": "4Gi",
38+
"tenant_id": "tenant-0",
39+
"user_id": "user-0",
3840
},
3941
)
4042

@@ -50,6 +52,8 @@ def test_create_session(requests_mock: Mocker) -> None:
5052
memory=SessionMemory.m_4GB.value,
5153
expiry_date=None,
5254
ttl=None,
55+
tenant_id="tenant-0",
56+
user_id="user-0",
5357
)
5458

5559

@@ -70,6 +74,8 @@ def test_list_session(requests_mock: Mocker) -> None:
7074
"host": "1.2.3.4",
7175
"memory": "4Gi",
7276
"expiry_date": "1977-01-01T00:00:00Z",
77+
"tenant_id": "tenant-0",
78+
"user_id": "user-0",
7379
},
7480
)
7581

@@ -85,6 +91,8 @@ def test_list_session(requests_mock: Mocker) -> None:
8591
memory=SessionMemory.m_4GB.value,
8692
expiry_date=TimeParser.fromisoformat("1977-01-01T00:00:00Z"),
8793
ttl=None,
94+
tenant_id="tenant-0",
95+
user_id="user-0",
8896
)
8997

9098

@@ -104,6 +112,8 @@ def test_list_sessions(requests_mock: Mocker) -> None:
104112
"host": "1.2.3.4",
105113
"memory": "4Gi",
106114
"expiry_date": "1977-01-01T00:00:00Z",
115+
"tenant_id": "tenant-1",
116+
"user_id": "user-1",
107117
},
108118
{
109119
"id": "id1",
@@ -113,6 +123,8 @@ def test_list_sessions(requests_mock: Mocker) -> None:
113123
"created_at": "2012-01-01T00:00:00Z",
114124
"memory": "8Gi",
115125
"host": "foo.bar",
126+
"tenant_id": "tenant-2",
127+
"user_id": "user-2",
116128
},
117129
],
118130
)
@@ -129,6 +141,8 @@ def test_list_sessions(requests_mock: Mocker) -> None:
129141
memory=SessionMemory.m_4GB.value,
130142
expiry_date=TimeParser.fromisoformat("1977-01-01T00:00:00Z"),
131143
ttl=None,
144+
tenant_id="tenant-1",
145+
user_id="user-1",
132146
)
133147

134148
expected2 = SessionDetails(
@@ -141,6 +155,8 @@ def test_list_sessions(requests_mock: Mocker) -> None:
141155
host="foo.bar",
142156
expiry_date=None,
143157
ttl=None,
158+
tenant_id="tenant-2",
159+
user_id="user-2",
144160
)
145161

146162
assert result == [expected1, expected2]
@@ -203,6 +219,8 @@ def test_dont_wait_forever_for_session(requests_mock: Mocker, caplog: LogCapture
203219
"host": "foo.bar",
204220
"memory": "4Gi",
205221
"expiry_date": "1977-01-01T00:00:00Z",
222+
"tenant_id": "tenant-1",
223+
"user_id": "user-1",
206224
},
207225
)
208226

@@ -230,6 +248,8 @@ def test_wait_for_session_running(requests_mock: Mocker) -> None:
230248
"host": "foo.bar",
231249
"memory": "4Gi",
232250
"expiry_date": "1977-01-01T00:00:00Z",
251+
"tenant_id": "tenant-1",
252+
"user_id": "user-1",
233253
},
234254
)
235255

@@ -671,6 +691,8 @@ def test_parse_session_info() -> None:
671691
"created_at": "2021-01-01T00:00:00Z",
672692
"host": "a.b",
673693
"ttl": "1d8h1m2s",
694+
"tenant_id": "tenant-1",
695+
"user_id": "user-1",
674696
}
675697
session_info = SessionDetails.fromJson(session_details)
676698

@@ -684,6 +706,8 @@ def test_parse_session_info() -> None:
684706
expiry_date=datetime(2022, 1, 1, 0, 0, 0, tzinfo=timezone.utc),
685707
created_at=datetime(2021, 1, 1, 0, 0, 0, tzinfo=timezone.utc),
686708
ttl=timedelta(days=1, hours=8, minutes=1, seconds=2),
709+
tenant_id="tenant-1",
710+
user_id="user-1",
687711
)
688712

689713

@@ -696,6 +720,8 @@ def test_parse_session_info_without_optionals() -> None:
696720
"status": "running",
697721
"host": "a.b",
698722
"created_at": "2021-01-01T00:00:00Z",
723+
"tenant_id": "tenant-1",
724+
"user_id": "user-1",
699725
}
700726
session_info = SessionDetails.fromJson(session_details)
701727

@@ -709,4 +735,6 @@ def test_parse_session_info_without_optionals() -> None:
709735
expiry_date=None,
710736
ttl=None,
711737
created_at=datetime(2021, 1, 1, 0, 0, 0, tzinfo=timezone.utc),
738+
tenant_id="tenant-1",
739+
user_id="user-1",
712740
)

graphdatascience/tests/unit/test_dedicated_sessions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def create_session(self, name: str, dbid: str, pwd: str, memory: SessionMemoryVa
5454
host="foo.bar",
5555
expiry_date=None,
5656
ttl=None,
57+
user_id="user-1",
58+
tenant_id=self._tenant_id,
5759
)
5860

5961
self.id_counter += 1
@@ -302,6 +304,8 @@ def test_get_or_create_expired_session(aura_api: AuraApi) -> None:
302304
host="foo.bar",
303305
expiry_date=None,
304306
ttl=None,
307+
tenant_id="tenant-0",
308+
user_id="user-0",
305309
)
306310
)
307311

@@ -327,6 +331,8 @@ def test_get_or_create_soon_expired_session(aura_api: AuraApi) -> None:
327331
host="foo.bar",
328332
expiry_date=datetime.now(tz=timezone.utc) - timedelta(hours=23),
329333
ttl=None,
334+
tenant_id="tenant-0",
335+
user_id="user-0",
330336
)
331337
)
332338

@@ -350,6 +356,8 @@ def test_get_or_create_with_different_memory_config(aura_api: AuraApi) -> None:
350356
host="foo.bar",
351357
expiry_date=None,
352358
ttl=None,
359+
tenant_id="tenant-0",
360+
user_id="user-0",
353361
)
354362
)
355363

0 commit comments

Comments
 (0)