Skip to content

Commit

Permalink
[back] tests: re-add the test test_anon_can_list_with_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
GresilleSiffle committed May 2, 2024
1 parent 605fa49 commit b61d619
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
26 changes: 23 additions & 3 deletions backend/tournesol/tests/test_api_polls.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,30 @@ def test_anonymous_can_list_unsafe_recommendations(self):
}
)

def test_anonymous_can_list_with_offset(self):
def test_anon_can_list_with_limit(self):
"""
An anonymous user can list a subset of videos by using the `offset`
query parameter.
An anonymous user can list a subset of recommendations by using the
`limit` query parameter.
"""
response = self.client.get("/polls/videos/recommendations/?limit=1")
results = response.data["results"]

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]), 1)
self.assertEqual(results[0]["collective_rating"]["tournesol_score"], 44.0)

response = self.client.get("/polls/videos/recommendations/?limit=2")
results = response.data["results"]

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]), 2)
self.assertEqual(results[0]["collective_rating"]["tournesol_score"], 44.0)
self.assertEqual(results[1]["collective_rating"]["tournesol_score"], 33.0)

def test_anon_can_list_with_offset(self):
"""
An anonymous user can list a subset of recommendations by using the
`offset` query parameter.
"""
response = self.client.get("/polls/videos/recommendations/?offset=2")
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down
9 changes: 0 additions & 9 deletions backend/tournesol/tests/test_api_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from core.models import User
from tournesol.entities.video import YOUTUBE_UID_NAMESPACE
from tournesol.tests.factories.entity import VideoCriteriaScoreFactory, VideoFactory
from tournesol.tests.factories.entity_poll_rating import EntityPollRatingFactory
from tournesol.utils.video_language import compute_video_language

from ..models import Entity
Expand Down Expand Up @@ -56,14 +55,6 @@ def setUp(self):
VideoCriteriaScoreFactory(entity=self.video_3, criteria="importance", score=0.3)
VideoCriteriaScoreFactory(entity=self.video_4, criteria="importance", score=0.4)

def test_anonymous_can_list_with_limit(self):
"""
An anonymous user can list a subset of videos by using the `limit`
query parameter.
"""
# TODO: ensure this feature is tested by the API /polls/{name}/recommendations/
pass

def test_anonymous_can_list_with_pagination(self):
"""
An anonymous user can list a subset of videos by using all pagination
Expand Down

0 comments on commit b61d619

Please sign in to comment.