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

Commit 7800983

Browse files
author
Rob Hudson
committed
Filter apps based on our adult/child flags (bug 852567)
1 parent 0bba7ba commit 7800983

File tree

4 files changed

+127
-37
lines changed

4 files changed

+127
-37
lines changed

mkt/constants/regions.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class REGION(object):
1818
1919
slug::
2020
The text that gets stored in the cookie or in ?region=<slug>.
21-
Use the ISO-3166 code please.
21+
Use the ISO-3166 code please.
2222
2323
mcc::
2424
Don't know what an ITU MCC is? They're useful for carrier billing.
@@ -33,6 +33,13 @@ class REGION(object):
3333
3434
weight::
3535
Determines sort order (after slug).
36+
37+
exclude_child::
38+
If true no apps flagged as containing child content will be shown.
39+
40+
exclude_adult::
41+
If true no apps flagged as containing adult content will be shown.
42+
3643
"""
3744
id = None
3845
name = slug = ''
@@ -43,13 +50,16 @@ class REGION(object):
4350
weight = 0
4451
ratingsbodies = ()
4552
has_payments = False
53+
exclude_child = False
54+
exclude_adult = False
4655

4756

4857
class WORLDWIDE(REGION):
4958
id = 1
5059
name = _lazy(u'Worldwide')
5160
slug = 'worldwide'
5261
weight = -1
62+
exclude_child = True
5363

5464

5565
class US(REGION):
@@ -59,6 +69,7 @@ class US(REGION):
5969
mcc = 310
6070
weight = 1
6171
has_payments = True
72+
exclude_child = True
6273

6374

6475
class UK(REGION):
@@ -108,6 +119,7 @@ class VE(REGION):
108119
default_language = 'es'
109120
mcc = 734
110121
has_payments = True
122+
exclude_adult = True
111123

112124

113125
class PL(REGION):
@@ -152,3 +164,8 @@ class PL(REGION):
152164
ALL_REGION_IDS = sorted(REGIONS_CHOICES_ID_DICT.keys())
153165
ALL_PAID_REGION_IDS = sorted(r.id for r in ALL_PAID_REGIONS)
154166
REGION_IDS = sorted(REGIONS_CHOICES_ID_DICT.keys())[1:]
167+
168+
CHILD_EXCLUDED = frozenset(r for r in ALL_REGIONS if r.exclude_child)
169+
CHILD_EXCLUDED_IDS = sorted(r.id for r in CHILD_EXCLUDED)
170+
ADULT_EXCLUDED = frozenset(r for r in ALL_REGIONS if r.exclude_adult)
171+
ADULT_EXCLUDED_IDS = sorted(r.id for r in ADULT_EXCLUDED)

mkt/search/tests/test_api.py

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from nose.tools import eq_
77

88
import amo
9-
from addons.models import AddonCategory, AddonDeviceType, Category
10-
from amo.tests import ESTestCase
119
import mkt.regions
10+
from addons.models import AddonCategory, AddonDeviceType, Category, Flag
11+
from amo.tests import ESTestCase
1212
from mkt.api.base import list_url
1313
from mkt.api.models import Access, generate
1414
from mkt.api.tests.test_oauth import BaseOAuth, OAuthClient
@@ -22,46 +22,46 @@ class TestApi(BaseOAuth, ESTestCase):
2222

2323
def setUp(self):
2424
self.client = OAuthClient(None)
25-
self.list_url = ('api_dispatch_list', {'resource_name': 'search'})
25+
self.url = list_url('search')
2626
self.webapp = Webapp.objects.get(pk=337141)
2727
self.category = Category.objects.create(name='test',
2828
type=amo.ADDON_WEBAPP)
2929
self.webapp.save()
3030
self.refresh()
3131

3232
def test_verbs(self):
33-
self._allowed_verbs(self.list_url, ['get'])
33+
self._allowed_verbs(self.url, ['get'])
3434

3535
def test_has_cors(self):
36-
res = self.client.get(self.list_url)
36+
res = self.client.get(self.url)
3737
eq_(res['Access-Control-Allow-Origin'], '*')
3838
eq_(res['Access-Control-Allow-Methods'], 'GET, OPTIONS')
3939

4040
def test_meta(self):
41-
res = self.client.get(self.list_url)
41+
res = self.client.get(self.url)
4242
eq_(res.status_code, 200)
4343
data = json.loads(res.content)
4444
eq_(set(data.keys()), set(['objects', 'meta']))
4545
eq_(data['meta']['total_count'], 1)
4646

4747
def test_wrong_category(self):
48-
res = self.client.get(self.list_url + ({'cat': self.category.pk + 1},))
48+
res = self.client.get(self.url + ({'cat': self.category.pk + 1},))
4949
eq_(res.status_code, 400)
5050
eq_(res['Content-Type'], 'application/json')
5151

5252
def test_wrong_weight(self):
5353
self.category.update(weight=-1)
54-
res = self.client.get(self.list_url + ({'cat': self.category.pk},))
54+
res = self.client.get(self.url + ({'cat': self.category.pk},))
5555
eq_(res.status_code, 200)
5656
data = json.loads(res.content)
5757
eq_(len(data['objects']), 0)
5858

5959
def test_wrong_sort(self):
60-
res = self.client.get(self.list_url + ({'sort': 'awesomeness'},))
60+
res = self.client.get(self.url + ({'sort': 'awesomeness'},))
6161
eq_(res.status_code, 400)
6262

6363
def test_right_category(self):
64-
res = self.client.get(self.list_url + ({'cat': self.category.pk},))
64+
res = self.client.get(self.url + ({'cat': self.category.pk},))
6565
eq_(res.status_code, 200)
6666
eq_(json.loads(res.content)['objects'], [])
6767

@@ -72,15 +72,15 @@ def create(self):
7272

7373
def test_right_category_present(self):
7474
self.create()
75-
res = self.client.get(self.list_url + ({'cat': self.category.pk},))
75+
res = self.client.get(self.url + ({'cat': self.category.pk},))
7676
eq_(res.status_code, 200)
7777
objs = json.loads(res.content)['objects']
7878
eq_(len(objs), 1)
7979

8080
def test_dehydrate(self):
8181
with self.settings(SITE_URL=''):
8282
self.create()
83-
res = self.client.get(self.list_url + ({'cat': self.category.pk},))
83+
res = self.client.get(self.url + ({'cat': self.category.pk},))
8484
eq_(res.status_code, 200)
8585
obj = json.loads(res.content)['objects'][0]
8686
eq_(obj['slug'], self.webapp.app_slug)
@@ -89,7 +89,7 @@ def test_dehydrate(self):
8989
eq_(obj['resource_uri'], None)
9090

9191
def test_q(self):
92-
res = self.client.get(self.list_url + ({'q': 'something'},))
92+
res = self.client.get(self.url + ({'q': 'something'},))
9393
eq_(res.status_code, 200)
9494
obj = json.loads(res.content)['objects'][0]
9595
eq_(obj['slug'], self.webapp.app_slug)
@@ -99,35 +99,35 @@ def test_device(self):
9999
addon=self.webapp, device_type=DEVICE_CHOICES_IDS['desktop'])
100100
self.webapp.save()
101101
self.refresh()
102-
res = self.client.get(self.list_url + ({'device': 'desktop'},))
102+
res = self.client.get(self.url + ({'device': 'desktop'},))
103103
eq_(res.status_code, 200)
104104
obj = json.loads(res.content)['objects'][0]
105105
eq_(obj['slug'], self.webapp.app_slug)
106106

107107
def test_premium_types(self):
108-
res = self.client.get(self.list_url + (
108+
res = self.client.get(self.url + (
109109
{'premium_types': 'free'},))
110110
eq_(res.status_code, 200)
111111
obj = json.loads(res.content)['objects'][0]
112112
eq_(obj['slug'], self.webapp.app_slug)
113113

114114
def test_premium_types_empty(self):
115-
res = self.client.get(self.list_url + (
115+
res = self.client.get(self.url + (
116116
{'premium_types': 'premium'},))
117117
eq_(res.status_code, 200)
118118
objs = json.loads(res.content)['objects']
119119
eq_(len(objs), 0)
120120

121121
def test_multiple_premium_types(self):
122-
res = self.client.get(self.list_url + (
122+
res = self.client.get(self.url + (
123123
{'premium_types': 'free'},
124124
{'premium_types': 'premium'}))
125125
eq_(res.status_code, 200)
126126
obj = json.loads(res.content)['objects'][0]
127127
eq_(obj['slug'], self.webapp.app_slug)
128128

129129
def test_app_type_hosted(self):
130-
res = self.client.get(self.list_url + ({'app_type': 'hosted'},))
130+
res = self.client.get(self.url + ({'app_type': 'hosted'},))
131131
eq_(res.status_code, 200)
132132
obj = json.loads(res.content)['objects'][0]
133133
eq_(obj['slug'], self.webapp.app_slug)
@@ -137,53 +137,53 @@ def test_app_type_packaged(self):
137137
self.webapp.save()
138138
self.refresh()
139139

140-
res = self.client.get(self.list_url + ({'app_type': 'packaged'},))
140+
res = self.client.get(self.url + ({'app_type': 'packaged'},))
141141
eq_(res.status_code, 200)
142142
obj = json.loads(res.content)['objects'][0]
143143
eq_(obj['slug'], self.webapp.app_slug)
144144

145145
def test_status_anon(self):
146-
res = self.client.get(self.list_url + ({'status': 'public'},))
146+
res = self.client.get(self.url + ({'status': 'public'},))
147147
eq_(res.status_code, 200)
148148
obj = json.loads(res.content)['objects'][0]
149149
eq_(obj['slug'], self.webapp.app_slug)
150150

151-
res = self.client.get(self.list_url + ({'status': 'vindaloo'},))
151+
res = self.client.get(self.url + ({'status': 'vindaloo'},))
152152
eq_(res.status_code, 400)
153153
error = json.loads(res.content)['error_message']
154154
eq_(error.keys(), ['status'])
155155

156-
res = self.client.get(self.list_url + ({'status': 'any'},))
156+
res = self.client.get(self.url + ({'status': 'any'},))
157157
eq_(res.status_code, 401)
158158
eq_(json.loads(res.content)['reason'],
159159
'Unauthorized to filter by status.')
160160

161-
res = self.client.get(self.list_url + ({'status': 'rejected'},))
161+
res = self.client.get(self.url + ({'status': 'rejected'},))
162162
eq_(res.status_code, 401)
163163
eq_(json.loads(res.content)['reason'],
164164
'Unauthorized to filter by status.')
165165

166166
def test_status_value_packaged(self):
167167
# When packaged and not a reviewer we exclude latest version status.
168168
self.webapp.update(is_packaged=True)
169-
res = self.client.get(self.list_url)
169+
res = self.client.get(self.url)
170170
eq_(res.status_code, 200)
171171
obj = json.loads(res.content)['objects'][0]
172172
eq_(obj['status'], amo.STATUS_PUBLIC)
173173
eq_('latest_version_status' in obj, False)
174174

175175
def test_addon_type_anon(self):
176-
res = self.client.get(self.list_url + ({'type': 'app'},))
176+
res = self.client.get(self.url + ({'type': 'app'},))
177177
eq_(res.status_code, 200)
178178
obj = json.loads(res.content)['objects'][0]
179179
eq_(obj['slug'], self.webapp.app_slug)
180180

181-
res = self.client.get(self.list_url + ({'type': 'vindaloo'},))
181+
res = self.client.get(self.url + ({'type': 'vindaloo'},))
182182
eq_(res.status_code, 400)
183183
error = json.loads(res.content)['error_message']
184184
eq_(error.keys(), ['type'])
185185

186-
res = self.client.get(self.list_url + ({'type': 'persona'},))
186+
res = self.client.get(self.url + ({'type': 'persona'},))
187187
eq_(res.status_code, 200)
188188
objs = json.loads(res.content)['objects']
189189
eq_(len(objs), 0)
@@ -201,7 +201,7 @@ def setUp(self, api_name='apps'):
201201
self.access = Access.objects.create(key='foo', secret=generate(),
202202
user=self.user)
203203
self.client = OAuthClient(self.access, api_name=api_name)
204-
self.list_url = ('api_dispatch_list', {'resource_name': 'search'})
204+
self.url = list_url('search')
205205

206206
self.webapp = Webapp.objects.get(pk=337141)
207207
self.category = Category.objects.create(name='test',
@@ -210,47 +210,47 @@ def setUp(self, api_name='apps'):
210210
self.refresh()
211211

212212
def test_status_reviewer(self):
213-
res = self.client.get(self.list_url + ({'status': 'public'},))
213+
res = self.client.get(self.url + ({'status': 'public'},))
214214
eq_(res.status_code, 200)
215215
obj = json.loads(res.content)['objects'][0]
216216
eq_(obj['slug'], self.webapp.app_slug)
217217

218-
res = self.client.get(self.list_url + ({'status': 'rejected'},))
218+
res = self.client.get(self.url + ({'status': 'rejected'},))
219219
eq_(res.status_code, 200)
220220
objs = json.loads(res.content)['objects']
221221
eq_(len(objs), 0)
222222

223-
res = self.client.get(self.list_url + ({'status': 'any'},))
223+
res = self.client.get(self.url + ({'status': 'any'},))
224224
eq_(res.status_code, 200)
225225
obj = json.loads(res.content)['objects'][0]
226226
eq_(obj['slug'], self.webapp.app_slug)
227227

228-
res = self.client.get(self.list_url + ({'status': 'vindaloo'},))
228+
res = self.client.get(self.url + ({'status': 'vindaloo'},))
229229
eq_(res.status_code, 400)
230230
error = json.loads(res.content)['error_message']
231231
eq_(error.keys(), ['status'])
232232

233233
def test_status_value_packaged(self):
234234
# When packaged we also include the latest version status.
235235
self.webapp.update(is_packaged=True)
236-
res = self.client.get(self.list_url)
236+
res = self.client.get(self.url)
237237
eq_(res.status_code, 200)
238238
obj = json.loads(res.content)['objects'][0]
239239
eq_(obj['status'], amo.STATUS_PUBLIC)
240240
eq_(obj['latest_version_status'], amo.STATUS_PUBLIC)
241241

242242
def test_addon_type_reviewer(self):
243-
res = self.client.get(self.list_url + ({'type': 'app'},))
243+
res = self.client.get(self.url + ({'type': 'app'},))
244244
eq_(res.status_code, 200)
245245
obj = json.loads(res.content)['objects'][0]
246246
eq_(obj['slug'], self.webapp.app_slug)
247247

248-
res = self.client.get(self.list_url + ({'type': 'persona'},))
248+
res = self.client.get(self.url + ({'type': 'persona'},))
249249
eq_(res.status_code, 200)
250250
objs = json.loads(res.content)['objects']
251251
eq_(len(objs), 0)
252252

253-
res = self.client.get(self.list_url + ({'type': 'vindaloo'},))
253+
res = self.client.get(self.url + ({'type': 'vindaloo'},))
254254
eq_(res.status_code, 400)
255255
error = json.loads(res.content)['error_message']
256256
eq_(error.keys(), ['type'])
@@ -289,3 +289,44 @@ def test_no_category(self):
289289
data = json.loads(res.content)
290290
eq_(len(data['objects']), 2)
291291
eq_(len(data['creatured']), 0)
292+
293+
294+
class TestApiFlags(BaseOAuth, ESTestCase):
295+
fixtures = fixture('webapp_337141')
296+
url = list_url('search')
297+
298+
def setUp(self):
299+
self.client = OAuthClient(None)
300+
self.webapp = Webapp.objects.get(pk=337141)
301+
302+
def _flag(self, adult=False, child=False):
303+
Flag.objects.create(addon=self.webapp, adult_content=adult,
304+
child_content=child)
305+
self.webapp.save()
306+
self.refresh()
307+
308+
def test_no_flags(self):
309+
self.webapp.save()
310+
self.refresh()
311+
res = self.client.get(self.url + ({'q': 'something'},))
312+
eq_(res.status_code, 200)
313+
obj = json.loads(res.content)['objects'][0]
314+
eq_(obj['slug'], self.webapp.app_slug)
315+
316+
def test_adult(self):
317+
self._flag(adult=True)
318+
res = self.client.get(self.url + (
319+
{'q': 'something',
320+
'region': list(mkt.regions.ADULT_EXCLUDED)[0].slug},))
321+
eq_(res.status_code, 200)
322+
objs = json.loads(res.content)['objects']
323+
eq_(len(objs), 0, 'App with adult_content not removed from search.')
324+
325+
def test_child(self):
326+
self._flag(child=True)
327+
res = self.client.get(self.url + (
328+
{'q': 'something',
329+
'region': list(mkt.regions.CHILD_EXCLUDED)[0].slug},))
330+
eq_(res.status_code, 200)
331+
objs = json.loads(res.content)['objects']
332+
eq_(len(objs), 0, 'App with child_content not removed from search.')

0 commit comments

Comments
 (0)