def test_get_recommendations(call_recommendation_server): a101 = addon_factory(id=101, guid='101@mozilla') addon_factory(id=102, guid='102@mozilla') addon_factory(id=103, guid='103@mozilla') addon_factory(id=104, guid='104@mozilla') call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@mozilla' ] recommendations = get_recommendations('0', { 'locale': 'en-US', 'platform': 'WINNT' }) assert ([r.addon_id for r in recommendations] == [101, 102, 103, 104]) assert all([r.is_recommendation for r in recommendations]) # only valid, public add-ons should match guids a101.update(status=amo.STATUS_NULL) call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@badguid' ] recommendations = get_recommendations('0', { 'locale': 'en-US', 'platform': 'WINNT' }) assert ([r.addon_id for r in recommendations] == [102, 103])
def test_get_recommendations(call_recommendation_server): expected_addons = [ addon_factory(guid='101@mozilla'), addon_factory(guid='102@mozilla'), addon_factory(guid='103@mozilla'), addon_factory(guid='104@mozilla'), ] # Only the first one has a DiscoveryItem. The rest should still be # returned. call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@mozilla' ] recommendations = get_recommendations( '0', {'locale': 'en-US', 'platform': 'WINNT'}) assert [r.addon for r in recommendations] == expected_addons # only valid, public add-ons should match guids incomplete_addon = expected_addons.pop() incomplete_addon.update(status=amo.STATUS_NULL) # Remove this one and have recommendations return a bad guid instead. expected_addons.pop() call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@badbadguid', '104@mozilla' ] recommendations = get_recommendations( '0', {'locale': 'en-US', 'platform': 'WINNT'}) assert [result.addon for result in recommendations] == expected_addons
def get_queryset(self): params = self.get_params() edition = params.pop('edition', 'default') position_field = 'position_china' if edition == 'china' else 'position' # Base queryset for editorial content. qs = (DiscoveryItem.objects .prefetch_related('addon') .filter(**{position_field + '__gt': 0}) .order_by(position_field)) # Recommendations stuff, potentially replacing some/all items in # the queryset with recommendations if applicable. if edition == 'china': # No TAAR for China Edition. telemetry_id = None else: telemetry_id = params.pop('telemetry-client-id', None) if switch_is_active('disco-recommendations') and telemetry_id: recommendations = get_recommendations( telemetry_id, params) if recommendations: # if we got some recommendations then replace the # extensions in the queryset with them. # Leave the non-extensions (personas) alone. qs = replace_extensions(qs, recommendations) return qs
def test_get_recommendations(call_recommendation_server): a101 = addon_factory(id=101, guid='101@mozilla') addon_factory(id=102, guid='102@mozilla') addon_factory(id=103, guid='103@mozilla') addon_factory(id=104, guid='104@mozilla') call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@mozilla' ] assert ([r.addon_id for r in get_recommendations('0')] == [101, 102, 103, 104]) # only valid, public add-ons should match guids a101.update(status=amo.STATUS_NULL) call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@badguid' ] assert ([r.addon_id for r in get_recommendations('0')] == [102, 103])
def test_get_recommendations(call_recommendation_server): a101 = addon_factory(id=101, guid='101@mozilla') addon_factory(id=102, guid='102@mozilla') addon_factory(id=103, guid='103@mozilla') addon_factory(id=104, guid='104@mozilla') call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@mozilla' ] assert ([r.addon_id for r in get_recommendations('0')] == [101, 102, 103, 104]) assert all([r.is_recommendation for r in get_recommendations('0')]) # only valid, public add-ons should match guids a101.update(status=amo.STATUS_NULL) call_recommendation_server.return_value = [ '101@mozilla', '102@mozilla', '103@mozilla', '104@badguid' ] assert ([r.addon_id for r in get_recommendations('0')] == [102, 103])
def get_discopane_items(self): if not getattr(self, 'discopane_items', None): telemetry_id = (self.kwargs.get('telemetry-client-id') or self.request.GET.get('telemetry-client-id')) self.discopane_items = discopane_items if switch_is_active('disco-recommendations') and telemetry_id: recommendations = get_recommendations(telemetry_id) if recommendations: # if we got some recommendations then replace the # extensions in discopane_items with them. # Leave the non-extensions (personas) alone. self.discopane_items = replace_extensions( discopane_items, recommendations) return self.discopane_items
def get_discopane_items(self): if not getattr(self, 'discopane_items', None): telemetry_id = (self.kwargs.get('telemetry-client-id') or self.request.GET.get('telemetry-client-id')) self.discopane_items = discopane_items if switch_is_active('disco-recommendations') and telemetry_id: recommendations = get_recommendations(telemetry_id) if recommendations: # if we got some recommendations then replace the # extensions in discopane_items with them. # Leave the non-extensions (personas) alone. self.discopane_items = replace_extensions( discopane_items, recommendations) return self.discopane_items
def get_discopane_items(self): if not getattr(self, 'discopane_items', None): params = self.get_params() telemetry_id = params.pop('telemetry-client-id', None) self.discopane_items = discopane_items if switch_is_active('disco-recommendations') and telemetry_id: recommendations = get_recommendations(telemetry_id, params) if recommendations: # if we got some recommendations then replace the # extensions in discopane_items with them. # Leave the non-extensions (personas) alone. self.discopane_items = replace_extensions( discopane_items, recommendations) return self.discopane_items
def get_discopane_items(self): if not getattr(self, 'discopane_items', None): params = self.get_params() edition = params.pop('edition', 'default') self.discopane_items = discopane_items.get( edition, discopane_items['default']) if edition == 'china': # No TAAR for China Edition. telemetry_id = None else: telemetry_id = params.pop('telemetry-client-id', None) if switch_is_active('disco-recommendations') and telemetry_id: recommendations = get_recommendations(telemetry_id, params) if recommendations: # if we got some recommendations then replace the # extensions in discopane_items with them. # Leave the non-extensions (personas) alone. self.discopane_items = replace_extensions( self.discopane_items, recommendations) return self.discopane_items