def test_second_job_is_scheduled(self): # If there is already one POFileStatsJob scheduled for a particular # POFile, then a second one is scheduled. self.assertEqual(len(list(POFileStatsJob.iterReady())), 0) # We need a POFile to update. pofile = self.factory.makePOFile(side=TranslationSide.UPSTREAM) # If we schedule a job, then there will be one scheduled. pofilestatsjob.schedule(pofile.id) self.assertIs(len(list(POFileStatsJob.iterReady())), 1) # If we attempt to schedule another job for the same POFile, a new job # is added. pofilestatsjob.schedule(pofile.id) self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
def test_run(self): # POFileJob can run via Celery. self.useFixture( FeatureFixture({'jobs.celery.enabled_classes': 'POFileStatsJob'})) # Running a job causes the POFile statistics to be updated. singular = self.factory.getUniqueString() pofile = self.factory.makePOFile(side=TranslationSide.UPSTREAM) # Create a message so we have something to have statistics about. self.factory.makePOTMsgSet(pofile.potemplate, singular) # The statistics start at 0. self.assertEqual(pofile.potemplate.messageCount(), 0) pofilestatsjob.schedule(pofile.id) with block_on_job(): transaction.commit() # Now that the job ran, the statistics have been updated. self.assertEqual(pofile.potemplate.messageCount(), 1)
def test_run(self): # POFileJob can run via Celery. self.useFixture(FeatureFixture( {'jobs.celery.enabled_classes': 'POFileStatsJob'})) # Running a job causes the POFile statistics to be updated. singular = self.factory.getUniqueString() pofile = self.factory.makePOFile(side=TranslationSide.UPSTREAM) # Create a message so we have something to have statistics about. self.factory.makePOTMsgSet(pofile.potemplate, singular) # The statistics start at 0. self.assertEqual(pofile.potemplate.messageCount(), 0) pofilestatsjob.schedule(pofile.id) with block_on_job(): transaction.commit() # Now that the job ran, the statistics have been updated. self.assertEqual(pofile.potemplate.messageCount(), 1)
def test_iterReady(self): # The POFileStatsJob class provides a way to iterate over the jobs # that are ready to run. Initially, there aren't any. self.assertEqual(len(list(POFileStatsJob.iterReady())), 0) # We need a POFile to update. pofile = self.factory.makePOFile(side=TranslationSide.UPSTREAM) # If we schedule a job, then we'll get it back. job = pofilestatsjob.schedule(pofile.id) self.assertIs(list(POFileStatsJob.iterReady())[0], job)
def test_run(self): # Running a job causes the POFile statistics to be updated. singular = self.factory.getUniqueString() pofile = self.factory.makePOFile(side=TranslationSide.UPSTREAM) # Create a message so we have something to have statistics about. self.factory.makePOTMsgSet(pofile.potemplate, singular) # The statistics start at 0. self.assertEqual(pofile.potemplate.messageCount(), 0) job = pofilestatsjob.schedule(pofile.id) # Just scheduling the job doesn't update the statistics. self.assertEqual(pofile.potemplate.messageCount(), 0) with dbuser('pofilestats'): job.run() # Now that the job ran, the statistics have been updated. self.assertEqual(pofile.potemplate.messageCount(), 1)
def test_run_with_product(self): product = self.factory.makeProduct( translations_usage=ServiceUsage.LAUNCHPAD) productseries = self.factory.makeProductSeries(product=product) potemplate = self.factory.makePOTemplate(productseries=productseries) pofile = self.factory.makePOFile('en', potemplate) # Create a message so we have something to have statistics about. singular = self.factory.getUniqueString() self.factory.makePOTMsgSet(pofile.potemplate, singular) # The statistics are still at 0, even though there is a message. self.assertEqual(potemplate.messageCount(), 0) job = pofilestatsjob.schedule(pofile.id) # Just scheduling the job doesn't update the statistics. self.assertEqual(pofile.potemplate.messageCount(), 0) with dbuser('pofilestats'): job.run() # Now that the job ran, the statistics have been updated. self.assertEqual(pofile.potemplate.messageCount(), 1)
def assertJobUpdatesStats(self, pofile1, pofile2): # Create a single POTMsgSet and add it to only one of the POTemplates. self.factory.makeSuggestion(pofile1) self.factory.makeSuggestion(pofile2) # The statistics start at 0. self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0)) self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0)) job = pofilestatsjob.schedule(pofile1.id) # Just scheduling the job doesn't update the statistics. self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0)) self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0)) with dbuser('pofilestats'): job.run() # Now that the job ran, the statistics for the POFile have been # updated. self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 1)) # The statistics for the other POFile is also updated as a result of # running the job for the other POFile because they share # translations. self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 1))