Skip to content

Commit 9c3f653

Browse files
feat: add operational status of "unpublished" to opeartions_api (#1132)
1 parent 7088cd2 commit 9c3f653

File tree

7 files changed

+124
-4
lines changed

7 files changed

+124
-4
lines changed

docs/OperationsAPI.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ paths:
3333
required: false
3434
schema:
3535
type: string
36-
enum: [ wip, published ]
36+
enum: [ wip, published, unpublished ]
3737
- name: data_type
3838
in: query
3939
description: Filter feeds by data type.
@@ -179,7 +179,7 @@ components:
179179
$ref: "#/components/schemas/SourceInfo"
180180
operational_status:
181181
type: string
182-
enum: [ wip, published ]
182+
enum: [ wip, published, unpublished ]
183183
description: Current operational status of the feed.
184184
created_at:
185185
type: string
@@ -319,6 +319,7 @@ components:
319319
- no_change
320320
- wip
321321
- published
322+
- unpublished
322323
official:
323324
type: boolean
324325
description: Whether this is an official feed.
@@ -367,6 +368,7 @@ components:
367368
- no_change
368369
- wip
369370
- published
371+
- unpublished
370372
official:
371373
type: boolean
372374
description: Whether this is an official feed.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ async def _populate_feed_values(feed, impl_class, session, update_request_feed):
238238
feed.operational_status = "wip"
239239
elif action.lower() == "published":
240240
feed.operational_status = "published"
241+
elif action.lower() == "unpublished":
242+
feed.operational_status = "unpublished"
241243
session.add(feed)
242244

243245
@staticmethod

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ async def test_update_gtfs_feed_set_published(_, update_request_gtfs_feed, db_se
132132
assert db_feed.operational_status == "published"
133133

134134

135+
@patch("shared.helpers.logger.Logger")
136+
@pytest.mark.asyncio
137+
@pytest.mark.usefixtures("update_request_gtfs_feed", "db_session")
138+
async def test_update_gtfs_feed_set_unpublished(
139+
_, update_request_gtfs_feed, db_session
140+
):
141+
update_request_gtfs_feed.operational_status_action = "unpublished"
142+
api = OperationsApiImpl()
143+
response: Response = await api.update_gtfs_feed(update_request_gtfs_feed)
144+
assert response.status_code == 200
145+
146+
db_feed = (
147+
db_session.query(Gtfsfeed)
148+
.filter(Gtfsfeed.stable_id == feed_mdb_40.stable_id)
149+
.one()
150+
)
151+
assert db_feed.operational_status == "unpublished"
152+
153+
135154
@patch("shared.helpers.logger.Logger")
136155
@pytest.mark.asyncio
137156
async def test_update_gtfs_feed_invalid_feed(_, update_request_gtfs_feed):

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ async def test_update_gtfs_rt_feed_set_published(
129129
assert db_feed.operational_status == "published"
130130

131131

132+
@patch("shared.helpers.logger.Logger")
133+
@pytest.mark.asyncio
134+
@pytest.mark.usefixtures("update_request_gtfs_rt_feed", "db_session")
135+
async def test_update_gtfs_rt_feed_set_unpublished(
136+
_, update_request_gtfs_rt_feed, db_session
137+
):
138+
update_request_gtfs_rt_feed.operational_status_action = "unpublished"
139+
api = OperationsApiImpl()
140+
response: Response = await api.update_gtfs_rt_feed(update_request_gtfs_rt_feed)
141+
assert response.status_code == 200
142+
143+
db_feed = (
144+
db_session.query(Gtfsrealtimefeed)
145+
.filter(Gtfsrealtimefeed.stable_id == feed_mdb_41.stable_id)
146+
.one()
147+
)
148+
assert db_feed.operational_status == "unpublished"
149+
150+
132151
@patch("shared.helpers.logger.Logger")
133152
@pytest.mark.asyncio
134153
async def test_update_gtfs_rt_feed_official_field(

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,60 @@ async def test_get_feeds_gtfs_rt_entity_types():
218218
assert isinstance(feed.entity_types, list)
219219
for entity_type in feed.entity_types:
220220
assert entity_type in ["vp", "tu", "sa"]
221+
222+
223+
@pytest.mark.asyncio
224+
async def test_get_feeds_unpublished_status():
225+
"""
226+
Test get_feeds endpoint with unpublished operational status filter.
227+
Should return only feeds with unpublished status.
228+
"""
229+
api = OperationsApiImpl()
230+
231+
# Test with unpublished status filter
232+
response = await api.get_feeds(operation_status="unpublished")
233+
assert response is not None
234+
for feed in response.feeds:
235+
assert feed.operational_status == "unpublished"
236+
237+
238+
@pytest.mark.asyncio
239+
async def test_get_feeds_all_operational_statuses():
240+
"""
241+
Test get_feeds endpoint with all possible operational status values.
242+
Verifies that each operational status filter works correctly.
243+
"""
244+
api = OperationsApiImpl()
245+
246+
# Test each operational status
247+
for status in ["wip", "published", "unpublished"]:
248+
response = await api.get_feeds(operation_status=status)
249+
assert response is not None
250+
for feed in response.feeds:
251+
assert feed.operational_status == status
252+
253+
254+
@pytest.mark.asyncio
255+
async def test_get_feeds_unpublished_with_data_type():
256+
"""
257+
Test get_feeds endpoint with unpublished status and data type filters combined.
258+
"""
259+
api = OperationsApiImpl()
260+
261+
gtfs_response = await api.get_feeds(
262+
operation_status="unpublished", data_type="gtfs"
263+
)
264+
assert gtfs_response is not None
265+
for feed in gtfs_response.feeds:
266+
assert feed.operational_status == "unpublished"
267+
assert feed.data_type == "gtfs"
268+
assert isinstance(feed, GtfsFeedResponse)
269+
270+
rt_response = await api.get_feeds(
271+
operation_status="unpublished", data_type="gtfs_rt"
272+
)
273+
assert rt_response is not None
274+
for feed in rt_response.feeds:
275+
assert feed.operational_status == "unpublished"
276+
assert feed.data_type == "gtfs_rt"
277+
assert isinstance(feed, GtfsRtFeedResponse)

liquibase/changelog.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848
<include file="changes/feat_1055.sql" relativeToChangelogFile="true"/>
4949
<include file="changes/feat_1041.sql" relativeToChangelogFile="true"/>
5050
<include file="changes/feat_997.sql" relativeToChangelogFile="true"/>
51-
<!-- Materialized view updated. Added features and totals. -->
51+
<!-- Materialized view updated. Added features and totals. -->
5252
<include file="changes/feat_993.sql" relativeToChangelogFile="true"/>
5353
<!-- Materialized view updated. Used Feed.official field as official status. -->
5454
<include file="changes/feat_1083.sql" relativeToChangelogFile="true"/>
55-
</databaseChangeLog>
55+
<include file="changes/feat_1132.sql" relativeToChangelogFile="true"/>
56+
</databaseChangeLog>

liquibase/changes/feat_1132.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Add 'unpublished' to the OperationalStatus enum if it doesn't exist
2+
DO $$
3+
BEGIN
4+
-- Check if the enum already has the 'unpublished' value
5+
IF NOT EXISTS (
6+
SELECT 1
7+
FROM pg_enum
8+
WHERE enumlabel = 'unpublished'
9+
AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'operationalstatus')
10+
) THEN
11+
-- Add 'unpublished' to the enum
12+
ALTER TYPE OperationalStatus ADD VALUE 'unpublished';
13+
RAISE NOTICE 'Added ''unpublished'' value to OperationalStatus enum';
14+
ELSE
15+
RAISE NOTICE 'The ''unpublished'' value already exists in OperationalStatus enum';
16+
END IF;
17+
EXCEPTION
18+
WHEN OTHERS THEN
19+
RAISE EXCEPTION 'Failed to add ''unpublished'' to OperationalStatus enum: %', SQLERRM;
20+
END $$;

0 commit comments

Comments
 (0)