Skip to content

Commit 7af22a0

Browse files
committed
Increased coverage of export_csv
1 parent dc528eb commit 7af22a0

File tree

4 files changed

+57
-18
lines changed

4 files changed

+57
-18
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[run]
2+
omit =
3+
*/test*/*
4+
*/database_gen/*
5+
*/dataset_service/*
6+
*/helpers/*
7+
*/shared/*
8+
9+
[report]
10+
exclude_lines =
11+
if __name__ == .__main__.:

functions-python/export_csv/src/main.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,11 @@ def get_gtfs_rt_feed_csv_data(feed: Gtfsrealtimefeed):
312312
return data
313313

314314

315-
def main():
316-
global csv_file_path
315+
if __name__ == "__main__":
317316
parser = argparse.ArgumentParser(description="Export DB feed contents to csv.")
318317
parser.add_argument(
319318
"--outpath", help="Path to the output csv file. Default is ./output.csv"
320319
)
321320
args = parser.parse_args()
322321
csv_file_path = args.outpath if args.outpath else csv_default_file_path
323322
export_csv()
324-
325-
326-
if __name__ == "__main__":
327-
main()

functions-python/export_csv/tests/conftest.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
from geoalchemy2 import WKTElement
2121

22-
from shared.database_gen.sqlacodegen_models import Validationreport, Feature
22+
from shared.database_gen.sqlacodegen_models import (
23+
Validationreport,
24+
Feature,
25+
Redirectingid,
26+
)
2327
from shared.database_gen.sqlacodegen_models import (
2428
Gtfsfeed,
2529
Gtfsrealtimefeed,
@@ -45,23 +49,51 @@ def populate_database():
4549
clean_testing_db()
4650
session = get_testing_session()
4751
fake = Faker()
52+
53+
feeds = []
54+
# We create 3 feeds. The first one is active. The third one is inactive and redirected to the first one.
55+
# The second one is active but not redirected.
56+
# First fill the generic paramaters
4857
for i in range(3):
4958
feed = Gtfsfeed(
50-
id=fake.uuid4(),
5159
data_type="gtfs",
5260
feed_name=f"gtfs-{i} Some fake name",
5361
note=f"gtfs-{i} Some fake note",
5462
producer_url=f"https://gtfs-{i}_some_fake_producer_url",
55-
authentication_type="0" if (i in [0, 1, 2]) else "1",
5663
authentication_info_url=None,
5764
api_key_parameter_name=None,
5865
license_url=f"https://gtfs-{i}_some_fake_license_url",
5966
stable_id=f"gtfs-{i}",
60-
status="active",
61-
# status="active" if (i in [0, 1]) else "inactive",
6267
feed_contact_email=f"gtfs-{i}[email protected]",
6368
provider=f"gtfs-{i} Some fake company",
6469
)
70+
feeds.append(feed)
71+
72+
# Then fill the specific parameters for each feed
73+
target_feed = feeds[0]
74+
target_feed.id = "e3155a30-81d8-40bb-9e10-013a60436d86" # Just an invented uuid
75+
target_feed.authentication_type = "0"
76+
target_feed.status = "active"
77+
78+
source_feed = feeds[2]
79+
source_feed.id = "6e7c5f17-537a-439a-bf99-9c37f1f01030"
80+
source_feed.authentication_type = "0"
81+
source_feed.status = "inactive"
82+
source_feed.redirectingids = [
83+
Redirectingid(
84+
source_id=source_feed.id,
85+
target_id=target_feed.id,
86+
redirect_comment="Some redirect comment",
87+
target=target_feed,
88+
)
89+
]
90+
91+
feed = feeds[1]
92+
feed.id = fake.uuid4()
93+
feed.authentication_type = "0"
94+
feed.status = "active"
95+
96+
for feed in feeds:
6597
session.add(feed)
6698

6799
for i in range(2):
@@ -104,8 +136,9 @@ def populate_database():
104136
.all()
105137
)
106138

139+
# the first 2 datasets are for the first feed
107140
for i in range(1, 4):
108-
feed_index = 0 if i in [1, 2] else i - 1
141+
feed_index = 0 if i in [1, 2] else 1
109142
wkt_polygon = "POLYGON((-18 -9, -18 9, 18 9, 18 -9, -18 -9))"
110143
wkt_element = WKTElement(wkt_polygon, srid=4326)
111144
gtfs_dataset = Gtfsdataset(
@@ -132,11 +165,11 @@ def populate_database():
132165
session.add(validation_report)
133166
gtfs_dataset.validation_reports.append(validation_report)
134167

135-
if i in [1, 2]:
136-
gtfs_dataset.locations = locations
137-
active_gtfs_feeds[i].locations = locations
168+
gtfs_dataset.locations = locations
138169

139170
active_gtfs_feeds[feed_index].gtfsdatasets.append(gtfs_dataset)
171+
active_gtfs_feeds[0].locations = locations
172+
active_gtfs_feeds[1].locations = locations
140173

141174
# active_gtfs_feeds[0].gtfsdatasets.append() = gtfs_datasets
142175

functions-python/export_csv/tests/test_export_csv_main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
# the data is correct.
2323
expected_csv = """
2424
id,data_type,entity_type,location.country_code,location.subdivision_name,location.municipality,provider,name,note,feed_contact_email,static_reference,urls.direct_download,urls.authentication_type,urls.authentication_info,urls.api_key_parameter_name,urls.latest,urls.license,location.bounding_box.minimum_latitude,location.bounding_box.maximum_latitude,location.bounding_box.minimum_longitude,location.bounding_box.maximum_longitude,location.bounding_box.extracted_on,status,features,redirect.id,redirect.comment
25-
gtfs-0,gtfs,,,,,gtfs-0 Some fake company,gtfs-0 Some fake name,gtfs-0 Some fake note,[email protected],,https://gtfs-0_some_fake_producer_url,0,,,https://dataset-1_some_fake_hosted_url,https://gtfs-0_some_fake_license_url,-9.0,9.0,-18.0,18.0,2025-01-12 00:00:00+00:00,active,Route Colors|Shapes,,
26-
gtfs-1,gtfs,,CA,Quebec,Montreal,gtfs-1 Some fake company,gtfs-1 Some fake name,gtfs-1 Some fake note,[email protected],,https://gtfs-1_some_fake_producer_url,0,,,,https://gtfs-1_some_fake_license_url,,,,,,active,,,
27-
gtfs-2,gtfs,,CA,Quebec,Montreal,gtfs-2 Some fake company,gtfs-2 Some fake name,gtfs-2 Some fake note,[email protected],,https://gtfs-2_some_fake_producer_url,0,,,https://dataset-3_some_fake_hosted_url,https://gtfs-2_some_fake_license_url,-9.0,9.0,-18.0,18.0,2025-01-12 00:00:00+00:00,active,Route Colors|Shapes,,
25+
gtfs-0,gtfs,,CA,Quebec,Montreal,gtfs-0 Some fake company,gtfs-0 Some fake name,gtfs-0 Some fake note,[email protected],,https://gtfs-0_some_fake_producer_url,0,,,https://dataset-1_some_fake_hosted_url,https://gtfs-0_some_fake_license_url,-9.0,9.0,-18.0,18.0,2025-01-12 00:00:00+00:00,active,Route Colors|Shapes,,
26+
gtfs-1,gtfs,,CA,Quebec,Montreal,gtfs-1 Some fake company,gtfs-1 Some fake name,gtfs-1 Some fake note,[email protected],,https://gtfs-1_some_fake_producer_url,0,,,https://dataset-3_some_fake_hosted_url,https://gtfs-1_some_fake_license_url,-9.0,9.0,-18.0,18.0,2025-01-12 00:00:00+00:00,active,Route Colors|Shapes,,
27+
gtfs-2,gtfs,,,,,gtfs-2 Some fake company,gtfs-2 Some fake name,gtfs-2 Some fake note,[email protected],,https://gtfs-2_some_fake_producer_url,0,,,,https://gtfs-2_some_fake_license_url,,,,,,inactive,,gtfs-0,Some redirect comment
2828
gtfs-deprecated-0,gtfs,,,,,gtfs-deprecated-0 Some fake company,gtfs-deprecated-0 Some fake name,gtfs-deprecated-0 Some fake note,[email protected],,https://gtfs-deprecated-0_some_fake_producer_url,0,,,,https://gtfs-0_some_fake_license_url,,,,,,deprecated,,,
2929
gtfs-deprecated-1,gtfs,,,,,gtfs-deprecated-1 Some fake company,gtfs-deprecated-1 Some fake name,gtfs-deprecated-1 Some fake note,[email protected],,https://gtfs-deprecated-1_some_fake_producer_url,1,,,,https://gtfs-1_some_fake_license_url,,,,,,deprecated,,,
3030
gtfs-rt-0,gtfs_rt,tu|vp,,,,gtfs-rt-0 Some fake company,gtfs-rt-0 Some fake name,gtfs-rt-0 Some fake note,[email protected],,https://gtfs-rt-0_some_fake_producer_url,0,https://gtfs-rt-0_some_fake_authentication_info_url,gtfs-rt-0_fake_api_key_parameter_name,,https://gtfs-rt-0_some_fake_license_url,,,,,,,,,

0 commit comments

Comments
 (0)