Skip to content

Commit

Permalink
Merge pull request #371 from jdaok/fix-post-review-api
Browse files Browse the repository at this point in the history
Fix post review API
  • Loading branch information
amCap1712 authored Aug 22, 2021
2 parents 63f014f + c180621 commit 1260411
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 13 additions & 0 deletions critiquebrainz/ws/review/test/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ def test_review_post(self):
resp = self.client.post('/review/', headers=self.header(self.another_user), data=json.dumps(review_2))
self.assert400(resp, "Review must have either text or rating")

# test writing a normal review works using the API. this test may not look useful but interestingly,
# writing a review using the API was broken for at least a year and no one seemed to notice or report
# it. so here it is, a test to write a valid review using the API.
review_3 = dict(
entity_id=self.review['entity_id'],
entity_type='release_group',
license_choice=self.license["id"],
language='en',
text="Hello, World! Let's write a long long long even longer the longest review........................"
)
resp = self.client.post('/review/', headers=self.header(self.another_user), data=json.dumps(review_3))
self.assert200(resp)

def test_review_vote_entity(self):
review = self.create_dummy_review()
resp = self.client.get('/review/%s/vote' % review["id"], headers=self.header(self.user))
Expand Down
5 changes: 2 additions & 3 deletions critiquebrainz/ws/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,10 @@ def review_post_handler(user):

def fetch_params():
is_draft = Parser.bool('json', 'is_draft', optional=True) or False
if is_draft:
REVIEW_TEXT_MIN_LENGTH = None
min_review_length = None if is_draft else REVIEW_TEXT_MIN_LENGTH
entity_id = Parser.uuid('json', 'entity_id')
entity_type = Parser.string('json', 'entity_type', valid_values=ENTITY_TYPES)
text = Parser.string('json', 'text', min=REVIEW_TEXT_MIN_LENGTH, max=REVIEW_TEXT_MAX_LENGTH, optional=True)
text = Parser.string('json', 'text', min=min_review_length, max=REVIEW_TEXT_MAX_LENGTH, optional=True)
rating = Parser.int('json', 'rating', min=REVIEW_RATING_MIN, max=REVIEW_RATING_MAX, optional=True)
license_choice = Parser.string('json', 'license_choice')
language = Parser.string('json', 'language', min=2, max=3, optional=True) or 'en'
Expand Down

0 comments on commit 1260411

Please sign in to comment.