def update_popularity(): """ Update the popularity score of all the projects Simply loops over all the tenants, and updates the scores """ logger.info("Updating projects popularity using Celery") for tenant in Client.objects.all(): with LocalTenant(tenant, clear_tenant=True): Project.update_popularity() logger.info("Finished updating projects popularity using Celery")
def update_popularity(): """ Update the popularity score of all the projects Simply loops over all the tenants, and updates the scores """ logger.info("Updating projects popularity using Celery") for tenant in Client.objects.all(): connection.set_tenant(tenant) with LocalTenant(tenant, clear_tenant=True): Project.update_popularity() logger.info("Finished updating projects popularity using Celery")
def setUp(self): super(MonthlyDonationAdminTest, self).setUp() self.app.extra_environ['HTTP_HOST'] = str(self.tenant.domain_url) self.superuser = BlueBottleUserFactory.create(is_staff=True, is_superuser=True) self.init_projects() self.phase_campaign = ProjectPhase.objects.get(slug='campaign') self.country = CountryFactory() self.projects = [] for amount in [500, 100, 1500, 300, 200]: self.projects.append( ProjectFactory.create(amount_asked=amount, status=self.phase_campaign)) # Some donations to get the popularity going # Top 3 after this should be projects 4, 3, 0 order = OrderFactory() DonationFactory(order=order, project=self.projects[3], amount=10) DonationFactory(order=order, project=self.projects[3], amount=100) DonationFactory(order=order, project=self.projects[3], amount=20) DonationFactory(order=order, project=self.projects[4], amount=10) DonationFactory(order=order, project=self.projects[4], amount=70) DonationFactory(order=order, project=self.projects[0], amount=10) order.locked() order.save() order.success() order.save() # Since we force the transitions update_amounts isn't triggered by # signal, so we run it manually here. for project in self.projects: project.update_amounts() self.user1 = BlueBottleUserFactory.create() self.user2 = BlueBottleUserFactory.create() # Create a monthly donor with a preferred project self.monthly_donor1 = MonthlyDonorFactory(user=self.user1, amount=25) self.monthly_donor1_project = MonthlyDonorProjectFactory( donor=self.monthly_donor1, project=self.projects[0]) # Create a monthly donor without preferred projects self.monthly_donor2 = MonthlyDonorFactory(user=self.user2, amount=100) Project.update_popularity()
def setUp(self): super(MonthlyDonationAdminTest, self).setUp() self.app.extra_environ['HTTP_HOST'] = str(self.tenant.domain_url) self.superuser = BlueBottleUserFactory.create(is_staff=True, is_superuser=True) self.init_projects() self.phase_campaign = ProjectPhase.objects.get(slug='campaign') self.country = CountryFactory() self.projects = [] for amount in [500, 100, 1500, 300, 200]: self.projects.append( ProjectFactory.create(amount_asked=amount, status=self.phase_campaign)) # Some donations to get the popularity going # Top 3 after this should be projects 4, 3, 0 order = OrderFactory() DonationFactory(order=order, project=self.projects[3], amount=10) DonationFactory(order=order, project=self.projects[3], amount=100) DonationFactory(order=order, project=self.projects[3], amount=20) DonationFactory(order=order, project=self.projects[4], amount=10) DonationFactory(order=order, project=self.projects[4], amount=70) DonationFactory(order=order, project=self.projects[0], amount=10) order.locked() order.save() order.success() order.save() # Since we force the transitions update_amounts isn't triggered by # signal, so we run it manually here. for project in self.projects: project.update_amounts() self.user1 = BlueBottleUserFactory.create() self.user2 = BlueBottleUserFactory.create() # Create a monthly donor with a preferred project self.monthly_donor1 = MonthlyDonorFactory(user=self.user1, amount=25) self.monthly_donor1_project = MonthlyDonorProjectFactory( donor=self.monthly_donor1, project=self.projects[0]) # Create a monthly donor without preferred projects self.monthly_donor2 = MonthlyDonorFactory(user=self.user2, amount=100) Project.update_popularity()
def test_update_popularity(self): Project.update_popularity() self.assertEqual(Project.objects.get(id=self.project.id).popularity, 11)
def test_update_popularity(self): Project.update_popularity() self.assertEqual( Project.objects.get(id=self.project.id).popularity, 11)