Merge lp:~jtv/launchpad/bug-702832 into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 12221
Proposed branch: lp:~jtv/launchpad/bug-702832
Merge into: lp:launchpad
Diff against target: 94 lines (+29/-12)
3 files modified
lib/lp/translations/model/potmsgset.py (+3/-4)
lib/lp/translations/tests/test_potmsgset.py (+0/-7)
lib/lp/translations/tests/test_translationmessage.py (+26/-1)
To merge this branch: bzr merge lp:~jtv/launchpad/bug-702832
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+46261@code.launchpad.net

Commit message

[r=sinzui][ui=none][bug=702832] Fix oops during translation approval.

Description of the change

= Bug 702832 =

Fixes a relatively rare oops in the "Recife" Translations code that was written over the past year and finally rolled out last cycle. A certain piece of data used to be structured as either a list of a message's translations for each of the language's plural forms, or a dict mapping the plural forms to their corresponding translations. Duck typing still made things work pretty well when a list was passed. One call site still passed a list, and the docstring still, mistakenly, asked for one.

The incorrect type only caused trouble when the data was then passed on to yet another method that did expect a dict. For invocations from the call site that made this mistake, that last method was only called in a rare scenario. That's how this managed to escape both unit tests (which passed the right type) and integration tests (which didn't tickle this particular, rare combination of calls).

Run this test to verify that the specific bug is gone:
{{{
./bin/test -vvc lp.translations.tests.test_potmsgset -t clones
}}}

I also removed an assertion that seems a bit silly given later changes: it checks that a required parameter is not None, but it's pretty much always going to be either a constant or a not-null database value. That also eliminated a now-pointless test.

For Q/A, we should see that approval of existing suggestions and translations still works.

No lint,

Jeroen

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

This look good to Land. Thank you for removing the cruft.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/model/potmsgset.py'
2--- lib/lp/translations/model/potmsgset.py 2011-01-05 20:44:50 +0000
3+++ lib/lp/translations/model/potmsgset.py 2011-01-14 14:17:57 +0000
4@@ -344,7 +344,6 @@
5
6 def getCurrentTranslation(self, potemplate, language, side):
7 """See `IPOTMsgSet`."""
8- assert side is not None, "Translation side must be specified."
9 traits = getUtility(ITranslationSideTraitsSet).getTraits(side)
10 flag = removeSecurityProxy(traits.getFlag(TranslationMessage))
11
12@@ -1152,7 +1151,7 @@
13 return
14
15 translator = suggestion.submitter
16- potranslations = suggestion.all_msgstrs
17+ potranslations = dictify_translations(suggestion.all_msgstrs)
18 activated_message = self._setTranslation(
19 pofile, translator, suggestion.origin, potranslations,
20 share_with_other_side=share_with_other_side,
21@@ -1250,8 +1249,8 @@
22 :param pofile: The `POFile` to set the translation in.
23 :param submitter: The `Person` who produced this translation.
24 :param origin: The translation's `RosettaTranslationOrigin`.
25- :param potranslations: List of `POTranslation`s, with a None for
26- each untranslated plural-form.
27+ :param potranslations: A dict mapping plural-form numbers to the
28+ respective `POTranslation`s for those forms.
29 :param identical_message: The already existing message, if any,
30 that's either shared or diverged for `pofile.potemplate`,
31 whose translations are identical to the ones we're setting.
32
33=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
34--- lib/lp/translations/tests/test_potmsgset.py 2011-01-04 17:23:42 +0000
35+++ lib/lp/translations/tests/test_potmsgset.py 2011-01-14 14:17:57 +0000
36@@ -1906,13 +1906,6 @@
37 pofile.potemplate, pofile.language, self.this_side)
38 self.assertEqual(message, current)
39
40- def test_requires_side(self):
41- pofile, potmsgset = self._makePOFileAndPOTMsgSet()
42- self.assertRaises(
43- AssertionError,
44- potmsgset.getCurrentTranslation,
45- pofile.potemplate, pofile.language, None)
46-
47 def test_other_languages_ignored(self):
48 # getCurrentTranslation never returns a translation for another
49 # language.
50
51=== modified file 'lib/lp/translations/tests/test_translationmessage.py'
52--- lib/lp/translations/tests/test_translationmessage.py 2010-12-10 11:44:07 +0000
53+++ lib/lp/translations/tests/test_translationmessage.py 2011-01-14 14:17:57 +0000
54@@ -18,7 +18,10 @@
55 from canonical.testing.layers import ZopelessDatabaseLayer
56 from lp.services.worlddata.interfaces.language import ILanguageSet
57 from lp.testing import TestCaseWithFactory
58-from lp.translations.interfaces.side import ITranslationSideTraitsSet
59+from lp.translations.interfaces.side import (
60+ ITranslationSideTraitsSet,
61+ TranslationSide,
62+ )
63 from lp.translations.interfaces.translationmessage import (
64 ITranslationMessage,
65 TranslationConflict,
66@@ -268,6 +271,28 @@
67 suggestion.approve,
68 pofile, self.factory.makePerson(), lock_timestamp=old)
69
70+ def test_approve_clones_message_from_other_side_to_diverge(self):
71+ package = self.factory.makeSourcePackage()
72+ template=self.factory.makePOTemplate(
73+ distroseries=package.distroseries,
74+ sourcepackagename=package.sourcepackagename)
75+ potmsgset = self.factory.makePOTMsgSet(potemplate=template)
76+ upstream_pofile = self.factory.makePOFile('nl')
77+ ubuntu_pofile = self.factory.makePOFile('nl', potemplate=template)
78+ diverged_tm = self.factory.makeDivergedTranslationMessage(
79+ pofile=upstream_pofile, potmsgset=potmsgset)
80+ ubuntu_tm = self.factory.makeSuggestion(
81+ pofile=ubuntu_pofile, potmsgset=potmsgset)
82+ ubuntu_tm.is_current_ubuntu = True
83+
84+ ubuntu_tm.approve(upstream_pofile, self.factory.makePerson())
85+
86+ upstream_tm = potmsgset.getCurrentTranslation(
87+ upstream_pofile.potemplate, upstream_pofile.language,
88+ TranslationSide.UPSTREAM)
89+ self.assertEqual(ubuntu_tm.all_msgstrs, upstream_tm.all_msgstrs)
90+ self.assertNotEqual(ubuntu_tm, upstream_tm)
91+
92
93 class TestApproveAsDiverged(TestCaseWithFactory):
94 """Tests for `TranslationMessage.approveAsDiverged`."""