def extract_popularity_trending_boost(cls, obj): extend = { 'boost': get_boost(obj), 'popularity': get_popularity(obj), 'trending': get_trending(obj) } for region in mkt.regions.ALL_REGIONS: extend['trending_%s' % region.id] = get_trending(obj, region) extend['popularity_%s' % region.id] = get_popularity(obj, region) return extend
def _test_get_popularity(self, obj): # Test no popularity record returns zero. eq_(get_trending(obj), 0) # Add a region specific popularity and test the global one is returned # because the region is not mature. region = Mock(id=1337, adolescent=True) obj.popularity.create(value=42.0, region=0) obj.popularity.create(value=10.0, region=region.id) eq_(get_popularity(obj, region=region), 42.0) # Now test the regional popularity is returned when adolescent=False. region.adolescent = False eq_(get_popularity(obj, region=region), 10.0)
def test_installs_saved(self, _mock): _mock.return_value = {'all': 12.0} update_app_installs() eq_(get_popularity(self.app), 12.0) for region in mkt.regions.REGIONS_DICT.values(): if region.adolescent: eq_(get_popularity(self.app, region=region), 12.0) else: eq_(get_popularity(self.app, region=region), 0.0) # Test running again updates the values as we'd expect. _mock.return_value = {'all': 2.0} update_app_installs() eq_(get_popularity(self.app), 2.0) for region in mkt.regions.REGIONS_DICT.values(): if region.adolescent: eq_(get_popularity(self.app, region=region), 2.0) else: eq_(get_popularity(self.app, region=region), 0.0)