Skip to content

Commit

Permalink
feat(storage): implement get_posts_by_created_at_start
Browse files Browse the repository at this point in the history
  • Loading branch information
osoken committed Mar 24, 2024
1 parent df585ff commit bb90f5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion birdxplorer/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bb90f5f

Please sign in to comment.