Service to Validate the GTFS flex file that is uploaded. At the moment, the service does the following:
-
- Listens to the topic which is mentioned in
.envfile for any new message (that is triggered when a file is uploaded), exampleUPLOAD_TOPIC=gtfs-flex-upload
- Listens to the topic which is mentioned in
- Consumes the message and perform following checks -
- Download the file locally
- File location is in the message
data.meta.file_upload_path, reference see this file msg-gtfs-flex-upload.json - Uses
tdei-gtfs-csv-validatorto validate the file - Added the
isValidandvalidationMessagekeys to the original message
- Publishes the result to the topic mentioned in
.envfile, exampleVALIDATION_TOPIC=gtfs-flex-validation
The project is built on Python with FastAPI framework. All the regular nuances for a Python project are valid for this.
| Software | Version |
|---|---|
| Python | 3.10.x |
- Connecting this to cloud will need the following in the
.envfile
REQUEST_TOPIC=xxxx
RESPONSE_TOPIC=xxxx
REQUEST_SUBSCRIPTION=xxxx
QUEUECONNECTION=xxxx
STORAGECONNECTION=xxxx
MAX_CONCURRENT_MESSAGES=xxThe application connect with the STORAGECONNECTION string provided in .env file and validates downloaded zipfile using tdei-gtfs-csv-validator package.
QUEUECONNECTION is not being used in this application but this is the main requirement for python-ms-core package
MAX_CONCURRENT_MESSAGES is the maximum number of concurrent messages that the service can handle. If not provided, defaults to 1
Follow the steps to install the node packages required for both building and running the application.
-
Setup virtual environment
python3.10 -m venv .venv source .venv/bin/activate -
Install the dependencies. Run the following command in terminal on the same directory as
requirements.txt# Installing requirements pip install -r requirements.txtNOTE: if you have problems building on a Mac, e.g. with uamqb, see here: Azure/azure-uamqp-python#386
- The http server by default starts with
8000port - Run server
uvicorn src.main:app --reload - By default
getcall onlocalhost:8000/healthgives a sample response - Other routes include a
pingwith get and post. Makegetorpostrequest tohttp://localhost:8000/health/ping - Once the server starts, it will start to listening the subscriber(
UPLOAD_SUBSCRIPTIONshould be in env file)
Make sure you have setup the project properly before running the tests, see above for How to Setup and Build.
- Add the new set of test inside
tests/test_harness/tests.jsonfile like -{ "Name": "Test Name", "Input_file": "test_files/flex_test_case1.json", // Input file path which you want to provide to the test "Result": true/false // Defining the test output } - Test Harness would require the valid
.envfile. - To run the test harness
python tests/test_harness/run_tests.py
.envfile is not required for Unit test cases.- To run the unit test cases
python test_report.py- Above command will run all test cases and generate the html report, in
reportsfolder at the root level.
- To run the coverage
coverage run --source=src -m unittest discover -s tests/unit_tests- Above command will run all the unit test cases.
- To generate the coverage report in console
coverage report- Above command will generate the code coverage report in terminal.
- To generate the coverage report in html.
coverage html- Above command will generate the html report, and generated html would be in
htmlcovdirectory at the root level.
- NOTE : To run the
htmlorreportcoverage, 3.i) command is mandatory
.envfile is required for Unit test cases.- To run the integration test cases, run the below command
python test_integration.py- Above command will run all integration test cases and generate the html report, in
reportsfolder at the root level.
This micro service deals with two topics/queues.
- upload queue from gtfs-flex-upload
- validation queue from gtfs-flex-validation
graph LR;
A(gtfs-flex-upload)-->B[gtfs-flex-validation-service];
B-->C(gtfs-flex-validation)
{
"messageId": "c8c76e89f30944d2b2abd2491bd95337",
"messageType": "workflow_identifier",
"data": {
"file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/gtfsflex/tests/success_1_all_attrs.zip",
"user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab",
"tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb"
}
}{
"messageId": "c8c76e89f30944d2b2abd2491bd95337",
"messageType": "workflow_identifier",
"data": {
"file_upload_path": "https://tdeisamplestorage.blob.core.windows.net/osw/test_upload/valid.zip",
"user_id": "c59d29b6-a063-4249-943f-d320d15ac9ab",
"tdei_project_group_id": "0b41ebc5-350c-42d3-90af-3af4ad3628fb",
"success": true,
"message": ""
}
}