~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/tests/test_pofilestatsjob.py

  • Committer: Raphael Badin
  • Date: 2012-01-06 08:27:55 UTC
  • mfrom: (14513.5.4 builder-history-lfa)
  • mto: This revision was merged to the branch mainline in revision 14654.
  • Revision ID: raphael.badin@canonical.com-20120106082755-95a0eh6nakv5hj3b
Merge devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
        # Now that the job ran, the statistics have been updated.
52
52
        self.assertEqual(pofile.potemplate.messageCount(), 1)
53
53
 
54
 
    def test_with_product(self):
 
54
    def test_run_with_product(self):
55
55
        product = self.factory.makeProduct(
56
56
            translations_usage=ServiceUsage.LAUNCHPAD)
57
57
        productseries = self.factory.makeProductSeries(product=product)
93
93
        # is added.
94
94
        pofilestatsjob.schedule(pofile.id)
95
95
        self.assertIs(len(list(POFileStatsJob.iterReady())), 2)
 
96
 
 
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):
 
109
            job.run()
 
110
        # Now that the job ran, the statistics for the POFile have been
 
111
        # updated.
 
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
 
115
        # translations.
 
116
        self.assertEqual(pofile2.getStatistics(), (0, 0, 0, 1))
 
117
 
 
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)
 
127
 
 
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')
 
131
 
 
132
        self.factory.makeLanguage('en-tt')
 
133
        pofile1 = self.factory.makePOFile('en-tt', template1)
 
134
        pofile2 = self.factory.makePOFile('en-tt', template2)
 
135
 
 
136
        self.assertJobUpdatesStats(pofile1, pofile2)
 
137
 
 
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())
 
149
 
 
150
        # Create template ready for sharing on the Ubuntu side.
 
151
        template1 = self.factory.makePOTemplate(
 
152
            distroseries=distroseries,
 
153
            sourcepackagename=sourcepackagename,
 
154
            name='messages')
 
155
        pofile1 = self.factory.makePOFile(
 
156
            language=language, potemplate=template1)
 
157
 
 
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)
 
162
 
 
163
        self.assertJobUpdatesStats(pofile1, pofile2)
 
164
 
 
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)
 
178
 
 
179
        template1 = self.factory.makePOTemplate(
 
180
            distroseries=distroseries1,
 
181
            sourcepackagename=sourcepackagename,
 
182
            name='messages')
 
183
        pofile1 = self.factory.makePOFile(
 
184
            language=language, potemplate=template1)
 
185
 
 
186
        template2 = self.factory.makePOTemplate(
 
187
            distroseries=distroseries2,
 
188
            sourcepackagename=sourcepackagename,
 
189
            name='messages')
 
190
        pofile2 = template2.getPOFileByLang(language.code)
 
191
 
 
192
        self.assertJobUpdatesStats(pofile1, pofile2)