Skip to content

Commit 4ad9920

Browse files
committed
fix: fixed tests for union_no_overlap
1 parent 6b08d43 commit 4ad9920

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

aw_client/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def _log_request_exception(e: req.RequestException):
3333
pass
3434

3535

36+
def _dt_is_tzaware(dt: datetime) -> bool:
37+
return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
38+
39+
3640
def always_raise_for_request_errors(f: Callable[..., req.Response]):
3741
@functools.wraps(f)
3842
def g(*args, **kwargs):
@@ -301,6 +305,14 @@ def query(
301305
params["name"] = name
302306
params["cache"] = int(cache)
303307

308+
# Check that datetimes have timezone information
309+
for start, stop in timeperiods:
310+
try:
311+
assert _dt_is_tzaware(start)
312+
assert _dt_is_tzaware(stop)
313+
except AssertionError:
314+
raise ValueError("start/stop needs to have a timezone set")
315+
304316
data = {
305317
"timeperiods": [
306318
"/".join([start.isoformat(), end.isoformat()])

tests/test_client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python3
22
import time
3-
43
from random import random
54
from datetime import datetime, timedelta, timezone
65
from requests.exceptions import HTTPError
76

7+
import pytest
8+
89
from aw_core.models import Event
910
from aw_client import ActivityWatchClient
1011

@@ -66,11 +67,19 @@ def test_full():
6667
assert eventcount == len(events)
6768

6869
result = client.query(
69-
f"RETURN = query_bucket('{bucket_name}');",
70+
f'RETURN = query_bucket("{bucket_name}");',
7071
timeperiods=[(now - timedelta(hours=1), now + timedelta(hours=1))],
7172
)
7273
assert len(result) == 1
7374
assert len(result[0]) == 3
7475

76+
# Test exception raising
77+
with pytest.raises(ValueError):
78+
# timeperiod end time does not have a timezone set
79+
result = client.query(
80+
f'RETURN = query_bucket("{bucket_name}");',
81+
timeperiods=[(now - timedelta(hours=1), datetime.now())],
82+
)
83+
7584
# Delete bucket
7685
client.delete_bucket(bucket_name)

0 commit comments

Comments
 (0)