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

Commit 4bb35c5

Browse files
author
Rob Hudson
committed
Added adult/child flags to search index (bug 852567)
1 parent 10afadc commit 4bb35c5

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

apps/addons/search.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import amo
1111
from amo.utils import create_es_index_if_missing
12-
from .models import Addon
12+
from .models import Addon, Flag
1313
from bandwagon.models import Collection
1414
from compat.models import AppCompat
1515
from stats.models import ClientData
@@ -60,6 +60,12 @@ def extract(addon):
6060
except ObjectDoesNotExist:
6161
d['has_version'] = None
6262
d['app'] = [app.id for app in addon.compatible_apps.keys()]
63+
try:
64+
d['flag_adult'] = addon.flag.adult_content
65+
d['flag_child'] = addon.flag.child_content
66+
except Flag.DoesNotExist:
67+
d['flag_adult'] = d['flag_child'] = False
68+
6369
if addon.type == amo.ADDON_PERSONA:
6470
# This would otherwise get attached when by the transformer.
6571
d['weekly_downloads'] = addon.persona.popularity

apps/addons/tests/test_search.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from nose.tools import eq_
2+
3+
import amo.tests
4+
from addons.models import Addon, Flag
5+
from addons.search import extract
6+
from addons.tasks import (attach_categories, attach_devices, attach_prices,
7+
attach_tags, attach_translations)
8+
9+
10+
class TestExtract(amo.tests.TestCase):
11+
fixtures = ['base/apps', 'base/users', 'base/addon_3615']
12+
13+
def setUp(self):
14+
self.attrs = ('id', 'slug', 'app_slug', 'created', 'last_updated',
15+
'weekly_downloads', 'average_daily_users', 'status',
16+
'type', 'hotness', 'is_disabled', 'premium_type',
17+
'uses_flash')
18+
self.transforms = (attach_categories, attach_devices, attach_prices,
19+
attach_tags, attach_translations)
20+
21+
def _extract(self):
22+
qs = Addon.objects.filter(id__in=[3615])
23+
for t in self.transforms:
24+
qs = qs.transform(t)
25+
self.addon = list(qs)[0]
26+
return extract(self.addon)
27+
28+
def test_extract_attributes(self):
29+
extracted = self._extract()
30+
for attr in self.attrs:
31+
eq_(extracted[attr], getattr(self.addon, attr))
32+
33+
def test_flags(self):
34+
Flag.objects.create(addon_id=3615, adult_content=True,
35+
child_content=False)
36+
extracted = self._extract()
37+
eq_(extracted['flag_adult'], True)
38+
eq_(extracted['flag_child'], False)
39+
40+
def test_no_flags(self):
41+
extracted = self._extract()
42+
eq_(extracted['flag_adult'], False)
43+
eq_(extracted['flag_child'], False)

0 commit comments

Comments
 (0)