Skip to content

Commit

Permalink
fix: PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y committed Dec 6, 2024
1 parent d59b370 commit 0d6fa15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions functions-python/feed_sync_process_transitland/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _process_existing_feed_refs(
if reference_count > 0:
logging.info(f"Updating feed for stable_id: {self.feed_stable_id}")
self.feed_stable_id = f"{self.feed_stable_id}_{reference_count}".lower()
new_feed = self._update_feed(payload, active_match[0].id)
new_feed = self._deprecate_old_feed(payload, active_match[0].id)
else:
logging.info(
f"No matching stable_id. Creating new feed for {payload.external_id}."
Expand All @@ -117,8 +117,10 @@ def _get_current_feeds(self, external_id: str, source: str) -> List[Feed]:
.all()
)

def _update_feed(self, payload: FeedPayload, old_feed_id: Optional[str]) -> Feed:
"""Update an existing feed with a new URL."""
def _deprecate_old_feed(
self, payload: FeedPayload, old_feed_id: Optional[str]
) -> Feed:
"""Update the status of an old feed and create a new one."""
if old_feed_id:
old_feed = self.session.get(Feed, old_feed_id)
if old_feed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_process_existing_feed_refs(
)
]
processor.feed_stable_id = "tld-feed1"
processor._update_feed = MagicMock(
processor._deprecate_old_feed = MagicMock(
return_value=Feed(
id="feed-uuid",
producer_url="https://example.com/different",
Expand Down Expand Up @@ -406,11 +406,11 @@ def test_process_existing_feed_refs(
def test_update_feed(self, create_new_feed_mock, processor, feed_payload):
"""Test updating an existing feed."""
# No matching feed
processor._update_feed(feed_payload, None)
processor._deprecate_old_feed(feed_payload, None)
create_new_feed_mock.assert_called_once()
# Provided id but no db entity
processor.session.get.return_value = None
processor._update_feed(feed_payload, "feed-uuid")
processor._deprecate_old_feed(feed_payload, "feed-uuid")
create_new_feed_mock.assert_called()
# Update existing feed
returned_feed = Gtfsfeed(
Expand All @@ -420,5 +420,5 @@ def test_update_feed(self, create_new_feed_mock, processor, feed_payload):
status="active",
)
processor.session.get.return_value = returned_feed
processor._update_feed(feed_payload, "feed-uuid")
processor._deprecate_old_feed(feed_payload, "feed-uuid")
assert returned_feed.status == "deprecated"

0 comments on commit 0d6fa15

Please sign in to comment.