Skip to content

Commit

Permalink
feat(storage): implement get_posts_by_created_at_end
Browse files Browse the repository at this point in the history
  • Loading branch information
osoken committed Mar 24, 2024
1 parent bb90f5f commit 41ff678
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion birdxplorer/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def get_posts_by_created_at_start(self, start: TwitterTimestamp) -> Generator[Po
yield self._post_record_to_model(post_record)

def get_posts_by_created_at_end(self, end: TwitterTimestamp) -> Generator[PostModel, None, None]:
raise NotImplementedError
with Session(self.engine) as sess:
for post_record in sess.query(PostRecord).filter(PostRecord.created_at < end).all():
yield self._post_record_to_model(post_record)


def gen_storage(settings: GlobalSettings) -> Storage:
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _get_posts_by_ids(post_ids: List[PostId]) -> Generator[Post, None, None]:

def _get_posts_by_created_at_range(start: TwitterTimestamp, end: TwitterTimestamp) -> Generator[Post, None, None]:
for post in post_samples:
if start <= post.created_at <= end:
if start <= post.created_at < end:
yield post

mock.get_posts_by_created_at_range.side_effect = _get_posts_by_created_at_range
Expand All @@ -161,7 +161,7 @@ def _get_posts_by_created_at_start(start: TwitterTimestamp) -> Generator[Post, N

def _get_posts_by_created_at_end(end: TwitterTimestamp) -> Generator[Post, None, None]:
for post in post_samples:
if post.created_at <= end:
if post.created_at < end:
yield post

mock.get_posts_by_created_at_end.side_effect = _get_posts_by_created_at_end
Expand Down
14 changes: 14 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,17 @@ def test_get_posts_by_created_at_start(
expected = [post_samples[i] for i in (1, 2)]
actual = list(storage.get_posts_by_created_at_start(start))
assert expected == actual


def test_get_posts_by_created_at_end(
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)
end = TwitterTimestamp.from_int(1153921700000)
expected = [post_samples[i] for i in (0,)]
actual = list(storage.get_posts_by_created_at_end(end))
assert expected == actual

0 comments on commit 41ff678

Please sign in to comment.