-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from LACMTA:2023-api-optimization
Refactor endpoint and load testing scripts
- Loading branch information
Showing
4 changed files
with
44 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import sys | ||
|
||
def run_tests(env): | ||
if env == '--local': | ||
os.system('ENV=local pytest test_endpoints.py') | ||
elif env == '--dev': | ||
os.system('ENV=dev pytest test_endpoints.py') | ||
else: | ||
raise ValueError("Invalid environment. Choose --local or --dev") | ||
|
||
if len(sys.argv) != 2: | ||
print("Usage: python run_tests.py [--local|--dev]") | ||
else: | ||
env = sys.argv[1] | ||
run_tests(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import os | ||
import requests | ||
import pytest | ||
# from simplified_models import TripUpdates, VehiclePositions | ||
|
||
# agency_ids = ["LACMTA", "LACMTA_Rail"] | ||
# trip_update_fields = [f for f in dir(TripUpdates) if not f.startswith('__') and not callable(getattr(TripUpdates, f))] | ||
# vehicle_position_fields = [f for f in dir(VehiclePositions) if not f.startswith('__') and not callable(getattr(VehiclePositions, f))] | ||
agency_ids = ["LACMTA", "LACMTA_Rail"] # replace with your actual agency IDs | ||
# Get the environment variable | ||
env = os.getenv('ENV') | ||
|
||
# Set the URL based on the environment variable | ||
if env == 'local': | ||
url = 'http://localhost:80' | ||
elif env == 'dev': | ||
url = 'https://dev-metro-api-v2.ofhq3vd1r7une.us-west-2.cs.amazonlightsail.com/' | ||
else: | ||
raise ValueError("Invalid environment. Set ENV environment variable to 'local' or 'dev'") | ||
|
||
agency_ids = ["LACMTA", "LACMTA_Rail"] | ||
|
||
@pytest.mark.parametrize("agency_id", agency_ids) | ||
def test_get_all_trip_updates(agency_id): | ||
response = requests.get(f"http://localhost:80/{agency_id}/trip_updates") | ||
response = requests.get(f"{url}/{agency_id}/trip_updates") | ||
assert response.status_code == 200 | ||
|
||
# @pytest.mark.parametrize("agency_id,field", [(a, f) for a in agency_ids for f in trip_update_fields]) | ||
# def test_get_list_of_trip_update_field_values(agency_id, field): | ||
# response = requests.get(f"http://localhost:80/{agency_id}/trip_updates/{field}") | ||
# assert response.status_code == 200 | ||
|
||
@pytest.mark.parametrize("agency_id", agency_ids) | ||
def test_get_all_vehicle_positions(agency_id): | ||
response = requests.get(f"http://localhost:80/{agency_id}/vehicle_positions") | ||
assert response.status_code == 200 | ||
|
||
# @pytest.mark.parametrize("agency_id,field", [(a, f) for a in agency_ids for f in vehicle_position_fields]) | ||
# def test_get_list_of_vehicle_position_field_values(agency_id, field): | ||
# response = requests.get(f"http://localhost:80/{agency_id}/vehicle_positions/{field}") | ||
# assert response.status_code == 200 | ||
response = requests.get(f"{url}/{agency_id}/vehicle_positions") | ||
assert response.status_code == 200 |