def test_update_package_activity_cron(self): addon = Package(type='a', author=self.author) addon.save() now = datetime.datetime.now() # Create 1 weeks worth of revisions... should equal .30 of score # see models.py def Packages for weights for i in range(1,8): r = addon.revisions.create(author=self.author, revision_number=i) r.created_at=now-datetime.timedelta(i) super(PackageRevision, r).save() #run task on this one package calculate_activity_rating([addon.pk]) addon = Package.objects.get(pk=addon.pk) eq_(addon.activity_rating, addon.calc_activity_rating())
def test_sorting_by_activity(self): #create 10 packages and a random number of revisions now = datetime.datetime.utcnow() addons = [] for i in range(10): addon = create_addon('addon-{0}'.format(i)) addons.append(addon) for k in range(1,random.randrange(1,50)): r = addon.revisions.create(author=addon.author, revision_number=k) r.created_at=now-datetime.timedelta(random.randrange(1,365)) super(PackageRevision, r).save() calculate_activity_rating([a.pk for a in addons]) self.es.refresh() qs = package_search().order_by('activity') last_score = 1 for r in qs: eq_(r.activity<last_score, True) last_score = r.activity