Skip to content

Commit 36747ba

Browse files
feat: add official field in the operational API update endpoint (#1097)
* feat: add official field in the operational API update endpoint * updated unit test & linter fix * added official field to Operations API schema
1 parent 7c3536e commit 36747ba

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

docs/OperationsAPI.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ components:
319319
- no_change
320320
- wip
321321
- published
322+
official:
323+
type: boolean
324+
description: Whether this is an official feed.
322325
required:
323326
- id
324327
- status
@@ -364,6 +367,9 @@ components:
364367
- no_change
365368
- wip
366369
- published
370+
official:
371+
type: boolean
372+
description: Whether this is an official feed.
367373
required:
368374
- id
369375
- status

functions-python/operations_api/src/feeds_operations/impl/models/update_request_gtfs_feed_impl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# limitations under the License.
1515
#
1616

17-
from shared.database_gen.sqlacodegen_models import Gtfsfeed
1817
from feeds_operations.impl.models.external_id_impl import ExternalIdImpl
1918
from feeds_operations.impl.models.redirect_impl import RedirectImpl
2019
from feeds_operations_gen.models.source_info import SourceInfo
2120
from feeds_operations_gen.models.update_request_gtfs_feed import UpdateRequestGtfsFeed
21+
from shared.database_gen.sqlacodegen_models import Gtfsfeed
2222

2323

2424
class UpdateRequestGtfsFeedImpl(UpdateRequestGtfsFeed):
@@ -64,6 +64,7 @@ def from_orm(cls, obj: Gtfsfeed | None) -> UpdateRequestGtfsFeed | None:
6464
[ExternalIdImpl.from_orm(item) for item in obj.externalids],
6565
key=lambda x: x.external_id,
6666
),
67+
official=obj.official,
6768
)
6869

6970
@classmethod
@@ -78,6 +79,7 @@ def to_orm(
7879
entity.feed_name = update_request.feed_name
7980
entity.note = update_request.note
8081
entity.feed_contact_email = update_request.feed_contact_email
82+
entity.official = update_request.official
8183
entity.producer_url = (
8284
None
8385
if (

functions-python/operations_api/src/feeds_operations/impl/models/update_request_gtfs_rt_feed_impl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
# limitations under the License.
1515
#
1616

17-
from shared.database_gen.sqlacodegen_models import Gtfsfeed, Gtfsrealtimefeed
1817
from feeds_operations.impl.models.entity_type_impl import EntityTypeImpl
1918
from feeds_operations.impl.models.external_id_impl import ExternalIdImpl
2019
from feeds_operations.impl.models.redirect_impl import RedirectImpl
2120
from feeds_operations_gen.models.source_info import SourceInfo
2221
from feeds_operations_gen.models.update_request_gtfs_rt_feed import (
2322
UpdateRequestGtfsRtFeed,
2423
)
24+
from shared.database_gen.sqlacodegen_models import Gtfsfeed, Gtfsrealtimefeed
2525

2626

2727
class UpdateRequestGtfsRtFeedImpl(UpdateRequestGtfsRtFeed):
@@ -71,6 +71,7 @@ def from_orm(cls, obj: Gtfsrealtimefeed | None) -> UpdateRequestGtfsRtFeed | Non
7171
[EntityTypeImpl.from_orm(item) for item in obj.entitytypes]
7272
),
7373
feed_references=sorted([item.stable_id for item in obj.gtfs_feeds]),
74+
official=obj.official,
7475
)
7576

7677
@classmethod
@@ -85,6 +86,7 @@ def to_orm(
8586
entity.feed_name = update_request.feed_name
8687
entity.note = update_request.note
8788
entity.feed_contact_email = update_request.feed_contact_email
89+
entity.official = update_request.official
8890
entity.producer_url = (
8991
None
9092
if (

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def update_request_gtfs_feed():
3838
),
3939
redirects=[],
4040
operational_status_action="no_change",
41+
official=True,
4142
)
4243

4344

@@ -52,7 +53,7 @@ def update_request_gtfs_feed():
5253
async def test_update_gtfs_feed_no_changes(_, update_request_gtfs_feed):
5354
api = OperationsApiImpl()
5455
response: Response = await api.update_gtfs_feed(update_request_gtfs_feed)
55-
assert response.status_code == 204
56+
assert response.status_code == 200
5657

5758

5859
@patch("shared.helpers.logger.Logger")
@@ -168,3 +169,27 @@ async def test_update_gtfs_feed_invalid_feed(_, update_request_gtfs_feed):
168169
await api.update_gtfs_feed(update_request_gtfs_feed)
169170
assert exc_info.value.status_code == 400
170171
assert exc_info.value.detail == "Feed ID not found: invalid"
172+
173+
174+
@patch("shared.helpers.logger.Logger")
175+
@mock.patch.dict(
176+
os.environ,
177+
{
178+
"FEEDS_DATABASE_URL": default_db_url,
179+
},
180+
)
181+
@pytest.mark.asyncio
182+
async def test_update_gtfs_feed_official_field(_, update_request_gtfs_feed):
183+
"""Test updating the official field of a GTFS feed."""
184+
update_request_gtfs_feed.official = True
185+
with get_testing_session() as session:
186+
api = OperationsApiImpl()
187+
response: Response = await api.update_gtfs_feed(update_request_gtfs_feed)
188+
assert response.status_code == 204
189+
190+
db_feed = (
191+
session.query(Gtfsfeed)
192+
.filter(Gtfsfeed.stable_id == feed_mdb_40.stable_id)
193+
.one()
194+
)
195+
assert db_feed.official is True

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def update_request_gtfs_rt_feed():
4040
redirects=[],
4141
operational_status_action="no_change",
4242
entity_types=[EntityType.VP],
43+
official=True,
4344
)
4445

4546

@@ -137,3 +138,27 @@ async def test_update_gtfs_rt_feed_set_published(_, update_request_gtfs_rt_feed)
137138
.one()
138139
)
139140
assert db_feed.operational_status == "published"
141+
142+
143+
@patch("shared.helpers.logger.Logger")
144+
@mock.patch.dict(
145+
os.environ,
146+
{
147+
"FEEDS_DATABASE_URL": default_db_url,
148+
},
149+
)
150+
@pytest.mark.asyncio
151+
async def test_update_gtfs_rt_feed_official_field(_, update_request_gtfs_rt_feed):
152+
"""Test updating the official field of a GTFS-RT feed."""
153+
update_request_gtfs_rt_feed.official = True
154+
with get_testing_session() as session:
155+
api = OperationsApiImpl()
156+
response: Response = await api.update_gtfs_rt_feed(update_request_gtfs_rt_feed)
157+
assert response.status_code == 200
158+
159+
db_feed = (
160+
session.query(Gtfsrealtimefeed)
161+
.filter(Gtfsrealtimefeed.stable_id == feed_mdb_41.stable_id)
162+
.one()
163+
)
164+
assert db_feed.official is True

0 commit comments

Comments
 (0)