Skip to content

Commit 748fbd8

Browse files
committed
added tests
1 parent 336fa9c commit 748fbd8

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

functions-python/helpers/feed_status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_filters(status: str):
5959
]
6060

6161
if len(stable_feed_ids) > 0:
62-
filters.append(Feed.stable_feed_id.in_(stable_feed_ids))
62+
filters.insert(0, Feed.stable_id.in_(stable_feed_ids))
6363

6464
return filters
6565

functions-python/update_feed_status/tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def populate_database(db_session):
5454
}
5555
for status, (a, b) in id_range_by_status.items():
5656
for _id in map(str, range(a, b + 1)):
57-
db_session.add(Feed(id=str(_id), status=status))
57+
db_session.add(
58+
Feed(id=str(_id), status=status, stable_id="mdb-" + str(_id))
59+
)
5860

5961
# -> inactive
6062
for _id in [

functions-python/update_feed_status/tests/test_update_feed_status_main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest.mock import patch, MagicMock
22

3+
from conftest import clean_testing_db, populate_database
34
from shared.database.database import with_db_session
45
from test_shared.test_utils.database_utils import default_db_url
56
from main import (
@@ -62,6 +63,29 @@ def test_update_feed_status(db_session: Session) -> None:
6263
)
6364

6465

66+
@with_db_session(db_url=default_db_url)
67+
def test_update_feed_status_with_ids(db_session: Session) -> None:
68+
clean_testing_db()
69+
populate_database()
70+
feeds_before: dict[str, PartialFeed] = {f.id: f for f in fetch_feeds(db_session)}
71+
result = dict(update_feed_statuses_query(db_session, ["mdb-8"]))
72+
assert result == {
73+
"inactive": 1,
74+
"active": 0,
75+
"future": 0,
76+
}
77+
78+
feeds_after: dict[str, PartialFeed] = {f.id: f for f in fetch_feeds(db_session)}
79+
expected_status_changes = {
80+
"8": "inactive",
81+
}
82+
for feed_id, feed_before in feeds_before.items():
83+
feed_after = feeds_after[feed_id]
84+
assert feed_after.status == expected_status_changes.get(
85+
feed_id, feed_before.status
86+
)
87+
88+
6589
def test_update_feed_status_failed_query():
6690
mock_session = MagicMock()
6791

0 commit comments

Comments
 (0)