Skip to content

Commit 10c93d1

Browse files
authored
Added feed_license_changes to the list of cascade entries. (#1528)
1 parent 9cd5f52 commit 10c93d1

File tree

8 files changed

+48
-8
lines changed

8 files changed

+48
-8
lines changed

api/src/scripts/populate_db.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DatabasePopulateHelper:
4545
Helper class to populate the database
4646
"""
4747

48-
def __init__(self, filepaths):
48+
def __init__(self, filepaths, test_mode=False):
4949
"""
5050
Specify a list of files to load the csv data from.
5151
Can also be a single string with a file name.
@@ -60,7 +60,10 @@ def __init__(self, filepaths):
6060
filepaths = [filepaths]
6161

6262
for filepath in filepaths:
63-
new_df = pandas.read_csv(filepath, low_memory=False)
63+
if test_mode:
64+
new_df = pandas.read_csv(filepath, comment="#", low_memory=False)
65+
else:
66+
new_df = pandas.read_csv(filepath, low_memory=False)
6467
self.df = pandas.concat([self.df, new_df])
6568

6669
self.filter_data()

api/src/scripts/populate_db_gbfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414

1515
class GBFSDatabasePopulateHelper(DatabasePopulateHelper):
16-
def __init__(self, filepaths):
17-
super().__init__(filepaths)
16+
def __init__(self, filepaths, test_mode=False):
17+
super().__init__(filepaths, test_mode)
1818

1919
def filter_data(self):
2020
"""Filter out rows with Authentication Info and duplicate System IDs"""

api/src/scripts/populate_db_gtfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class GTFSDatabasePopulateHelper(DatabasePopulateHelper):
2626
GTFS - Helper class to populate the database
2727
"""
2828

29-
def __init__(self, filepaths):
29+
def __init__(self, filepaths, test_mode=False):
3030
"""
3131
Specify a list of files to load the csv data from.
3232
Can also be a single string with a file name.
3333
"""
34-
super().__init__(filepaths)
34+
super().__init__(filepaths, test_mode)
3535
# Keep track of the feeds that have been added to the database
3636
self.added_gtfs_feeds = []
3737

api/src/shared/database/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def configure_polymorphic_mappers():
7575
Feed.officialstatushistories, # officialstatushistory_feed_id_fkey
7676
Feed.redirectingids, # redirectingid_source_id_fkey
7777
Feed.redirectingids_, # redirectingid_target_id_fkey
78+
Feed.feed_license_changes,
7879
],
7980
Gbfsfeed: [
8081
Gbfsfeed.gbfsversions, # gbfsversion_feed_id_fkey

api/tests/integration/cascade_delete/test_cascade_delete.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Notice,
2626
Gtfsfeed,
2727
Geopolygon,
28+
FeedLicenseChange,
2829
)
2930

3031
from sqlalchemy import text
@@ -188,6 +189,24 @@ def test_delete_feed_cascadeto_redirectingid(test_database):
188189
assert assoc_count == 0
189190

190191

192+
def test_delete_feed_cascadeto_feed_license_changes(test_database):
193+
194+
with test_database.start_db_session() as session:
195+
feed = Feed(id="f1")
196+
feed_license_change = FeedLicenseChange(feed_id="f1")
197+
session.add_all([feed, feed_license_change])
198+
session.commit()
199+
200+
delete_and_assert(
201+
session,
202+
[
203+
"SELECT COUNT(*) FROM feed where id = 'f1'",
204+
"SELECT COUNT(*) FROM feed_license_change where feed_id = 'f1'",
205+
],
206+
feed,
207+
)
208+
209+
191210
def test_delete_gbfsfeed_cascadeto_gbfsversion_cascadeto_gbfsendpoint_cascadeto_gbfsendpointhttpaccesslog(
192211
test_database,
193212
):
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
# The contents of this file will be added to the database after the sources_test.csv of the parent directories.
2+
# So we can replicate some feeds here that are a slight change from the ones in the parent source_test.csv
3+
# and see the effect.
4+
# We want to make sure the is_official flag is handled properly in that case.
5+
# Normally changing to True or False should change the original value but changing to an empty cell should not
16
mdb_source_id,data_type,entity_type,location.country_code,location.subdivision_name,location.municipality,provider,is_official,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
7+
# For mdb-40, change is_official from TRUE to empty. Should retain True# For mdb-40, change is_official from TRUE to empty. Should retain True
28
40,gtfs,,CA,Ontario,London,London Transit Commission,,,,[email protected],,http://www.londontransit.ca/gtfsfeed/google_transit.zip,0,,,https://storage.googleapis.com/storage/v1/b/mdb-latest/o/ca-ontario-london-transit-commission-gtfs-2.zip?alt=media,https://www.londontransit.ca/open-data/ltcs-open-data-terms-of-use/,42.905244,43.051188,-81.36311,-81.137591,2022-02-22T19:51:34+00:00,inactive,,,
9+
# For mdb-50, change is_official from FALSE to empty. Should retain False
310
50,gtfs,,CA,Ontario,Barrie,ZBarrie Transit,,,,,,http://www.myridebarrie.ca/gtfs/Google_transit.zip,,,,https://storage.googleapis.com/storage/v1/b/mdb-latest/o/ca-ontario-barrie-transit-gtfs-3.zip?alt=media,https://www.barrie.ca/services-payments/transportation-parking/barrie-transit/barrie-gtfs,44.3218044,44.42020676,-79.74063237,-79.61089569,2022-03-01T22:43:25+00:00,deprecated,,40|mdb-702,Some|Comment
11+
# For mdb-1562, change is_official from FALSE to TRUE. Should change to True
412
1562,gtfs-rt,sa,CA,BC,Vancouver,Vancouver-Transit(éèàçíóúČ),TRUE,Realtime(ŘŤÜÎ),,,50,http://foo.org/google_transit.zip,0,,,,,,,,,,active,,10,
13+
# For mdb-1563, change is_official from TRUE to FALSE. Should change to False
514
1563,gtfs-rt,tu,US,SomeState,SomeCity,SomeCity Bus,FALSE,RT,,,mdb-50,http://bar.com,0,,,,,,,,,,inactive,,10,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# We want to test the populate when there is already stuff in the DB and we rerun
2+
# with changes in systems.csv
13
Country Code,Name,Location,System ID,URL,Auto-Discovery URL,Supported Versions,Authentication Info URL, Authentication Type,Authentication Parameter Name
4+
# Feed 1 stays the same
25
AE,Feed 1,Dubai,feed_1,https://www.careem.com/en-ae/careem-bike/,https://some_url/gbfs.json,1.1 ; 2.3,,,
6+
# Feed 2 was removed. We expect it to be made deprecated in the DB
7+
# Feed 3 was modified (Name will be Feed 3 modified instead of Feed 3)
38
AE,Feed 3 modified,Dubai,feed_3,https://www.careem.com/en-ae/careem-bike/,https://some_url/gbfs.json,1.1 ; 2.3,,,
9+
# Feed 4 was added
410
AE,Feed 4,Dubai,feed_4,https://ridedott.com/,https://some_url/gbfs.json,2.3,,,

api/tests/test_utils/database.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _populate_db_phase(db: Database, data_dirs: List[str]):
7272
if (filepath := os.path.join(directory, "sources_test.csv")) and os.path.isfile(filepath)
7373
]
7474
if csv_filepaths:
75-
gtfs_db_helper = GTFSDatabasePopulateHelper(csv_filepaths)
75+
gtfs_db_helper = GTFSDatabasePopulateHelper(csv_filepaths, test_mode=True)
7676
gtfs_db_helper.initialize(trigger_downstream_tasks=False)
7777

7878
# GBFS
@@ -82,7 +82,9 @@ def _populate_db_phase(db: Database, data_dirs: List[str]):
8282
if (filepath := os.path.join(directory, "systems_test.csv")) and os.path.isfile(filepath)
8383
]
8484
if gbfs_csv_filepaths:
85-
GBFSDatabasePopulateHelper(gbfs_csv_filepaths).initialize(trigger_downstream_tasks=False, fetch_url=False)
85+
GBFSDatabasePopulateHelper(gbfs_csv_filepaths, test_mode=True).initialize(
86+
trigger_downstream_tasks=False, fetch_url=False
87+
)
8688

8789
# Extra test data
8890
json_filepaths = [

0 commit comments

Comments
 (0)