Skip to content

Commit 424ec9d

Browse files
committed
chore: Integration test for timezone awareness
1 parent aa8432e commit 424ec9d

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

tests/test_server.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from urllib.parse import quote_plus
44

55
import pytest
6-
from datetime import datetime
6+
from datetime import datetime, timedelta
77
from PIL import Image
88
from plexapi.exceptions import BadRequest, NotFound
99
from plexapi.server import PlexServer
10-
from plexapi.utils import download
10+
from plexapi.utils import download, setDatetimeTimezone, DATETIME_TIMEZONE
1111
from requests import Session
1212

1313
from . import conftest as utils
@@ -32,6 +32,32 @@ def test_server_attr(plex, account):
3232
assert len(plex.version) >= 5
3333

3434

35+
def test_server_updatedAt_timezone(plex):
36+
original = DATETIME_TIMEZONE
37+
try:
38+
# no timezone configured, should be naive
39+
setDatetimeTimezone(False)
40+
dt_naive = plex.updatedAt
41+
assert dt_naive.tzinfo is None
42+
43+
# local timezone configured, should be aware
44+
setDatetimeTimezone(True)
45+
dt_local = plex.updatedAt
46+
assert dt_local.tzinfo is not None
47+
48+
# explicit IANA zones. Check that the offset is correct too
49+
setDatetimeTimezone("UTC")
50+
dt: datetime = plex.updatedAt
51+
assert dt.tzinfo is not None
52+
assert dt.tzinfo.utcoffset(dt) == timedelta(0)
53+
setDatetimeTimezone("Asia/Dubai")
54+
dt: datetime = plex.updatedAt
55+
assert dt.tzinfo is not None
56+
assert dt.tzinfo.utcoffset(dt) == timedelta(hours=4)
57+
finally: # Restore for other tests
58+
setDatetimeTimezone(original)
59+
60+
3561
def test_server_alert_listener(plex, movies):
3662
try:
3763
messages = []

0 commit comments

Comments
 (0)