Skip to content

Commit 6a2192d

Browse files
Feat: update operational status endpoint to include 'published' (#927)
1 parent c42c3f2 commit 6a2192d

File tree

14 files changed

+172
-80
lines changed

14 files changed

+172
-80
lines changed

api/src/feeds/impl/feeds_api_impl.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def get_feed(self, id: str, db_session: Session) -> BasicFeed:
7575
.filter(Feed.data_type != "gbfs") # Filter out GBFS feeds
7676
.filter(
7777
or_(
78-
Feed.operational_status == None, # noqa: E711
79-
Feed.operational_status != "wip",
78+
Feed.operational_status == "published",
8079
not is_email_restricted, # Allow all feeds to be returned if the user is not restricted
8180
)
8281
)
@@ -110,8 +109,7 @@ def get_feeds(
110109
feed_query = feed_query.filter(Feed.data_type != "gbfs") # Filter out GBFS feeds
111110
feed_query = feed_query.filter(
112111
or_(
113-
Feed.operational_status == None, # noqa: E711
114-
Feed.operational_status != "wip",
112+
Feed.operational_status == "published",
115113
not is_email_restricted, # Allow all feeds to be returned if the user is not restricted
116114
)
117115
)
@@ -147,8 +145,7 @@ def _get_gtfs_feed(stable_id: str, db_session: Session) -> Optional[Gtfsfeed]:
147145
.filter(db_session.query(Gtfsfeed))
148146
.filter(
149147
or_(
150-
Gtfsfeed.operational_status == None, # noqa: E711
151-
Gtfsfeed.operational_status != "wip",
148+
Gtfsfeed.operational_status == "published",
152149
not is_user_email_restricted(), # Allow all feeds to be returned if the user is not restricted
153150
)
154151
)
@@ -191,8 +188,7 @@ def get_gtfs_feed_datasets(
191188
.filter(Database().get_query_model(db_session, Gtfsfeed))
192189
.filter(
193190
or_(
194-
Feed.operational_status == None, # noqa: E711
195-
Feed.operational_status != "wip",
191+
Feed.operational_status == "published",
196192
not is_user_email_restricted(), # Allow all feeds to be returned if the user is not restricted
197193
)
198194
)
@@ -273,8 +269,7 @@ def get_gtfs_rt_feed(self, id: str, db_session: Session) -> GtfsRTFeed:
273269
db_session.query(Gtfsrealtimefeed, t_location_with_translations_en)
274270
.filter(
275271
or_(
276-
Gtfsrealtimefeed.operational_status == None, # noqa: E711
277-
Gtfsrealtimefeed.operational_status != "wip",
272+
Gtfsrealtimefeed.operational_status == "published",
278273
not is_user_email_restricted(), # Allow all feeds to be returned if the user is not restricted
279274
)
280275
)
@@ -361,8 +356,7 @@ def get_gtfs_rt_feeds(
361356
.filter(Gtfsrealtimefeed.id.in_(subquery))
362357
.filter(
363358
or_(
364-
Gtfsrealtimefeed.operational_status == None, # noqa: E711
365-
Gtfsrealtimefeed.operational_status != "wip",
359+
Gtfsrealtimefeed.operational_status == "published",
366360
not is_user_email_restricted(), # Allow all feeds to be returned if the user is not restricted
367361
)
368362
)

api/src/feeds/impl/search_api_impl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def add_search_query_filters(query, search_query, data_type, feed_id, status, is
4040
query = query.filter(t_feedsearch.c.data_type != "gbfs") # Filter out GBFS feeds
4141
query = query.filter(
4242
or_(
43-
t_feedsearch.c.operational_status == None, # noqa: E711
44-
t_feedsearch.c.operational_status != "wip",
43+
t_feedsearch.c.operational_status == "published",
4544
not is_user_email_restricted(),
4645
)
4746
)

api/src/scripts/populate_db_gbfs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def populate_db(self):
8080
data_type="gbfs",
8181
stable_id=stable_id,
8282
created_at=datetime.now(pytz.utc),
83+
operational_status="published",
8384
)
8485
gbfs_feed.externalids = [self.get_external_id(feed_id, row["System ID"])]
8586
session.add(gbfs_feed)

api/src/scripts/populate_db_gtfs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def populate_db(self, session: "Session"):
198198
stable_id=stable_id,
199199
# Current timestamp with UTC timezone
200200
created_at=datetime.now(pytz.utc),
201+
operational_status="published",
201202
)
202203
self.logger.info(f"Creating {feed.__class__.__name__}: {stable_id}")
203204
session.add(feed)

api/src/scripts/populate_db_test_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def populate_test_feeds(self, feeds_data, db_session: "Session"):
158158
license_url=None,
159159
feed_contact_email=feed_data["feed_contact_email"],
160160
producer_url=feed_data["source_info"]["producer_url"],
161+
operational_status="published",
161162
)
162163
locations = []
163164
for location_data in feed_data["locations"]:

api/src/shared/common/db_utils.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ def get_gtfs_feeds_query(
5858

5959
feed_query = db_session.query(Gtfsfeed).filter(Gtfsfeed.id.in_(subquery))
6060
if not include_wip:
61-
feed_query = feed_query.filter(
62-
or_(Gtfsfeed.operational_status == None, Gtfsfeed.operational_status != "wip") # noqa: E711
63-
)
61+
feed_query = feed_query.filter(Gtfsfeed.operational_status == "published")
6462

6563
feed_query = feed_query.options(
6664
joinedload(Gtfsfeed.gtfsdatasets)
@@ -91,7 +89,7 @@ def get_all_gtfs_feeds(
9189
"""
9290
feed_query = db_session.query(Gtfsfeed).order_by(Gtfsfeed.stable_id).yield_per(batch_size)
9391
if not include_wip:
94-
feed_query = feed_query.filter(Gtfsfeed.operational_status.is_distinct_from("wip"))
92+
feed_query = feed_query.filter(Gtfsfeed.operational_status == "published")
9593

9694
for batch in batched(feed_query, batch_size):
9795
stable_ids = (f.stable_id for f in batch)
@@ -153,12 +151,7 @@ def get_gtfs_rt_feeds_query(
153151
feed_query = db_session.query(Gtfsrealtimefeed).filter(Gtfsrealtimefeed.id.in_(subquery))
154152

155153
if not include_wip:
156-
feed_query = feed_query.filter(
157-
or_(
158-
Gtfsrealtimefeed.operational_status == None, # noqa: E711
159-
Gtfsrealtimefeed.operational_status != "wip",
160-
)
161-
)
154+
feed_query = feed_query.filter(Gtfsrealtimefeed.operational_status == "published")
162155

163156
feed_query = feed_query.options(
164157
joinedload(Gtfsrealtimefeed.entitytypes),
@@ -188,7 +181,7 @@ def get_all_gtfs_rt_feeds(
188181
"""
189182
feed_query = db_session.query(Gtfsrealtimefeed.stable_id).order_by(Gtfsrealtimefeed.stable_id).yield_per(batch_size)
190183
if not include_wip:
191-
feed_query = feed_query.filter(Gtfsrealtimefeed.operational_status.is_distinct_from("wip"))
184+
feed_query = feed_query.filter(Gtfsrealtimefeed.operational_status == "published")
192185

193186
for batch in batched(feed_query, batch_size):
194187
stable_ids = (f.stable_id for f in batch)

functions-python/export_csv/tests/conftest.py

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
# limitations under the License.
1515
#
1616

17-
from faker import Faker
1817
from datetime import datetime
1918

19+
from faker import Faker
2020
from geoalchemy2 import WKTElement
2121

22-
from shared.database_gen.sqlacodegen_models import (
23-
Validationreport,
24-
Feature,
25-
Redirectingid,
26-
)
2722
from shared.database_gen.sqlacodegen_models import (
2823
Gtfsfeed,
2924
Gtfsrealtimefeed,
3025
Gtfsdataset,
3126
Location,
3227
Entitytype,
3328
)
29+
from shared.database_gen.sqlacodegen_models import (
30+
Validationreport,
31+
Feature,
32+
Redirectingid,
33+
)
3434
from test_shared.test_utils.database_utils import clean_testing_db, get_testing_session
3535

3636

@@ -48,7 +48,6 @@ def populate_database():
4848
session = get_testing_session()
4949
fake = Faker()
5050

51-
feed_reference = None
5251
feeds = []
5352
# We create 3 feeds. The first one is active. The third one is inactive and redirected to the first one.
5453
# The second one is active but not redirected.
@@ -65,9 +64,9 @@ def populate_database():
6564
stable_id=f"gtfs-{i}",
6665
feed_contact_email=f"gtfs-{i}[email protected]",
6766
provider=f"gtfs-{i} Some fake company",
67+
operational_status="published",
68+
official=True,
6869
)
69-
if i == 0:
70-
feed_reference = feed
7170
feeds.append(feed)
7271

7372
# Then fill the specific parameters for each feed
@@ -112,6 +111,8 @@ def populate_database():
112111
status="deprecated",
113112
feed_contact_email=f"gtfs-deprecated-{i}[email protected]",
114113
provider=f"gtfs-deprecated-{i} Some fake company",
114+
operational_status="published",
115+
official=True,
115116
)
116117
session.add(feed)
117118

@@ -187,46 +188,46 @@ def populate_database():
187188
session.add(tu_entitytype)
188189

189190
# GTFS Realtime feeds
190-
rt_feeds = []
191+
gtfs_rt_feeds = []
191192
for i in range(3):
192-
rt_feeds.append(
193-
Gtfsrealtimefeed(
194-
id=fake.uuid4(),
195-
data_type="gtfs_rt",
196-
feed_name=f"gtfs-rt-{i} Some fake name",
197-
note=f"gtfs-rt-{i} Some fake note",
198-
producer_url=f"https://gtfs-rt-{i}_some_fake_producer_url",
199-
authentication_type=str(i),
200-
authentication_info_url=f"https://gtfs-rt-{i}_some_fake_authentication_info_url",
201-
api_key_parameter_name=f"gtfs-rt-{i}_fake_api_key_parameter_name",
202-
license_url=f"https://gtfs-rt-{i}_some_fake_license_url",
203-
stable_id=f"gtfs-rt-{i}",
204-
status="inactive" if i == 1 else "active",
205-
feed_contact_email=f"gtfs-rt-{i}[email protected]",
206-
provider=f"gtfs-rt-{i} Some fake company",
207-
entitytypes=[vp_entitytype, tu_entitytype]
208-
if i == 0
209-
else [vp_entitytype],
210-
gtfs_feeds=[feed_reference] if i == 0 else [],
211-
)
193+
feed = Gtfsrealtimefeed(
194+
id=fake.uuid4(),
195+
data_type="gtfs_rt",
196+
feed_name=f"gtfs-rt-{i} Some fake name",
197+
note=f"gtfs-rt-{i} Some fake note",
198+
producer_url=f"https://gtfs-rt-{i}_some_fake_producer_url",
199+
authentication_type=str(i),
200+
authentication_info_url=f"https://gtfs-rt-{i}_some_fake_authentication_info_url",
201+
api_key_parameter_name=f"gtfs-rt-{i}_fake_api_key_parameter_name",
202+
license_url=f"https://gtfs-rt-{i}_some_fake_license_url",
203+
stable_id=f"gtfs-rt-{i}",
204+
status="inactive" if i == 1 else "active",
205+
feed_contact_email=f"gtfs-rt-{i}[email protected]",
206+
provider=f"gtfs-rt-{i} Some fake company",
207+
entitytypes=[vp_entitytype, tu_entitytype] if i == 0 else [vp_entitytype],
208+
operational_status="published",
209+
official=True,
210+
gtfs_feeds=[active_gtfs_feeds[0]] if i == 0 else [],
212211
)
213-
# rt_feeds[1] is inactive and redirected to rt_feeds[0] and rt_feee[2]
214-
rt_feeds[1].redirectingids = [
212+
gtfs_rt_feeds.append(feed)
213+
214+
# Add redirecting IDs (from main branch logic)
215+
gtfs_rt_feeds[1].redirectingids = [
215216
Redirectingid(
216-
source_id=rt_feeds[1].id,
217-
target_id=rt_feeds[0].id,
217+
source_id=gtfs_rt_feeds[1].id,
218+
target_id=gtfs_rt_feeds[0].id,
218219
redirect_comment="comment 1",
219-
target=rt_feeds[0],
220+
target=gtfs_rt_feeds[0],
220221
),
221222
Redirectingid(
222-
source_id=rt_feeds[1].id,
223-
target_id=rt_feeds[2].id,
223+
source_id=gtfs_rt_feeds[1].id,
224+
target_id=gtfs_rt_feeds[2].id,
224225
redirect_comment="comment 2",
225-
target=rt_feeds[2],
226+
target=gtfs_rt_feeds[2],
226227
),
227228
]
228229

229-
session.add_all(rt_feeds)
230+
session.add_all(gtfs_rt_feeds)
230231

231232
session.commit()
232233

functions-python/feed_sync_process_transitland/src/feed_processor_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def create_new_feed(session: Session, stable_id: str, payload: FeedPayload) -> F
6161
api_key_parameter_name=payload.auth_param_name,
6262
status="active",
6363
provider=payload.operator_name,
64-
operational_status="wip",
64+
operational_status="wip", # Default to of wip
6565
created_at=datetime.now(),
6666
)
6767

functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from pydantic import Field
2424
from starlette.responses import Response
2525

26-
from shared.database_gen.sqlacodegen_models import Gtfsfeed, t_feedsearch
2726
from feeds_operations.impl.models.update_request_gtfs_feed_impl import (
2827
UpdateRequestGtfsFeedImpl,
2928
)
@@ -33,6 +32,7 @@
3332
from feeds_operations_gen.models.update_request_gtfs_rt_feed import (
3433
UpdateRequestGtfsRtFeed,
3534
)
35+
from shared.database_gen.sqlacodegen_models import Gtfsfeed, t_feedsearch
3636
from shared.helpers.database import Database, refresh_materialized_view
3737
from shared.helpers.query_helper import query_feed_by_stable_id
3838
from .models.update_request_gtfs_rt_feed_impl import UpdateRequestGtfsRtFeedImpl
@@ -171,7 +171,10 @@ async def _populate_feed_values(feed, impl_class, session, update_request_feed):
171171
action = update_request_feed.operational_status_action
172172
# This is a temporary solution as the operational_status is not visible in the diff
173173
if action is not None and not action.lower() == "no_change":
174-
feed.operational_status = "wip" if action.lower() == "wip" else None
174+
if action.lower() == "wip":
175+
feed.operational_status = "wip"
176+
elif action.lower() == "published":
177+
feed.operational_status = "published"
175178
session.add(feed)
176179

177180
@staticmethod

functions-python/operations_api/tests/feeds_operations/impl/test_feeds_operations_impl_gtfs.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
from fastapi import HTTPException
77
from starlette.responses import Response
88

9-
from shared.database_gen.sqlacodegen_models import Gtfsfeed
9+
from conftest import feed_mdb_40
1010
from feeds_operations.impl.feeds_operations_impl import OperationsApiImpl
1111
from feeds_operations_gen.models.authentication_type import AuthenticationType
1212
from feeds_operations_gen.models.external_id import ExternalId
1313
from feeds_operations_gen.models.feed_status import FeedStatus
1414
from feeds_operations_gen.models.source_info import SourceInfo
1515
from feeds_operations_gen.models.update_request_gtfs_feed import UpdateRequestGtfsFeed
16-
from conftest import feed_mdb_40
16+
from shared.database_gen.sqlacodegen_models import Gtfsfeed
1717
from test_shared.test_utils.database_utils import get_testing_session, default_db_url
1818

1919

@@ -115,19 +115,19 @@ async def test_update_gtfs_feed_set_wip(_, update_request_gtfs_feed):
115115
},
116116
)
117117
@pytest.mark.asyncio
118-
async def test_update_gtfs_feed_set_wip_publish(_, update_request_gtfs_feed):
119-
update_request_gtfs_feed.operational_status_action = "published"
118+
async def test_update_gtfs_feed_set_wip_nochange(_, update_request_gtfs_feed):
119+
update_request_gtfs_feed.operational_status_action = "no_change"
120120
with get_testing_session() as session:
121121
api = OperationsApiImpl()
122122
response: Response = await api.update_gtfs_feed(update_request_gtfs_feed)
123-
assert response.status_code == 200
123+
assert response.status_code == 204
124124

125125
db_feed = (
126126
session.query(Gtfsfeed)
127127
.filter(Gtfsfeed.stable_id == feed_mdb_40.stable_id)
128128
.one()
129129
)
130-
assert db_feed.operational_status is None
130+
assert db_feed.operational_status == "wip"
131131

132132

133133
@patch("shared.helpers.logger.Logger")
@@ -138,19 +138,19 @@ async def test_update_gtfs_feed_set_wip_publish(_, update_request_gtfs_feed):
138138
},
139139
)
140140
@pytest.mark.asyncio
141-
async def test_update_gtfs_feed_set_wip_nochange(_, update_request_gtfs_feed):
142-
update_request_gtfs_feed.operational_status_action = "no_change"
141+
async def test_update_gtfs_feed_set_published(_, update_request_gtfs_feed):
142+
update_request_gtfs_feed.operational_status_action = "published"
143143
with get_testing_session() as session:
144144
api = OperationsApiImpl()
145145
response: Response = await api.update_gtfs_feed(update_request_gtfs_feed)
146-
assert response.status_code == 204
146+
assert response.status_code == 200
147147

148148
db_feed = (
149149
session.query(Gtfsfeed)
150150
.filter(Gtfsfeed.stable_id == feed_mdb_40.stable_id)
151151
.one()
152152
)
153-
assert db_feed.operational_status is None
153+
assert db_feed.operational_status == "published"
154154

155155

156156
@patch("shared.helpers.logger.Logger")

0 commit comments

Comments
 (0)