Feat/realtime validation json helpers and serialization tests s14 s15 #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 filetest_realtime.pywas created to centralize all Realtime test cases.A new
manage.pyfile 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__.pywas temporarily added to maintain compatibility with existing modules.The project configuration was updated by modifying
settings.pyto include the project root (gtfs-django/) insys.path, ensuring proper resolution of internal imports.After these changes,
test_realtime.pywas 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(), andget_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:
export_to_json()andexport_batch_to_json()to convertFeedMessageobjects into GTFS-Realtime-compliant JSON structures, covering the “JSON conversion utilities documented” criterion.FeedMessagemodel, theclean()method was added to enforce strictly increasing timestamps and to verify identifier consistency against the Schedule layer.to_json()method was incorporated intoFeedMessageto generate reusable JSON objects compatible with the exporter.Alertmodel was updated with a JSONField (informed_entity) to better align with the GTFS-Realtime specification.Results
Unit tests were executed successfully using Python’s
unittestrunner.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
.pbfile is parsed withgtfs_realtime_pb2.FeedMessage()and converted to JSON usingjson_format.MessageToJson()to verify correctness.Tests and binary generation were executed with:
python manage.py test tests