Merge lp:~jtv/launchpad/cp-bug-409465 into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jtv/launchpad/cp-bug-409465
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~jtv/launchpad/cp-bug-409465
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Review via email: mp+9763@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

= Bug 409465 =

This branch is for cherry-picking.

The translation uploads auto-approver was crashing when certain uploads
were waiting to be approved: translation files for disabled templates in
projects (not distributions) where the path for the translation file did
not match any existing POFile's path.

See the bug report for a more detailed analysis. This branch presents a
very minimal fix to prevent regressions, and adds a unit test. The test
establishes that the normal approval case succeeds, and that the problem
case fails as it should (as opposed to breaking completely).

To test:
{{{
./bin/test -vv -t autoapproval
}}}

For Q/A, read error-reports and see that the error does not return. The
test faithfully reproduces the error on an unpatched branch.

I considered updating the existing test cases in the test file I edited
to use TestCaseWithFactory, but... not in a cherrypicking branch!

No lint complaints.

Jeroen

Revision history for this message
Данило Шеган (danilo) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/model/translationimportqueue.py'
2--- lib/lp/translations/model/translationimportqueue.py 2009-07-24 12:40:30 +0000
3+++ lib/lp/translations/model/translationimportqueue.py 2009-08-06 04:29:04 +0000
4@@ -345,8 +345,13 @@
5 potemplate = potemplate_subset.getPOTemplateByTranslationDomain(
6 translation_domain)
7
8- if (potemplate is None and (sourcepackagename is None or
9- self.sourcepackagename.name != sourcepackagename.name)):
10+ is_for_distro = self.distroseries is not None
11+ know_package = (
12+ sourcepackagename is not None and
13+ self.sourcepackagename is not None and
14+ self.sourcepackagename.name == sourcepackagename.name)
15+
16+ if potemplate is None and is_for_distro and not know_package:
17 # The source package from where this translation doesn't have the
18 # template that this translation needs it, and thus, we look for
19 # it in a different source package as a second try. To do it, we
20
21=== modified file 'lib/lp/translations/tests/test_autoapproval.py'
22--- lib/lp/translations/tests/test_autoapproval.py 2009-07-17 00:26:05 +0000
23+++ lib/lp/translations/tests/test_autoapproval.py 2009-08-06 13:56:17 +0000
24@@ -24,6 +24,7 @@
25 from lp.translations.interfaces.customlanguagecode import ICustomLanguageCode
26 from lp.translations.interfaces.translationimportqueue import (
27 RosettaImportStatus)
28+from lp.testing import TestCaseWithFactory
29 from lp.testing.factory import LaunchpadObjectFactory
30 from canonical.launchpad.webapp.testing import verifyObject
31 from canonical.testing import LaunchpadZopelessLayer
32@@ -470,6 +471,50 @@
33 pofile = entry.getGuessedPOFile()
34 self.assertEqual(pofile, self.pofile_nl)
35
36+
37+class TestGetPOFileFromLanguage(TestCaseWithFactory):
38+ """Test `TranslationImportQueueEntry._get_pofile_from_language`."""
39+
40+ layer = LaunchpadZopelessLayer
41+
42+ def setUp(self):
43+ super(TestGetPOFileFromLanguage, self).setUp()
44+ self.queue = TranslationImportQueue()
45+
46+ def test_get_pofile_from_language_feeds_enabled_template(self):
47+ # _get_pofile_from_language will find an enabled template, and
48+ # return either an existing POFile for the given language, or a
49+ # newly created one.
50+ product = self.factory.makeProduct()
51+ product.official_rosetta = True
52+ trunk = product.getSeries('trunk')
53+ template = self.factory.makePOTemplate(
54+ productseries=trunk, translation_domain='domain')
55+ template.iscurrent = True
56+
57+ entry = self.queue.addOrUpdateEntry(
58+ 'nl.po', '# ...', False, template.owner, productseries=trunk)
59+
60+ pofile = entry._get_pofile_from_language('nl', 'domain')
61+ self.assertNotEqual(None, pofile)
62+
63+ def test_get_pofile_from_language_starves_disabled_template(self):
64+ # _get_pofile_from_language will not consider a disabled
65+ # template as an auto-approval target, and so will not return a
66+ # POFile for it.
67+ product = self.factory.makeProduct()
68+ product.official_rosetta = True
69+ trunk = product.getSeries('trunk')
70+ template = self.factory.makePOTemplate(
71+ productseries=trunk, translation_domain='domain')
72+ template.iscurrent = False
73+
74+ entry = self.queue.addOrUpdateEntry(
75+ 'nl.po', '# ...', False, template.owner, productseries=trunk)
76+
77+ pofile = entry._get_pofile_from_language('nl', 'domain')
78+ self.assertEqual(None, pofile)
79+
80+
81 def test_suite():
82 return unittest.TestLoader().loadTestsFromName(__name__)
83-