Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ably/pubsub/request/paginatedresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def format_time_param(t):
try:
return f'{calendar.timegm(t.utctimetuple()) * 1000}'
return f'{calendar.timegm(t.utctimetuple()) * 1000 + t.microsecond // 1000}'
except Exception:
return str(t)

Expand Down
16 changes: 14 additions & 2 deletions test/unit/paginatedresult_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Unit tests for the headers of an HttpPaginatedResponse.
"""Unit tests for paginated requests and responses.

Tests cover:
- HP8: headers as a read-only mapping, looked up by name case-insensitively
- datetime start/end bounds are sent as milliseconds since the epoch
"""

from datetime import datetime, timedelta, timezone

import httpx
import pytest

from ably.pubsub.request.paginatedresult import ResponseHeaders
from ably.pubsub.request.paginatedresult import ResponseHeaders, format_params


def test_headers_look_up_case_insensitively():
Expand Down Expand Up @@ -40,3 +43,12 @@ def test_headers_are_read_only():
headers['X-One'] = '2'
with pytest.raises(TypeError):
del headers['X-One']


@pytest.mark.parametrize('value', [
datetime(2024, 1, 1, 12, 0, 0, 999000, tzinfo=timezone.utc),
datetime(2024, 1, 1, 14, 0, 0, 999000, tzinfo=timezone(timedelta(hours=2))),
datetime(2024, 1, 1, 12, 0, 0, 999999),
])
def test_datetime_bounds_keep_milliseconds(value):
assert format_params(start=value, end=value) == '?start=1704110400999&end=1704110400999'
Loading