Skip to content

Commit

Permalink
fix: fix test for top query
Browse files Browse the repository at this point in the history
  • Loading branch information
hyukychang committed Nov 28, 2024
1 parent 1bf8c29 commit 3b95dee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/core/views/viewsets/article.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import time

from django.core.paginator import Paginator as DjangoPaginator
from django.db import models
Expand Down
11 changes: 8 additions & 3 deletions tests/test_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,23 +723,28 @@ def test_top_ordered(self):
board = Board.objects.create()
articles = [
Article.objects.create(created_by=self.user, parent_board=board)
for _ in range(3)
for _ in range(5)
]

time_early = timezone.datetime(2001, 10, 18) # retro's birthday
time_late = timezone.datetime(2003, 6, 17) # yuwol's birthday

time_now = timezone.now()

articles[0].topped_at = time_early
articles[1].topped_at = time_early
articles[2].topped_at = time_late
articles[3].topped_at = time_now
articles[4].topped_at = time_now

for article in articles:
article.save()

response = self.http_request(self.user, "get", "articles/top")
assert response.status_code == status.HTTP_200_OK
assert response.data["num_items"] == 3
assert response.data["num_items"] == 2

oracle_indices = [2, 1, 0]
oracle_indices = [5, 4]
for idx, res in zip(oracle_indices, response.data["results"]):
assert articles[idx].pk == res["id"]

Expand Down

0 comments on commit 3b95dee

Please sign in to comment.