Skip to content

Commit

Permalink
Merge branch 'main' into feat/issue-99-improve-posts
Browse files Browse the repository at this point in the history
  • Loading branch information
osoken authored Aug 24, 2024
2 parents 3596ad8 + 6889587 commit 9421fca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions api/birdxplorer_api/routers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ def get_posts(
request: Request,
post_id: Union[List[PostId], None] = Query(default=None),
note_id: Union[List[NoteId], None] = Query(default=None),
created_at_start: Union[None, TwitterTimestamp, str] = Query(default=None),
created_at_end: Union[None, TwitterTimestamp, str] = Query(default=None),
created_at_from: Union[None, TwitterTimestamp, str] = Query(default=None),
created_at_to: Union[None, TwitterTimestamp, str] = Query(default=None),
offset: int = Query(default=0, ge=0),
limit: int = Query(default=100, gt=0, le=1000),
search_text: Union[None, str] = Query(default=None),
) -> PostListResponse:
if created_at_start is not None and isinstance(created_at_start, str):
created_at_start = ensure_twitter_timestamp(created_at_start)
if created_at_end is not None and isinstance(created_at_end, str):
created_at_end = ensure_twitter_timestamp(created_at_end)
if created_at_from is not None and isinstance(created_at_from, str):
created_at_from = ensure_twitter_timestamp(created_at_from)
if created_at_to is not None and isinstance(created_at_to, str):
created_at_to = ensure_twitter_timestamp(created_at_to)
posts = list(
storage.get_posts(
post_ids=post_id,
note_ids=note_id,
start=created_at_start,
end=created_at_end,
start=created_at_from,
end=created_at_to,
search_text=search_text,
offset=offset,
limit=limit,
Expand All @@ -120,8 +120,8 @@ def get_posts(
total_count = storage.get_number_of_posts(
post_ids=post_id,
note_ids=note_id,
start=created_at_start,
end=created_at_end,
start=created_at_from,
end=created_at_to,
search_text=search_text,
)

Expand Down
14 changes: 7 additions & 7 deletions api/tests/routers/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def test_posts_get_has_note_id_filter(client: TestClient, post_samples: List[Pos


def test_posts_get_has_created_at_filter_start_and_end(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtStart=2006-7-25 00:00:00&createdAtEnd=2006-7-30 23:59:59")
response = client.get("/api/v1/data/posts/?createdAtFrom=2006-7-25 00:00:00&createdAtTo=2006-7-30 23:59:59")
assert response.status_code == 200
res_json = response.json()
assert res_json == {"data": [json.loads(post_samples[1].model_dump_json())], "meta": {"next": None, "prev": None}}


def test_posts_get_has_created_at_filter_start(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtStart=2006-7-25 00:00:00")
response = client.get("/api/v1/data/posts/?createdAtFrom=2006-7-25 00:00:00")
assert response.status_code == 200
res_json = response.json()
assert res_json == {
Expand All @@ -78,7 +78,7 @@ def test_posts_get_has_created_at_filter_start(client: TestClient, post_samples:


def test_posts_get_has_created_at_filter_end(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtEnd=2006-7-30 00:00:00")
response = client.get("/api/v1/data/posts/?createdAtTo=2006-7-30 00:00:00")
assert response.status_code == 200
res_json = response.json()
assert res_json == {
Expand All @@ -88,14 +88,14 @@ def test_posts_get_has_created_at_filter_end(client: TestClient, post_samples: L


def test_posts_get_created_at_range_filter_accepts_integer(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtStart=1153921700000&createdAtEnd=1154921800000")
response = client.get("/api/v1/data/posts/?createdAtFrom=1153921700000&createdAtTo=1154921800000")
assert response.status_code == 200
res_json = response.json()
assert res_json == {"data": [json.loads(post_samples[1].model_dump_json())], "meta": {"next": None, "prev": None}}


def test_posts_get_created_at_start_filter_accepts_integer(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtStart=1153921700000")
response = client.get("/api/v1/data/posts/?createdAtFrom=1153921700000")
assert response.status_code == 200
res_json = response.json()
assert res_json == {
Expand All @@ -105,7 +105,7 @@ def test_posts_get_created_at_start_filter_accepts_integer(client: TestClient, p


def test_posts_get_created_at_end_filter_accepts_integer(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtEnd=1154921800000")
response = client.get("/api/v1/data/posts/?createdAtTo=1154921800000")
assert response.status_code == 200
res_json = response.json()
assert res_json == {
Expand All @@ -115,7 +115,7 @@ def test_posts_get_created_at_end_filter_accepts_integer(client: TestClient, pos


def test_posts_get_timestamp_out_of_range(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?createdAtStart=1153921700&createdAtEnd=1153921700")
response = client.get("/api/v1/data/posts/?createdAtFrom=1153921700&createdAtTo=1153921700")
assert response.status_code == 422


Expand Down

0 comments on commit 9421fca

Please sign in to comment.