From bb90f5f4e0b27b30445576208c9a915a5b73777d Mon Sep 17 00:00:00 2001 From: osoken Date: Sun, 24 Mar 2024 22:23:45 +0900 Subject: [PATCH] feat(storage): implement get_posts_by_created_at_start --- birdxplorer/storage.py | 4 +++- tests/test_storage.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/birdxplorer/storage.py b/birdxplorer/storage.py index f7c2c36..f30fd84 100644 --- a/birdxplorer/storage.py +++ b/birdxplorer/storage.py @@ -170,7 +170,9 @@ def get_posts_by_created_at_range( yield self._post_record_to_model(post_record) def get_posts_by_created_at_start(self, start: TwitterTimestamp) -> Generator[PostModel, None, None]: - raise NotImplementedError + with Session(self.engine) as sess: + for post_record in sess.query(PostRecord).filter(PostRecord.created_at >= start).all(): + yield self._post_record_to_model(post_record) def get_posts_by_created_at_end(self, end: TwitterTimestamp) -> Generator[PostModel, None, None]: raise NotImplementedError diff --git a/tests/test_storage.py b/tests/test_storage.py index 53f4c61..97f96f7 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -72,3 +72,17 @@ def test_get_posts_by_created_at_range( expected = [post_samples[i] for i in (1,)] actual = list(storage.get_posts_by_created_at_range(start, end)) assert expected == actual + + +def test_get_posts_by_created_at_start( + engine_for_test: Engine, + post_samples: List[Post], + post_records_sample: List[PostRecord], + topic_records_sample: List[TopicRecord], + note_records_sample: List[NoteRecord], +) -> None: + storage = Storage(engine=engine_for_test) + start = TwitterTimestamp.from_int(1153921700000) + expected = [post_samples[i] for i in (1, 2)] + actual = list(storage.get_posts_by_created_at_start(start)) + assert expected == actual