Skip to content

Conversation

@jloria2703
Copy link
Collaborator

Completion of Sub-issue #14 and Implementation Work on Sub-issue #15

Work continued on the unit tests for Sub-issue #14, which were originally embedded inside realtime.py.
Following Django conventions, the testing logic was moved into a dedicated tests/ directory, and a new file test_realtime.py was created to centralize all Realtime test cases.

A new manage.py file was introduced, enabling direct execution of tests through Django commands.
To resolve import-path conflicts during this migration, an additional tests/ directory containing only __init__.py was temporarily added to maintain compatibility with existing modules.

The project configuration was updated by modifying settings.py to include the project root (gtfs-django/) in sys.path, ensuring proper resolution of internal imports.
After these changes, test_realtime.py was successfully integrated into the final test structure, completing the environment setup required for GTFS-Realtime unit testing.

The functions get_vehicle_positions(), get_trip_updates(), and get_service_alerts() were rewritten to correctly download, decode, and store GTFS-Realtime feeds retrieved from providers configured in the database.


Sub-issue #15 — Timestamp/ID Validation and JSON Export Utilities

Several components were implemented to satisfy the validation and JSON export requirements:

  • RealTimeValidator was added to check timestamp monotonicity across consecutive messages, fulfilling the first acceptance criterion.
  • JSONExporter was implemented with export_to_json() and export_batch_to_json() to convert FeedMessage objects into GTFS-Realtime-compliant JSON structures, covering the “JSON conversion utilities documented” criterion.
  • In the FeedMessage model, the clean() method was added to enforce strictly increasing timestamps and to verify identifier consistency against the Schedule layer.
  • A new to_json() method was incorporated into FeedMessage to generate reusable JSON objects compatible with the exporter.
  • The Alert model was updated with a JSONField (informed_entity) to better align with the GTFS-Realtime specification.

Results

Unit tests were executed successfully using Python’s unittest runner.
A dedicated directory was created to store the generated protobuf binary samples.
Because these files are not directly human-readable, an additional decoding step was implemented: each .pb file is parsed with gtfs_realtime_pb2.FeedMessage() and converted to JSON using json_format.MessageToJson() to verify correctness.

Tests and binary generation were executed with:

python manage.py test tests

@jloria2703 jloria2703 self-assigned this Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants