Skip to content

Commit cb56b30

Browse files
committed
feat(qaas): wip timezone
1 parent c4649ea commit cb56b30

File tree

5 files changed

+27
-57
lines changed

5 files changed

+27
-57
lines changed

requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ randomname>=0.2.1
44
httpx>=0.27.0
55
pytimeparse>=1.1.8
66
attrs>=22.2.0
7-
python-dateutil>=2.8.0
8-
pytz>=2024.1
9-
tzlocal>=5.3.1
7+
python-dateutil>=2.8.0

scaleway_qaas_client/v1alpha1/client.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@
127127
Response,
128128
)
129129

130-
from scaleway_qaas_client.v1alpha1.utils import get_local_iana_timezone, is_valid_iana
131-
132130
_DEFAULT_URL = "https://api.scaleway.com"
133131

134132

@@ -253,7 +251,6 @@ def create_session(
253251
booking_demand_started_at: Optional[datetime] = None,
254252
booking_demand_finished_at: Optional[datetime] = None,
255253
booking_demand_description: Optional[str] = None,
256-
booking_demand_time_zone: Optional[str] = None,
257254
) -> ScalewayQaasV1Alpha1Session:
258255
"""Create a session
259256
@@ -267,10 +264,9 @@ def create_session(
267264
max_duration (Union[None, Unset, str]): Maximum duration before the session ends. (in seconds) Example: 20m.
268265
deduplication_id (Union[None, Unset, str]): Deduplication ID of the session.
269266
model_id (Union[None, Unset, str]): Default computation model ID to be executed by job assigned to this session.
270-
booking_demand_started_at (Union[None, Unset, datetime.datetime]): Wished started time for an exclusive session over a QPU, only works if the platform is_bookable (RFC 3339 format) Example: 2022-03-22T12:34:56.123456Z.
271-
booking_demand_finished_at (Union[None, Unset, datetime.datetime]): Wished finished time for an exclusive session over a QPU, only works if the platform is_bookable (RFC 3339 format) Example: 2022-03-22T12:34:56.123456Z.
267+
booking_demand_started_at (Union[None, Unset, datetime.datetime]): Wished started UTC time for an exclusive session over a QPU, only works if the platform is_bookable (RFC 3339 format) Example: 2022-03-22T12:34:56.123456Z.
268+
booking_demand_finished_at (Union[None, Unset, datetime.datetime]): Wished finished UTC time for an exclusive session over a QPU, only works if the platform is_bookable (RFC 3339 format) Example: 2022-03-22T12:34:56.123456Z.
272269
booking_demand_description (Union[None, Unset, str]): User description of the booking
273-
booking_demand_time_zone (Union[None, Unset, str]): Time zone of the demanded booking (eg: Europe/Paris, America/New_York...)
274270
275271
Raises:
276272
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -309,25 +305,11 @@ def create_session(
309305
booking_demand = UNSET
310306

311307
if booking_demand_started_at and booking_demand_finished_at:
312-
booking_demand_started_at_timestamp = booking_demand_started_at.timestamp()
313-
booking_demand_finished_at_timestamp = (
314-
booking_demand_finished_at.timestamp()
315-
)
316-
317-
if booking_demand_time_zone is not None and not is_valid_iana(
318-
booking_demand_time_zone
319-
):
320-
raise Exception(
321-
f"create_session: invalid time zone {booking_demand_time_zone} as IANA format"
322-
)
323-
else:
324-
time_zone = get_local_iana_timezone()
325-
326308
booking_demand = CreateSessionBodyBookingDemand(
327-
started_at=booking_demand_started_at_timestamp,
328-
finished_at=booking_demand_finished_at_timestamp,
309+
started_at=booking_demand_started_at,
310+
finished_at=booking_demand_finished_at,
329311
description=booking_demand_description,
330-
time_zone=time_zone,
312+
time_zone="UTC",
331313
)
332314

333315
response = _create_session_sync(

scaleway_qaas_client/v1alpha1/utils.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pytest
22
pytest-dependency
33
pytest-progress
4-
pytest-httpx
4+
pytest-httpx
5+
pytz

tests/test_booking.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
import os
1515
import time
16+
import pytz
1617

1718
from datetime import datetime, timedelta, timezone
1819

@@ -21,6 +22,14 @@
2122
_TEST_PLATFORM_NAME = os.environ.get("TEST_PLATFORM_NAME", "aer_simulation_pop_c16m128")
2223

2324

25+
def _get_now_utc() -> datetime:
26+
return datetime.now(timezone.utc)
27+
28+
29+
def _get_now_paris() -> datetime:
30+
return datetime.now(pytz.timezone("Europe/Paris"))
31+
32+
2433
def _get_client() -> QaaSClient:
2534
client = QaaSClient(
2635
project_id=os.environ["SCALEWAY_PROJECT_ID"],
@@ -41,8 +50,8 @@ def test_create_and_cancel_booking():
4150
target_platform = platforms[0]
4251

4352
try:
44-
now = datetime.now(timezone.utc)
45-
booking_start = now + timedelta(seconds=15)
53+
now = _get_now_paris()
54+
booking_start = now + timedelta(seconds=16)
4655
booking_finish = booking_start + timedelta(seconds=20)
4756
booking_description = "my lovely booking"
4857

@@ -100,7 +109,7 @@ def test_create_overlaping_booking():
100109

101110
target_platform = platforms[0]
102111

103-
now = datetime.now(timezone.utc)
112+
now = _get_now_paris()
104113
booking_start = now + timedelta(days=1)
105114
booking_finish = booking_start + timedelta(hours=1)
106115
booking_description = "my overlaping booking"
@@ -127,7 +136,7 @@ def test_create_too_long_booking():
127136

128137
target_platform = platforms[0]
129138

130-
now = datetime.now(timezone.utc)
139+
now = _get_now_paris()
131140
booking_start = now + timedelta(minutes=1)
132141
booking_finish = booking_start + timedelta(hours=10)
133142
booking_description = "my too long booking"
@@ -152,7 +161,7 @@ def test_create_too_short_booking():
152161

153162
target_platform = platforms[0]
154163

155-
now = datetime.now(timezone.utc)
164+
now = _get_now_paris()
156165
booking_start = now + timedelta(minutes=1)
157166
booking_finish = booking_start + timedelta(seconds=10)
158167
booking_description = "my lovely booking"
@@ -177,7 +186,7 @@ def test_create_too_far_booking():
177186

178187
target_platform = platforms[0]
179188

180-
now = datetime.now(timezone.utc)
189+
now = _get_now_paris()
181190
booking_start = now + timedelta(days=30)
182191
booking_finish = booking_start + timedelta(hours=2)
183192
booking_description = "my lovely booking"
@@ -202,7 +211,7 @@ def test_create_too_close_booking():
202211

203212
target_platform = platforms[0]
204213

205-
now = datetime.now(timezone.utc)
214+
now = _get_now_paris()
206215
booking_start = now + timedelta(seconds=10)
207216
booking_finish = booking_start + timedelta(hours=2)
208217
booking_description = "my lovely booking"
@@ -227,7 +236,7 @@ def test_stop_too_close_booking():
227236

228237
target_platform = platforms[0]
229238

230-
now = datetime.now(timezone.utc)
239+
now = _get_now_paris()
231240
booking_start = now + timedelta(seconds=20)
232241
booking_finish = booking_start + timedelta(seconds=30)
233242
booking_description = "my lovely booking"
@@ -273,7 +282,7 @@ def test_cannot_start_not_booked_session_during_booked_session_is_running():
273282

274283
target_platform = platforms[0]
275284

276-
now = datetime.now(timezone.utc)
285+
now = _get_now_paris()
277286
booking_start = now + timedelta(seconds=20)
278287
booking_finish = booking_start + timedelta(seconds=20)
279288
booking_description = "my booking"
@@ -347,7 +356,7 @@ def test_not_booked_session_is_killed_when_booked_session_starts():
347356

348357
assert not_booked_session_2
349358

350-
now = datetime.now(timezone.utc)
359+
now = _get_now_paris()
351360
booking_start = now + timedelta(seconds=20)
352361
booking_finish = booking_start + timedelta(seconds=20)
353362
booking_description = "my booking"

0 commit comments

Comments
 (0)