def test_adolescent_popularity(self): """ Adolescent regions use global popularity. Webapp: Global: 0, Regional: 0 Unknown1: Global: 1, Regional: 1 + 10 * 1 = 11 Unknown2: Global: 2, Regional: 0 """ user = UserProfile.objects.all()[0] cd = ClientData.objects.create(region=mkt.regions.BR.id) unknown1 = amo.tests.app_factory() Installed.objects.create(addon=unknown1, user=user, client_data=cd) unknown2 = amo.tests.app_factory() Installed.objects.create(addon=unknown2, user=user) Installed.objects.create(addon=unknown2, user=user) self.reindex(Webapp, 'webapp') res = self.client.get(self.url + ({'region': 'br'}, )) eq_(res.status_code, 200) objects = res.json['objects'] eq_(len(objects), 3) eq_(int(objects[0]['id']), unknown2.id) eq_(int(objects[1]['id']), unknown1.id) eq_(int(objects[2]['id']), self.webapp.id) # Cleanup to remove these from the index. unindex_webapps([unknown1.id, unknown2.id]) unknown1.delete() unknown2.delete()
def test_adolescent_popularity(self): """ Adolescent regions use global popularity. Webapp: Global: 0, Regional: 0 Unknown1: Global: 1, Regional: 1 + 10 * 1 = 11 Unknown2: Global: 2, Regional: 0 """ # TODO: help from robhudson. raise SkipTest unknown1 = amo.tests.app_factory() unknown2 = amo.tests.app_factory() self.reindex(Webapp, 'webapp') res = self.client.get(self.url, data={'region': 'br'}) eq_(res.status_code, 200) objects = res.json['objects'] eq_(len(objects), 3) eq_(int(objects[0]['id']), unknown2.id) eq_(int(objects[1]['id']), unknown1.id) eq_(int(objects[2]['id']), self.webapp.id) # Cleanup to remove these from the index. unknown1.delete() unknown2.delete() unindex_webapps([unknown1.id, unknown2.id])
def tearDownClass(cls): if hasattr(cls, '_addons'): Addon.objects.filter(pk__in=[a.id for a in cls._addons]).delete() unindex_webapps([a.id for a in cls._addons if a.type == amo.ADDON_WEBAPP]) unindex_addons([a.id for a in cls._addons if a.type != amo.ADDON_WEBAPP])
def test_suggestions(self): app1 = Webapp.objects.get(pk=337141) app1.save() app2 = app_factory(name=u"Second âpp", description=u"Second dèsc" * 25, created=self.days_ago(3)) self.refresh('webapp') response = self.client.get(self.url) parsed = json.loads(response.content) eq_(parsed[0], '') self.assertSetEqual( parsed[1], [unicode(app1.name), unicode(app2.name)]) self.assertSetEqual( parsed[2], [unicode(app1.description), unicode(truncate(app2.description))]) self.assertSetEqual(parsed[3], [ absolutify(app1.get_detail_url()), absolutify(app2.get_detail_url()) ]) self.assertSetEqual(parsed[4], [app1.get_icon_url(64), app2.get_icon_url(64)]) # Cleanup to remove these from the index. unindex_webapps([app1.id, app2.id]) app1.delete() app2.delete()
def test_adolescent_popularity(self): """ Adolescent regions use global popularity. Webapp: Global: 0, Regional: 0 Unknown1: Global: 1, Regional: 1 + 10 * 1 = 11 Unknown2: Global: 2, Regional: 0 """ user = UserProfile.objects.all()[0] cd = ClientData.objects.create(region=mkt.regions.BR.id) unknown1 = amo.tests.app_factory() Installed.objects.create(addon=unknown1, user=user, client_data=cd) unknown2 = amo.tests.app_factory() Installed.objects.create(addon=unknown2, user=user) Installed.objects.create(addon=unknown2, user=user) self.reindex(Webapp, 'webapp') res = self.client.get(self.url, data={'region': 'br'}) eq_(res.status_code, 200) objects = res.json['objects'] eq_(len(objects), 3) eq_(int(objects[0]['id']), unknown2.id) eq_(int(objects[1]['id']), unknown1.id) eq_(int(objects[2]['id']), self.webapp.id) # Cleanup to remove these from the index. unindex_webapps([unknown1.id, unknown2.id]) unknown1.delete() unknown2.delete()
def tearDown(self): # Cleanup to remove these from the index. self.app1.delete() self.app2.delete() unindex_webapps([self.app1.id, self.app2.id]) # Required to purge the suggestions data structure. In Lucene, a # document is not deleted from a segment, just marked as deleted. WebappIndexer.get_es().indices.optimize(index=WebappIndexer.get_index(), only_expunge_deletes=True)
def tearDown(self): # Cleanup to remove these from the index. self.app1.delete() self.app2.delete() unindex_webapps([self.app1.id, self.app2.id]) # Required to purge the suggestions data structure. In Lucene, a # document is not deleted from a segment, just marked as deleted. WebappIndexer.get_es().optimize(WebappIndexer.get_index(), only_expunge_deletes=True)
def test_no_category(self): app2 = app_factory() self.make_featured(app=app2, category=self.cat) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) unindex_webapps([app2.id]) app2.delete()
def test_no_category(self): app2 = app_factory() self.make_featured(app=app2, category=self.cat) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs,)) eq_(res.status_code, 200) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) unindex_webapps([app2.id]) app2.delete()
def tearDownClass(cls): try: if hasattr(cls, "_addons"): Addon.objects.filter(pk__in=[a.id for a in cls._addons]).delete() unindex_webapps([a.id for a in cls._addons if a.type == amo.ADDON_WEBAPP]) amo.SEARCH_ANALYZER_MAP = cls._SEARCH_ANALYZER_MAP finally: # Make sure we're calling super's tearDownClass even if something # went wrong in the code above, as otherwise we'd run into bug # 960598. super(ESTestCase, cls).tearDownClass()
def tearDownClass(cls): try: if hasattr(cls, '_addons'): Webapp.objects.filter(pk__in=[a.id for a in cls._addons]).delete() unindex_webapps([a.id for a in cls._addons]) amo.SEARCH_ANALYZER_MAP = cls._SEARCH_ANALYZER_MAP finally: # Make sure we're calling super's tearDownClass even if something # went wrong in the code above, as otherwise we'd run into bug # 960598. super(ESTestCase, cls).tearDownClass()
def test_featured_plus_category(self): app2 = amo.tests.app_factory() AddonCategory.objects.get_or_create(addon=app2, category=self.cat) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs,)) eq_(res.status_code, 200) eq_(len(res.json['objects']), 2) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) unindex_webapps([app2.id]) app2.delete()
def test_featured_plus_category(self): app2 = amo.tests.app_factory() AddonCategory.objects.get_or_create(addon=app2, category=self.cat) self.reindex(Webapp, 'webapp') res = self.client.get(self.list_url + (self.qs, )) eq_(res.status_code, 200) eq_(len(res.json['objects']), 2) eq_(len(res.json['featured']), 1) eq_(int(res.json['featured'][0]['id']), self.app.pk) unindex_webapps([app2.id]) app2.delete()
def test_q_exact(self): app1 = app_factory(name='test app test11') app2 = app_factory(name='test app test21') app3 = app_factory(name='test app test31') self.refresh('webapp') res = self.client.get(self.url, data={'q': 'test app test21'}) eq_(res.status_code, 200) eq_(len(res.json['objects']), 3) # app2 should be first since it's an exact match and is boosted higher. obj = res.json['objects'][0] eq_(obj['slug'], app2.app_slug) unindex_webapps([app1.id, app2.id, app3.id]) app1.delete() app2.delete() app3.delete()
def test_q_exact(self): app1 = app_factory(name='test app test11') app2 = app_factory(name='test app test21') app3 = app_factory(name='test app test31') self.refresh('webapp') res = self.client.get(self.url + ({'q': 'test app test21'}, )) eq_(res.status_code, 200) eq_(len(res.json['objects']), 3) # app2 should be first since it's an exact match and is boosted higher. obj = res.json['objects'][0] eq_(obj['slug'], app2.app_slug) unindex_webapps([app1.id, app2.id, app3.id]) app1.delete() app2.delete() app3.delete()
def tearDownClass(cls): try: if hasattr(cls, '_addons'): addons = Webapp.objects.filter( pk__in=[a.id for a in cls._addons]) # First delete all the translations. for addon in addons: for field in addon._meta.translated_fields: delete_translation(addon, field.name) addons.delete() unindex_webapps([a.id for a in cls._addons]) mkt.SEARCH_ANALYZER_MAP = cls._SEARCH_ANALYZER_MAP finally: # Make sure we're calling super's tearDownClass even if something # went wrong in the code above, as otherwise we'd run into bug # 960598. super(ESTestCase, cls).tearDownClass()
def test_q_exact(self): app1 = app_factory(name="test app test11") app2 = app_factory(name="test app test21") app3 = app_factory(name="test app test31") self.refresh("webapp") res = self.client.get(self.url, data={"q": "test app test21"}) eq_(res.status_code, 200) eq_(len(res.json["objects"]), 3) # app2 should be first since it's an exact match and is boosted higher. obj = res.json["objects"][0] eq_(obj["slug"], app2.app_slug) unindex_webapps([app1.id, app2.id, app3.id]) app1.delete() app2.delete() app3.delete()
def test_upsell(self): upsell = app_factory() AddonUpsell.objects.create(free=self.webapp, premium=upsell) self.webapp.save() self.refresh('webapp') res = self.client.get(self.url) eq_(res.status_code, 200) obj = res.json['objects'][0] eq_(obj['upsell']['id'], upsell.id) eq_(obj['upsell']['app_slug'], upsell.app_slug) eq_(obj['upsell']['name'], upsell.name) eq_(obj['upsell']['icon_url'], upsell.get_icon_url(128)) eq_(obj['upsell']['resource_uri'], '/api/v1/apps/app/%s/' % upsell.id) unindex_webapps([upsell.id]) upsell.delete()
def test_suggestions(self): app1 = Webapp.objects.get(pk=337141) app1.save() app2 = app_factory(name=u"Second âpp", description=u"Second dèsc" * 25, created=self.days_ago(3)) self.refresh("webapp") response = self.client.get(self.url) parsed = json.loads(response.content) eq_(parsed[0], "") eq_(parsed[1], [unicode(app1.name), unicode(app2.name)]) eq_(parsed[2], [unicode(app1.description), unicode(truncate(app2.description))]) eq_(parsed[3], [absolutify(app1.get_detail_url()), absolutify(app2.get_detail_url())]) eq_(parsed[4], [app1.get_icon_url(64), app2.get_icon_url(64)]) # Cleanup to remove these from the index. unindex_webapps([app1.id, app2.id]) app1.delete() app2.delete()
def test_upsell(self): upsell = app_factory(premium_type=amo.ADDON_PREMIUM) AddonUpsell.objects.create(free=self.webapp, premium=upsell) self.webapp.save() self.refresh("webapp") res = self.client.get(self.url, {"premium_types": "free"}) eq_(res.status_code, 200) eq_(len(res.json["objects"]), 1) obj = res.json["objects"][0] eq_(obj["upsell"]["id"], upsell.id) eq_(obj["upsell"]["app_slug"], upsell.app_slug) eq_(obj["upsell"]["name"], upsell.name) eq_(obj["upsell"]["icon_url"], upsell.get_icon_url(128)) eq_(obj["upsell"]["resource_uri"], "/api/v1/apps/app/%s/" % upsell.id) eq_(obj["upsell"]["region_exclusions"], []) unindex_webapps([upsell.id]) upsell.delete()
def test_upsell(self): upsell = app_factory(premium_type=amo.ADDON_PREMIUM) AddonUpsell.objects.create(free=self.webapp, premium=upsell) self.webapp.save() self.refresh('webapp') res = self.client.get(self.url, {'premium_types': 'free'}) eq_(res.status_code, 200) eq_(len(res.json['objects']), 1) obj = res.json['objects'][0] eq_(obj['upsell']['id'], upsell.id) eq_(obj['upsell']['app_slug'], upsell.app_slug) eq_(obj['upsell']['name'], upsell.name) eq_(obj['upsell']['icon_url'], upsell.get_icon_url(128)) eq_(obj['upsell']['resource_uri'], '/api/apps/app/%s/' % upsell.id) eq_(obj['upsell']['region_exclusions'], []) unindex_webapps([upsell.id]) upsell.delete()
def test_upsell(self): upsell = app_factory(premium_type=amo.ADDON_PREMIUM) AddonUpsell.objects.create(free=self.webapp, premium=upsell) self.webapp.save() self.refresh('webapp') res = self.client.get(self.url, {'premium_types': 'free'}) eq_(res.status_code, 200) eq_(len(res.json['objects']), 1) obj = res.json['objects'][0] eq_(obj['upsell']['id'], upsell.id) eq_(obj['upsell']['app_slug'], upsell.app_slug) eq_(obj['upsell']['name'], upsell.name) eq_(obj['upsell']['icon_url'], upsell.get_icon_url(128)) eq_(obj['upsell']['resource_uri'], '/api/v1/apps/app/%s/' % upsell.id) eq_(obj['upsell']['region_exclusions'], []) unindex_webapps([upsell.id]) upsell.delete()
def tearDown(self): unindex_webapps(list(Webapp.with_deleted.values_list('id', flat=True))) Webapp.objects.all().delete() super(TestApi, self).tearDown()
def tearDown(self): unindex_webapps([self.w1.id, self.w2.id]) self.w1.delete() self.w2.delete()
def tearDown(self): # Cleanup to remove these from the index. self.app1.delete() self.app2.delete() unindex_webapps([self.app1.id, self.app2.id])
def tearDown(self): for w in Webapp.objects.all(): w.delete() unindex_webapps(list(Webapp.with_deleted.values_list('id', flat=True))) super(TestApi, self).tearDown()
def tearDown(self): for w in Webapp.objects.all(): w.delete() unindex_webapps(list(Webapp.with_deleted.values_list("id", flat=True))) super(TestApi, self).tearDown()
def tearDown(self): # Cleanup to remove these from the index. unindex_webapps([self.app1.id, self.app2.id]) self.app1.delete() self.app2.delete()
def tearDownClass(cls): if hasattr(cls, "_addons"): Addon.objects.filter(pk__in=[a.id for a in cls._addons]).delete() unindex_webapps([a.id for a in cls._addons if a.type == amo.ADDON_WEBAPP]) unindex_addons([a.id for a in cls._addons if a.type != amo.ADDON_WEBAPP]) amo.SEARCH_ANALYZER_MAP = cls._SEARCH_ANALYZER_MAP