From e673518371ecdb08bb1f26997f6c57e14083e186 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Tue, 8 Feb 2022 20:50:37 +0530 Subject: [PATCH 1/4] Some misc minor fixes --- critiquebrainz/frontend/templates/macros.html | 23 +++++++++++++------ .../frontend/templates/user/reviews.html | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/critiquebrainz/frontend/templates/macros.html b/critiquebrainz/frontend/templates/macros.html index 92c74bb96..c2ea433fd 100644 --- a/critiquebrainz/frontend/templates/macros.html +++ b/critiquebrainz/frontend/templates/macros.html @@ -225,28 +225,37 @@

{{ _('Rate this {}:'.format(entity_type_readable)) {% set total_pages = (count/limit)|round(method='ceil')|int %} {% if count > limit %}
-
diff --git a/critiquebrainz/frontend/templates/user/reviews.html b/critiquebrainz/frontend/templates/user/reviews.html index 73b41f780..46363ff08 100644 --- a/critiquebrainz/frontend/templates/user/reviews.html +++ b/critiquebrainz/frontend/templates/user/reviews.html @@ -16,7 +16,7 @@ {{ _('Created on') }} {{ _('Published on')}} {{ _('Votes (+/-)') }} - {{ _('Rating') }} + {{ _('Rating') }} {% if current_user.is_authenticated and current_user == user %} {% endif %} From 8c062aa1c779a20732c62788878e61a1327fe868 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Tue, 8 Feb 2022 21:39:11 +0530 Subject: [PATCH 2/4] fix doc of review_list_handler --- critiquebrainz/ws/review/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/critiquebrainz/ws/review/views.py b/critiquebrainz/ws/review/views.py index 4b06267c9..5fe0bf118 100644 --- a/critiquebrainz/ws/review/views.py +++ b/critiquebrainz/ws/review/views.py @@ -335,8 +335,8 @@ def review_list_handler(): ] } - :json uuid entity_id: UUID of the entity that is being reviewed - :json string entity_type: One of the supported reviewable entities. :data:`critiquebrainz.db.review.ENTITY_TYPES` **(optional)** + :query entity_id: UUID of the entity that is being reviewed + :query entity_type: One of the supported reviewable entities. :data:`critiquebrainz.db.review.ENTITY_TYPES` **(optional)** :query user_id: user's UUID **(optional)** :query sort: ``popularity`` or ``published_on`` **(optional)** :query limit: results limit, min is 0, max is 50, default is 50 **(optional)** From 76bb90422b40701c2f0e643bdb431e864cb3f00c Mon Sep 17 00:00:00 2001 From: Alastair Porter Date: Tue, 8 Feb 2022 18:02:51 +0100 Subject: [PATCH 3/4] Improve docstrings and docs --- critiquebrainz/db/review.py | 4 ++-- critiquebrainz/ws/review/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/critiquebrainz/db/review.py b/critiquebrainz/db/review.py index c1a045c99..2e1e8fd7d 100644 --- a/critiquebrainz/db/review.py +++ b/critiquebrainz/db/review.py @@ -525,8 +525,8 @@ def list_reviews(*, inc_drafts=False, inc_hidden=False, entity_id=None, entity_t inc_drafts (bool): True if reviews marked as drafts should be included, False if not. inc_hidden (bool): True if reviews marked as hidden should be included, False if not. exclude (list): List of reviews (their IDs) to exclude from results. - review_type (str): Filter reviews. Can either be "review"(for reviews with only text), or "rating" (for - reviews with only rating), or "None" (for all reviews). + review_type (str): Return reviews of this type. Can either be "review" (to return reviews with text), + or "rating" (to return reviews which have a rating), or ``None`` (to return all reviews). Returns: Tuple with two values: diff --git a/critiquebrainz/ws/review/views.py b/critiquebrainz/ws/review/views.py index 5fe0bf118..82bd99abe 100644 --- a/critiquebrainz/ws/review/views.py +++ b/critiquebrainz/ws/review/views.py @@ -335,14 +335,14 @@ def review_list_handler(): ] } - :query entity_id: UUID of the entity that is being reviewed + :query entity_id: UUID of an entity to retrieve reviews for **(optional)** :query entity_type: One of the supported reviewable entities. :data:`critiquebrainz.db.review.ENTITY_TYPES` **(optional)** :query user_id: user's UUID **(optional)** :query sort: ``popularity`` or ``published_on`` **(optional)** :query limit: results limit, min is 0, max is 50, default is 50 **(optional)** :query offset: result offset, default is 0 **(optional)** :query language: language code (ISO 639-1) **(optional)** - :query review_type: ``review`` or ``rating`` **(optional)** + :query review_type: ``review`` or ``rating``. If set, only return reviews which have a text review, or a rating **(optional)** :resheader Content-Type: *application/json* """ From dc9353f85c85b1d9a6fa62b0029faf4a24afc0c8 Mon Sep 17 00:00:00 2001 From: Alastair Porter Date: Tue, 8 Feb 2022 18:03:14 +0100 Subject: [PATCH 4/4] Test a large amount of different types of reviews --- critiquebrainz/ws/review/test/views_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/critiquebrainz/ws/review/test/views_test.py b/critiquebrainz/ws/review/test/views_test.py index 53fa42188..9bee2546d 100644 --- a/critiquebrainz/ws/review/test/views_test.py +++ b/critiquebrainz/ws/review/test/views_test.py @@ -112,6 +112,10 @@ def test_review_type(self): self.assertCountEqual(actual_review_ids, expected_review_ids) def test_review_large_count(self): + """Test that retrieving reviews of a particular type correctly returns the total number of + reviews of this type in addition to the paged results""" + + # 100 text reviews and 1 rating for _ in range(100): review = dict( entity_id=uuid.uuid4(), @@ -122,6 +126,19 @@ def test_review_large_count(self): license_id=self.license["id"], ) db_review.create(**review) + + db_review.create( + entity_id="2b3abc25-7453-39f3-86c4-1441f360e121", + entity_type='release_group', + user_id=self.user.id, + rating=5, + is_draft=False, + license_id=self.license["id"], + ) + resp = self.client.get('/review/') + self.assert200(resp) + self.assertEqual(resp.json["count"], 101) + resp = self.client.get('/review/', query_string={'review_type': 'review'}) self.assert200(resp) self.assertEqual(resp.json["count"], 100)