Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Report false for can_rate for non-purchased paid apps. (bug 882774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Short committed Jun 19, 2013
1 parent aa3d9b0 commit 061fc24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mkt/ratings/resources.py
Expand Up @@ -204,7 +204,11 @@ def alter_list_data_to_serialize(self, request, data):
if not request.user.is_anonymous():
filters['user'] = request.user
existing_review = Review.objects.valid().filter(**filters)
data['user'] = {'can_rate': not addon.has_author(request.user),
if addon.is_premium():
can_rate = addon.has_purchased(request.amo_user)
else:
can_rate = not addon.has_author(request.user)
data['user'] = {'can_rate': can_rate,
'has_rated': existing_review.exists()}
else:
data['user'] = None
Expand Down
18 changes: 18 additions & 0 deletions mkt/ratings/tests/test_resources.py
Expand Up @@ -6,6 +6,7 @@
import amo
from addons.models import AddonUser
from amo.tests import AMOPaths
from market.models import AddonPurchase
from reviews.models import Review, ReviewFlag
from users.models import UserProfile

Expand Down Expand Up @@ -156,6 +157,17 @@ def test_already_rated(self):
assert data['user']['can_rate']
assert data['user']['has_rated']

def test_can_rate_unpurchased(self):
self.app.update(premium_type=amo.ADDON_PREMIUM)
res = self.client.get(self._collection_url())
assert not res.json['user']['can_rate']

def test_can_rate_purchased(self):
self.app.update(premium_type=amo.ADDON_PREMIUM)
AddonPurchase.objects.create(addon=self.app, user=self.user)
res = self.client.get(self._collection_url())
assert res.json['user']['can_rate']

def _create(self, data=None, anonymous=False):
default_data = {
'app': self.app.id,
Expand Down Expand Up @@ -215,6 +227,12 @@ def test_rate_unpurchased_premium(self):
res, data = self._create()
eq_(403, res.status_code)

def test_rate_purchased_premium(self):
self.app.update(premium_type=amo.ADDON_PREMIUM)
AddonPurchase.objects.create(addon=self.app, user=self.user)
res, data = self._create()
eq_(201, res.status_code)

def _update(self, updated_data):
# Create the original review
default_data = {
Expand Down

0 comments on commit 061fc24

Please sign in to comment.