Skip to content

Commit

Permalink
Fix error when adding prefix aut nav treni with venezia (#173)
Browse files Browse the repository at this point in the history
* Create migration to replace in tables stations, stops, stop_times

* Rename all references to aut, nav, treni

* Fix error with source_name for GTFS class
  • Loading branch information
gsarrco authored Jan 19, 2024
1 parent 1a739c5 commit c2f0fd4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions server/GTFS/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def get_latest_gtfs_version(transport_type):


class GTFS(Source):
def __init__(self, transport_type, emoji, session, typesense, gtfs_versions_range: tuple[int] = None, location='', dev=False, ref_dt: datetime = None):
super().__init__(transport_type[:3], emoji, session, typesense)
def __init__(self, transport_type, source_name, emoji, session, typesense, gtfs_versions_range: tuple[int] = None,
location='', dev=False, ref_dt: datetime = None):
super().__init__(source_name, emoji, session, typesense)
self.transport_type = transport_type
self.location = location
self.service_ids = {}
Expand Down
4 changes: 2 additions & 2 deletions server/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
typesense = connect_to_typesense()

sources = {
'venezia-aut': GTFS('automobilistico', '🚌', session, typesense, dev=config.get('DEV', False)),
'venezia-nav': GTFS('navigazione', '⛴️', session, typesense, dev=config.get('DEV', False)),
'venezia-aut': GTFS('automobilistico', 'venezia-aut', '🚌', session, typesense, dev=config.get('DEV', False)),
'venezia-nav': GTFS('navigazione', 'venezia-nav', '⛴️', session, typesense, dev=config.get('DEV', False)),
'venezia-treni': Trenitalia(session, typesense)
}

Expand Down
13 changes: 7 additions & 6 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@
@pytest.fixture
def db_file():
ref_dt = datetime(2023, 10, 15)
return GTFS('navigazione', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=ref_dt)
return GTFS('navigazione', 'venezia-nav', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=ref_dt)


def test_valid_gtfs():
_558_ref_df = datetime(2023, 10, 7)
_558_gtfs = GTFS('navigazione', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=_558_ref_df)
_558_gtfs = GTFS('navigazione', 'venezia-nav', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=_558_ref_df)
assert _558_gtfs.gtfs_version == 558, 'invalid gtfs version'

_557_ref_dt = datetime(2023, 10, 6)
_557_gtfs = GTFS('navigazione', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=_557_ref_dt)
_557_gtfs = GTFS('navigazione', 'venezia-nav', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=_557_ref_dt)
assert _557_gtfs.gtfs_version == 557, 'invalid gtfs version'


def test_invalid_gtfs():
invalid_ref_df = datetime(2023, 9, 30)
with pytest.raises(Exception):
GTFS('navigazione', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=invalid_ref_df)
GTFS('navigazione', 'venezia-nav', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=invalid_ref_df)


def test_zero_stop_times_for_next_service():
db_file = GTFS('navigazione', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=datetime(2023, 10, 6))
db_file = GTFS('navigazione', 'venezia-nav', '⛴️', None, None, (558, 557), 'tests/data',
ref_dt=datetime(2023, 10, 6))
next_service_date = date(2023, 10, 7)

# On the 2023-10-06 we already know that there will a new service starting on 2023-10-07
Expand All @@ -46,7 +47,7 @@ def test_zero_stop_times_for_next_service():

def test_normal_stop_times_for_current_service():
ref_dt = datetime(2023, 10, 7)
db_file = GTFS('navigazione', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=ref_dt)
db_file = GTFS('navigazione', 'venezia-nav', '⛴️', None, None, (558, 557), 'tests/data', ref_dt=ref_dt)

# On the 2023-10-06 we already know that there will a new service starting on 2023-10-07
assert not hasattr(db_file, 'next_service_start_date')
Expand Down

0 comments on commit c2f0fd4

Please sign in to comment.