94
94
pofilestatsjob.schedule(pofile.id)
95
95
self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
97
def assertJobUpdatesStats(self, pofile1, pofile2):
98
# Create a single POTMsgSet and add it to only one of the POTemplates.
99
self.factory.makeSuggestion(pofile1)
100
self.factory.makeSuggestion(pofile2)
101
# The statistics start at 0.
102
self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
103
self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
104
job = pofilestatsjob.schedule(pofile1.id)
105
# Just scheduling the job doesn't update the statistics.
106
self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 0))
107
self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 0))
108
with dbuser(config.pofile_stats.dbuser):
110
# Now that the job ran, the statistics for the POFile have been
112
self.assertEqual(pofile1.getStatistics(), (0, 0, 0, 1))
113
# The statistics for the other POFile is also updated as a result of
114
# running the job for the other POFile because they share
116
self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 1))
118
def test_run_with_project_shared_template(self):
119
# Create a product with two series and sharing POTemplates
120
# in different series ('devel' and 'stable').
121
product = self.factory.makeProduct(
122
translations_usage=ServiceUsage.LAUNCHPAD)
123
devel = self.factory.makeProductSeries(
124
name='devel', product=product)
125
stable = self.factory.makeProductSeries(
126
name='stable', product=product)
128
# POTemplate is a 'sharing' one if it has the same name ('messages').
129
template1 = self.factory.makePOTemplate(devel, name='messages')
130
template2 = self.factory.makePOTemplate(stable, name='messages')
132
self.factory.makeLanguage('en-tt')
133
pofile1 = self.factory.makePOFile('en-tt', template1)
134
pofile2 = self.factory.makePOFile('en-tt', template2)
136
self.assertJobUpdatesStats(pofile1, pofile2)
138
def test_run_with_product_and_distro_translation_sharing(self):
139
language = self.factory.makeLanguage('en-tt')
140
distroseries = self.factory.makeUbuntuDistroSeries()
141
distroseries.distribution.translation_focus = distroseries
142
sourcepackagename = self.factory.makeSourcePackageName()
143
sourcepackage = self.factory.makeSourcePackage(
144
distroseries=distroseries,
145
sourcepackagename=sourcepackagename)
146
productseries = self.factory.makeProductSeries()
147
sourcepackage.setPackaging(
148
productseries, self.factory.makePerson())
150
# Create template ready for sharing on the Ubuntu side.
151
template1 = self.factory.makePOTemplate(
152
distroseries=distroseries,
153
sourcepackagename=sourcepackagename,
155
pofile1 = self.factory.makePOFile(
156
language=language, potemplate=template1)
158
# Create template ready for sharing on the upstream side.
159
template2 = self.factory.makePOTemplate(
160
productseries=productseries, name='messages')
161
pofile2 = template2.getPOFileByLang(language.code)
163
self.assertJobUpdatesStats(pofile1, pofile2)
165
def test_run_with_distro_translation_sharing(self):
166
language = self.factory.makeLanguage('en-tt')
167
distroseries1 = self.factory.makeUbuntuDistroSeries()
168
distroseries1.distribution.translation_focus = distroseries1
169
sourcepackagename = self.factory.makeSourcePackageName()
170
self.factory.makeSourcePackage(
171
distroseries=distroseries1,
172
sourcepackagename=sourcepackagename)
173
distroseries2 = self.factory.makeUbuntuDistroSeries()
174
distroseries2.distribution.translation_focus = distroseries2
175
self.factory.makeSourcePackage(
176
distroseries=distroseries2,
177
sourcepackagename=sourcepackagename)
179
template1 = self.factory.makePOTemplate(
180
distroseries=distroseries1,
181
sourcepackagename=sourcepackagename,
183
pofile1 = self.factory.makePOFile(
184
language=language, potemplate=template1)
186
template2 = self.factory.makePOTemplate(
187
distroseries=distroseries2,
188
sourcepackagename=sourcepackagename,
190
pofile2 = template2.getPOFileByLang(language.code)
192
self.assertJobUpdatesStats(pofile1, pofile2)