Skip to content
Merged
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 examples/basic_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def main() -> None:
flight_summary = client.flight_summary.get_light(flights=["KL1316"], flight_datetime_from=datetime(2025, 5, 13, 12, 0, 0), flight_datetime_to=datetime(2025, 5, 14, 17, 10, 0))
if flight_summary.data:
print(flight_summary.data[0].fr24_id)
print(client.flight_summary.get_full(operating_as=["FDX"],flight_datetime_from=datetime(2026, 1, 15, 15, 0, 0),flight_datetime_to=datetime(2026, 1, 15, 15, 5, 0),categories=[FlightCategory.CARGO]))
print(client.flight_summary.get_full(operating_as=["FDX"],flight_datetime_from=datetime(2026, 1, 15, 15, 0, 0, tzinfo=timezone.utc),flight_datetime_to=datetime(2026, 1, 15, 15, 5, 0),categories=[FlightCategory.CARGO]))
print(client.live.flight_positions.get_light(flights=["SK2752"]))
print(client.live.flight_positions.get_light(bounds=Boundary(north=55.6, south=55.5, west=12.5, east=12.6)))
print(client.live.flight_positions.get_full(bounds="55.6,55.5,12.5,12.6"))
Expand Down
6 changes: 5 additions & 1 deletion src/fr24sdk/resources/flight_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import warnings
from typing import Optional, Any, Annotated, Union
from datetime import datetime
from datetime import datetime, timezone
from pydantic import BaseModel, model_serializer, StringConstraints, Field

from ..transport import HttpTransport
Expand Down Expand Up @@ -69,6 +69,10 @@ def _to_query_dict(self) -> dict[str, Any]:
continue
if isinstance(value, list):
query[key] = ",".join(map(str, value))
elif isinstance(value, datetime):
if value.tzinfo is not None and value.utcoffset() is not None:
value = value.astimezone(timezone.utc).replace(tzinfo=None)
query[key] = str(value)
else:
query[key] = str(value)
return query
Expand Down
24 changes: 17 additions & 7 deletions tests/unit/test_flight_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# SPDX-License-Identifier: MIT
"""Unit tests for the flight_summary module."""

import pytest
from unittest.mock import Mock, MagicMock
from datetime import datetime, timezone
from datetime import datetime, timedelta, timezone

import pytest

from fr24sdk.resources.flight_summary import FlightSummaryResource, _FlightSummaryParams
from fr24sdk.models.flight import (
Expand Down Expand Up @@ -40,7 +41,9 @@ class TestFlightSummaryParams:
def test_serialize_params(self):
"""Test parameters are correctly serialized for API requests."""
# Test with various parameter types
test_datetime = datetime(2023, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
test_datetime = datetime(
2023, 1, 1, 12, 0, 0, tzinfo=timezone(timedelta(hours=2))
)
params = _FlightSummaryParams(
flight_datetime_from=test_datetime,
flight_datetime_to=test_datetime,
Expand All @@ -52,8 +55,12 @@ def test_serialize_params(self):
serialized = params._to_query_dict()

# Check serialization results
assert serialized["flight_datetime_from"] == str(test_datetime)
assert serialized["flight_datetime_to"] == str(test_datetime)
assert serialized["flight_datetime_from"] == str(
test_datetime.astimezone(timezone.utc).replace(tzinfo=None)
)
assert serialized["flight_datetime_to"] == str(
test_datetime.astimezone(timezone.utc).replace(tzinfo=None)
)
assert serialized["flights"] == "BA1234,LH5678"
assert serialized["callsigns"] == "BAW123"
assert serialized["aircraft"] == "B738,A320"
Expand Down Expand Up @@ -145,8 +152,9 @@ def test_get_light_success_with_datetime_range(
mock_transport.request.return_value = mock_response

# Call with datetime parameters
from_dt = datetime(2023, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
to_dt = datetime(2023, 1, 1, 23, 59, 59, tzinfo=timezone.utc)
offset = timezone(timedelta(hours=2))
from_dt = datetime(2023, 1, 1, 0, 0, 0, tzinfo=offset)
to_dt = datetime(2023, 1, 1, 23, 59, 59, tzinfo=offset)

result = flight_summary.get_light(
flight_datetime_from=from_dt, flight_datetime_to=to_dt, airports=["EGLL"]
Expand All @@ -159,6 +167,8 @@ def test_get_light_success_with_datetime_range(
args, kwargs = mock_transport.request.call_args
assert "flight_datetime_from" in kwargs["params"]
assert "flight_datetime_to" in kwargs["params"]
assert kwargs["params"]["flight_datetime_from"] == "2022-12-31 22:00:00"
assert kwargs["params"]["flight_datetime_to"] == "2023-01-01 21:59:59"
assert kwargs["params"]["airports"] == "EGLL"

def test_get_full_success(self, flight_summary, mock_transport):
Expand Down
Loading