Merge lp:~jtv/launchpad/recife-limited-setcurrenttranslation into lp:~launchpad/launchpad/recife

Proposed by Jeroen T. Vermeulen
Status: Merged
Merged at revision: 9140
Proposed branch: lp:~jtv/launchpad/recife-limited-setcurrenttranslation
Merge into: lp:~launchpad/launchpad/recife
Prerequisite: lp:~jtv/launchpad/recife-552639
Diff against target: 1558 lines (+1520/-2)
5 files modified
lib/lp/translations/model/potmsgset.py (+2/-0)
lib/lp/translations/tests/helpers.py (+143/-0)
lib/lp/translations/tests/test_helpers.py (+178/-0)
lib/lp/translations/tests/test_potmsgset.py (+3/-2)
lib/lp/translations/tests/test_setcurrenttranslation.py (+1194/-0)
To merge this branch: bzr merge lp:~jtv/launchpad/recife-limited-setcurrenttranslation
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Approve
Review via email: mp+28715@code.launchpad.net

Commit message

POTMsgSet.setCurrentTranslation

Description of the change

= setCurrentTranslation tests =

This branch is basically Danilo's tests for POTMsgSet.setCurrentTranslation, with a few changes where the tests did not match the design. This chips away at the very core of the Recife project. POTMsgSet.setCurrentTranslation is to replace the most significant part (but not all the myriad functionalities and tricks) of the old and convoluted POTMsgSet.updateTranslation. We kept implementation and testing strictly separate, with me doing the former and Danilo doing the latter. The implementation is a separate branch, prerequisite to this one.

Combining the two branches was not entirely trivial, of course. Besides exhaustively testing behavior of upstream and Ubuntu translations when setting Ubuntu translations, these tests are also meant to demonstrate symmetrical behavior when going the other way. The only difference should be in choice of sharing policy between the two. (The difference in policy is in how a particular parameter will be set in browser/script code, so that shouldn't show up here).

There is still one shortcoming in this symmetry: POTMsgSet.getCurrentTranslation and POTMsgSet.getImportedTranslation still assume a hard-coded difference between "current in Ubuntu" and "current upstream" flags on TranslationMessage. In the symmetrical future, getCurrentTranslation will mean "give me whatever TranslationMessage is current on this side, whether that's upstream or Ubuntu." And getImportedTranslation will return whatever's current on the other side. (Its name will change later.) Danilo has another branch implementing this change, but it needs more changes and things quickly grow out of hand. So we decided to land the implementation and the tests for one side on the Recife feature branch. Next we'll work on completing the symmetry in a separate branch.

To run the tests:
{{{
./bin/test -m lp.translations -vv -t test_setcurrenttranslation -t potmsgset
}}}

No lint related to the changes; a bit of lint elsewhere that I could fix but it'd hurt legibility and grow the diff. Another time perhaps.

Jeroen

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :
Download full text (30.0 KiB)

Hi Jeroen,
thanks for doing this and putting up with Danilo's mess... ;-) You (two)
really achieved good test coverage it seems. I have to admit I did not trace
every test, though, to see if the coverage is complete. I trust you there.

But I *did* run the tests and they passed. Good job! ;-)

Since I could not find any real problems I had to resort to complaining about
minor stuff like long method names. Also, I think I see SQLObject code introduced.

Let me heare what you think about my comments and let's do another round.

Cheers,
Hennning

> === added file 'lib/lp/translations/tests/helpers.py'
> --- lib/lp/translations/tests/helpers.py 1970-01-01 00:00:00 +0000
> +++ lib/lp/translations/tests/helpers.py 2010-06-29 10:50:45 +0000
> @@ -0,0 +1,146 @@
> +# Copyright 2010 Canonical Ltd. This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +__all__ = [
> + 'get_all_important_translations',
> + 'make_translationmessage',
> + 'make_translationmessage_for_context',
> + ]
> +
> +from zope.security.proxy import removeSecurityProxy
> +
> +from canonical.database.sqlbase import sqlvalues
> +
> +from lp.translations.interfaces.translationmessage import (
> + RosettaTranslationOrigin,
> + TranslationValidationStatus)
> +from lp.translations.model.translationmessage import (
> + TranslationMessage)
> +
> +def make_translationmessage_for_context(factory, pofile, potmsgset=None,
> + current=True, other=False,
> + diverged=False, translations=None):
> + """A low-level way of constructing TMs appropriate to `pofile` context."""
> + assert pofile is not None, "You must pass in an existing POFile."
> +
> + potemplate = pofile.potemplate
> + if potemplate.distroseries is not None:
> + ubuntu = current
> + upstream = other
> + else:
> + ubuntu = other
> + upstream = current
> + return make_translationmessage(
> + factory, pofile, potmsgset, ubuntu, upstream, diverged, translations)
> +
> +def make_translationmessage(factory, pofile=None, potmsgset=None,
> + ubuntu=True, upstream=True,
> + diverged=False, translations=None):
> + """Creates a TranslationMessage directly and sets relevant parameters.
> +
> + This is very low level function used to test core Rosetta
> + functionality such as setCurrentTranslation() method. If not used
> + correctly, it will trigger unique constraints.
> + """
> + if pofile is None:
> + pofile = factory.makePOFile('sr')
> + if potmsgset is None:
> + potmsgset = factory.makePOTMsgSet(
> + potemplate=pofile.potemplate)
> + if translations is None:
> + translations = [factory.getUniqueString()]
> + if diverged:
> + potemplate = pofile.potemplate
> + else:
> + potemplate = None
> +
> + # Parameters we don't care about are origin, submitter and
> + # validation_status.
> + origin = RosettaTranslationOrigin.SCM
> + submitter = pofile.owner
> + validation_status = TranslationValidat...

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :
Download full text (30.4 KiB)

Hi Henning,

Thanks for a thorough review. A lot of stuff needs polishing here, and in fact some of this polish I had lost in the shenanigans I went through trying to get the branches to fit together. So a good thing you spotted them.

> > === added file 'lib/lp/translations/tests/helpers.py'
> > --- lib/lp/translations/tests/helpers.py 1970-01-01 00:00:00 +0000
> > +++ lib/lp/translations/tests/helpers.py 2010-06-29 10:50:45 +0000
> > @@ -0,0 +1,146 @@
> > +# Copyright 2010 Canonical Ltd. This software is licensed under the
> > +# GNU Affero General Public License version 3 (see the file LICENSE).
> > +
> > +__all__ = [
> > + 'get_all_important_translations',
> > + 'make_translationmessage',
> > + 'make_translationmessage_for_context',
> > + ]
> > +
> > +from zope.security.proxy import removeSecurityProxy
> > +
> > +from canonical.database.sqlbase import sqlvalues
> > +
> > +from lp.translations.interfaces.translationmessage import (
> > + RosettaTranslationOrigin,
> > + TranslationValidationStatus)
> > +from lp.translations.model.translationmessage import (
> > + TranslationMessage)
> > +
> > +def make_translationmessage_for_context(factory, pofile, potmsgset=None,

Oops, that should have been a double blank line of course. That mistake is in other places as well.

> > + current=True, other=False,
> > + diverged=False, translations=None):
> > + """A low-level way of constructing TMs appropriate to `pofile`
> context."""
> > + assert pofile is not None, "You must pass in an existing POFile."
> > +
> > + potemplate = pofile.potemplate
> > + if potemplate.distroseries is not None:
> > + ubuntu = current
> > + upstream = other
> > + else:
> > + ubuntu = other
> > + upstream = current
> > + return make_translationmessage(
> > + factory, pofile, potmsgset, ubuntu, upstream, diverged,
> translations)
> > +
> > +def make_translationmessage(factory, pofile=None, potmsgset=None,
> > + ubuntu=True, upstream=True,
> > + diverged=False, translations=None):
> > + """Creates a TranslationMessage directly and sets relevant parameters.
> > +
> > + This is very low level function used to test core Rosetta
> > + functionality such as setCurrentTranslation() method. If not used
> > + correctly, it will trigger unique constraints.
> > + """
> > + if pofile is None:
> > + pofile = factory.makePOFile('sr')
> > + if potmsgset is None:
> > + potmsgset = factory.makePOTMsgSet(
> > + potemplate=pofile.potemplate)
> > + if translations is None:
> > + translations = [factory.getUniqueString()]
> > + if diverged:
> > + potemplate = pofile.potemplate
> > + else:
> > + potemplate = None
> > +
> > + # Parameters we don't care about are origin, submitter and
> > + # validation_status.
> > + origin = RosettaTranslationOrigin.SCM
> > + submitter = pofile.owner
> > + validation_status = TranslationValidationStatus.UNKNOWN
> > +
> > + translations = dict(
> > + ...

Revision history for this message
Henning Eggers (henninge) wrote :

Thank you for your cooperation. ;-)

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 2010-07-02 13:03:30 +0000
3+++ lib/lp/translations/model/potmsgset.py 2010-07-02 13:03:32 +0000
4@@ -132,6 +132,8 @@
5 return
6
7 if value and self.incumbent_message is not None:
8+ Store.of(self.incumbent_message).add_flush_order(
9+ self.incumbent_message, translationmessage)
10 self.setFlag(self.incumbent_message, False)
11
12 setattr(translationmessage, self.flag_name, value)
13
14=== added file 'lib/lp/translations/tests/helpers.py'
15--- lib/lp/translations/tests/helpers.py 1970-01-01 00:00:00 +0000
16+++ lib/lp/translations/tests/helpers.py 2010-07-02 13:03:32 +0000
17@@ -0,0 +1,143 @@
18+# Copyright 2010 Canonical Ltd. This software is licensed under the
19+# GNU Affero General Public License version 3 (see the file LICENSE).
20+
21+__all__ = [
22+ 'summarize_current_translations',
23+ 'make_translationmessage',
24+ 'make_translationmessage_for_context',
25+ ]
26+
27+from zope.security.proxy import removeSecurityProxy
28+
29+from storm.store import Store
30+from storm.expr import Coalesce, Or
31+
32+from lp.translations.interfaces.translationmessage import (
33+ RosettaTranslationOrigin,
34+ TranslationValidationStatus)
35+from lp.translations.model.translationmessage import (
36+ TranslationMessage)
37+
38+
39+def make_translationmessage_for_context(factory, pofile, potmsgset=None,
40+ current=True, other=False,
41+ diverged=False, translations=None):
42+ """A low-level way of constructing TMs appropriate to `pofile` context."""
43+ assert pofile is not None, "You must pass in an existing POFile."
44+
45+ potemplate = pofile.potemplate
46+ if potemplate.distroseries is not None:
47+ ubuntu, upstream = current, other
48+ else:
49+ ubuntu, upstream = other, current
50+ return make_translationmessage(
51+ factory, pofile, potmsgset, ubuntu, upstream, diverged, translations)
52+
53+
54+def make_translationmessage(factory, pofile=None, potmsgset=None,
55+ ubuntu=True, upstream=True,
56+ diverged=False, translations=None):
57+ """Creates a TranslationMessage directly and sets relevant parameters.
58+
59+ This is very low level function used to test core Rosetta
60+ functionality such as setCurrentTranslation() method. If not used
61+ correctly, it will trigger unique constraints.
62+ """
63+ if pofile is None:
64+ pofile = factory.makePOFile('sr')
65+ if potmsgset is None:
66+ potmsgset = factory.makePOTMsgSet(
67+ potemplate=pofile.potemplate)
68+ if translations is None:
69+ translations = [factory.getUniqueString()]
70+ if diverged:
71+ potemplate = pofile.potemplate
72+ else:
73+ potemplate = None
74+
75+ # Parameters we don't care about are origin, submitter and
76+ # validation_status.
77+ origin = RosettaTranslationOrigin.SCM
78+ submitter = pofile.owner
79+ validation_status = TranslationValidationStatus.UNKNOWN
80+
81+ translations = dict(enumerate(translations))
82+
83+ potranslations = removeSecurityProxy(
84+ potmsgset)._findPOTranslations(translations)
85+ new_message = TranslationMessage(
86+ potmsgset=potmsgset,
87+ potemplate=potemplate,
88+ pofile=None,
89+ language=pofile.language,
90+ variant=pofile.variant,
91+ origin=origin,
92+ submitter=submitter,
93+ msgstr0=potranslations[0],
94+ msgstr1=potranslations[1],
95+ msgstr2=potranslations[2],
96+ msgstr3=potranslations[3],
97+ msgstr4=potranslations[4],
98+ msgstr5=potranslations[5],
99+ validation_status=validation_status,
100+ is_current_ubuntu=ubuntu,
101+ is_current_upstream=upstream)
102+ return new_message
103+
104+
105+def get_all_translations_current_anywhere(pofile, potmsgset):
106+ """Get current `TranslationMessage`s for this `POTMsgSet` and language.
107+
108+ The `TranslationMessage`s can be in use anywhere; the `pofile` only
109+ selects the language.
110+ """
111+ result = Store.of(potmsgset).find(
112+ TranslationMessage,
113+ TranslationMessage.potmsgset == potmsgset,
114+ Or(
115+ TranslationMessage.is_current_ubuntu == True,
116+ TranslationMessage.is_current_upstream == True),
117+ TranslationMessage.potemplate != None,
118+ TranslationMessage.language == pofile.language,
119+ TranslationMessage.variant == pofile.variant)
120+ return result.order_by(-Coalesce(TranslationMessage.potemplateID, -1))
121+
122+
123+def summarize_current_translations(pofile, potmsgset):
124+ """Return all existing current translations for `POTMsgSet`.
125+
126+ Returns a tuple containing 4 elements:
127+ * current, shared translation for `potmsgset`.
128+ * diverged translation for `potmsgset` in `pofile`, or None.
129+ * shared translation for `potmsgset` in "other" context.
130+ * list of all other diverged translations (not including the one
131+ diverged in `pofile`) or an empty list if there are none.
132+ """
133+ current_shared = potmsgset.getCurrentTranslationMessage(
134+ None, pofile.language, pofile.variant)
135+ current_diverged = potmsgset.getCurrentTranslationMessage(
136+ pofile.potemplate, pofile.language, pofile.variant)
137+ if current_diverged is not None and not current_diverged.is_diverged:
138+ current_diverged = None
139+
140+ other_shared = potmsgset.getImportedTranslationMessage(
141+ None, pofile.language, pofile.variant)
142+ other_diverged = potmsgset.getImportedTranslationMessage(
143+ pofile.potemplate, pofile.language, pofile.variant)
144+ assert other_diverged is None or other_diverged.potemplate is None, (
145+ "There is a diverged 'other' translation for "
146+ "this same template, which should be impossible.")
147+
148+ all_used = get_all_translations_current_anywhere(
149+ pofile, potmsgset)
150+ diverged = []
151+ for suggestion in all_used:
152+ if ((suggestion.potemplate is not None and
153+ suggestion.potemplate != pofile.potemplate) and
154+ (suggestion.is_current_ubuntu or
155+ suggestion.is_current_upstream)):
156+ # It's diverged for another template and current somewhere.
157+ diverged.append(suggestion)
158+ return (
159+ current_shared, current_diverged,
160+ other_shared, diverged)
161
162=== added file 'lib/lp/translations/tests/test_helpers.py'
163--- lib/lp/translations/tests/test_helpers.py 1970-01-01 00:00:00 +0000
164+++ lib/lp/translations/tests/test_helpers.py 2010-07-02 13:03:32 +0000
165@@ -0,0 +1,178 @@
166+# Copyright 2010 Canonical Ltd. This software is licensed under the
167+# GNU Affero General Public License version 3 (see the file LICENSE).
168+
169+__metaclass__ = type
170+
171+from zope.component import getUtility
172+
173+from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
174+from canonical.testing import ZopelessDatabaseLayer
175+
176+from lp.testing import TestCaseWithFactory
177+
178+from lp.translations.tests.helpers import (
179+ make_translationmessage,
180+ summarize_current_translations)
181+
182+
183+class TestTranslationMessageHelpers(TestCaseWithFactory):
184+ """Test discovery of translation suggestions."""
185+
186+ layer = ZopelessDatabaseLayer
187+
188+ def setUp(self):
189+ super(TestTranslationMessageHelpers, self).setUp()
190+ ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
191+ new_series = self.factory.makeDistroSeries(distribution=ubuntu)
192+ sourcepackagename = self.factory.makeSourcePackageName()
193+ potemplate = self.factory.makePOTemplate(
194+ distroseries=new_series,
195+ sourcepackagename=sourcepackagename)
196+ self.pofile = self.factory.makePOFile('sr', potemplate=potemplate)
197+ self.potmsgset = self.factory.makePOTMsgSet(
198+ potemplate=potemplate, sequence=1)
199+
200+ # A POFile in a different context from self.pofile.
201+ self.other_pofile = self.factory.makePOFile(
202+ language_code=self.pofile.language.code,
203+ variant=self.pofile.variant)
204+
205+ def test_make_translationmessage(self):
206+ translations = [u"testing"]
207+ tm = make_translationmessage(self.factory, pofile=self.pofile,
208+ potmsgset=self.potmsgset,
209+ translations=translations)
210+ self.assertEquals(translations, tm.translations)
211+
212+ def test_summarize_current_translations_baseline(self):
213+ # The trivial case for summarize_current_translations: no
214+ # translations at all.
215+ current_shared, current_diverged, other, divergences = (
216+ summarize_current_translations(self.pofile, self.potmsgset))
217+ self.assertIs(None, current_shared)
218+ self.assertIs(None, current_diverged)
219+ self.assertIs(None, other)
220+ self.assertEquals([], divergences)
221+
222+ def test_summarize_current_translations_current_shared(self):
223+ # summarize_current_translations when there is a single, shared
224+ # current message.
225+ tm = make_translationmessage(
226+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
227+ ubuntu=True, upstream=False, diverged=False)
228+ current_shared, current_diverged, other, divergences = (
229+ summarize_current_translations(self.pofile, self.potmsgset))
230+ self.assertEquals(tm, current_shared)
231+ self.assertIs(None, current_diverged)
232+ self.assertIs(None, other)
233+ self.assertEquals([], divergences)
234+
235+ def test_summarize_current_translations_current_both(self):
236+ # summarize_current_translations when there is a single message
237+ # shared between Ubuntu and upstream.
238+ tm = make_translationmessage(
239+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
240+ ubuntu=True, upstream=True, diverged=False)
241+ current_shared, current_diverged, other, divergences = (
242+ summarize_current_translations(self.pofile, self.potmsgset))
243+ self.assertEquals(tm, current_shared)
244+ self.assertIs(None, current_diverged)
245+ self.assertEquals(tm, other)
246+ self.assertEquals([], divergences)
247+
248+ def test_summarize_current_translations_current_both_same(self):
249+ # summarize_current_translations when there are identical but
250+ # separate shared current messages on the Ubuntu side and
251+ # upstream.
252+ tm_ubuntu = make_translationmessage(
253+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
254+ ubuntu=True, upstream=False, diverged=False)
255+ tm_upstream = make_translationmessage(
256+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
257+ ubuntu=False, upstream=True, diverged=False)
258+ current_shared, current_diverged, other, divergences = (
259+ summarize_current_translations(self.pofile, self.potmsgset))
260+
261+ self.assertIn(current_shared, (tm_ubuntu, tm_upstream))
262+ if self.pofile.potemplate.distroseries is not None:
263+ self.assertEquals(tm_ubuntu, current_shared)
264+ else:
265+ self.assertEquals(tm_upstream, current_shared)
266+
267+ self.assertIs(None, current_diverged)
268+ self.assertIn(other, (tm_ubuntu, tm_upstream))
269+ self.assertNotEqual(current_shared, other)
270+ self.assertEquals([], divergences)
271+
272+ def test_summarize_current_translations_current_2_different(self):
273+ # summarize_current_translations when there are different
274+ # shared, current translations on the Ubuntu and upstream sides.
275+ tm_this = make_translationmessage(
276+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
277+ ubuntu=True, upstream=False, diverged=False)
278+ tm_other = make_translationmessage(
279+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
280+ ubuntu=False, upstream=True, diverged=False)
281+ current_shared, current_diverged, other, divergences = (
282+ summarize_current_translations(self.pofile, self.potmsgset))
283+ self.assertEquals(tm_this, current_shared)
284+ self.assertIs(None, current_diverged)
285+ self.assertEquals(tm_other, other)
286+ self.assertEquals([], divergences)
287+
288+ def test_summarize_current_translations_current_3_different(self):
289+ # summarize_current_translations when there are different
290+ # shared current messages on the Ubuntu side and upstream, and
291+ # there is also a diverged message.
292+ tm_this = make_translationmessage(
293+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
294+ ubuntu=True, upstream=False, diverged=False)
295+ tm_other = make_translationmessage(
296+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
297+ ubuntu=False, upstream=True, diverged=False)
298+ tm_diverged = make_translationmessage(
299+ self.factory, pofile=self.pofile, potmsgset=self.potmsgset,
300+ ubuntu=True, upstream=False, diverged=True)
301+ current_shared, current_diverged, other, divergences = (
302+ summarize_current_translations(self.pofile, self.potmsgset))
303+ self.assertEquals(tm_this, current_shared)
304+ self.assertEquals(tm_diverged, current_diverged)
305+ self.assertEquals(tm_other, other)
306+ self.assertEquals([], divergences)
307+
308+ def test_summarize_current_translations_current_3_diverged_elsewh(self):
309+ # summarize_current_translations when there are different
310+ # shared current messages on the Ubuntu side and upstream, and
311+ # there is also a diverged message in another template than the
312+ # one we're looking at.
313+ tm_diverged = make_translationmessage(
314+ self.factory, pofile=self.other_pofile, potmsgset=self.potmsgset,
315+ ubuntu=True, upstream=False, diverged=True)
316+ self.assertTrue(tm_diverged.is_current_ubuntu)
317+ self.assertEquals(
318+ tm_diverged.potemplate, self.other_pofile.potemplate)
319+ self.assertEquals(self.potmsgset, tm_diverged.potmsgset)
320+ current_shared, current_diverged, other, divergences = (
321+ summarize_current_translations(self.pofile, self.potmsgset))
322+ self.assertIs(None, current_shared)
323+ self.assertIs(None, current_diverged)
324+ self.assertIs(None, other)
325+ self.assertEquals([tm_diverged], divergences)
326+
327+ def test_summarize_current_translations_multiple_divergences_elswh(self):
328+ tm_diverged1 = make_translationmessage(
329+ self.factory, pofile=self.other_pofile, potmsgset=self.potmsgset,
330+ ubuntu=True, upstream=False, diverged=True)
331+
332+ potemplate2 = self.factory.makePOTemplate(
333+ productseries=self.factory.makeProductSeries(
334+ product=self.pofile.potemplate.productseries.product))
335+ pofile2 = self.factory.makePOFile(
336+ self.pofile.language.code, potemplate=potemplate2)
337+ tm_diverged2 = make_translationmessage(
338+ self.factory, pofile=pofile2, potmsgset=self.potmsgset)
339+
340+ current_shared, current_diverged, other, divergences = (
341+ summarize_current_translations(self.pofile, self.potmsgset))
342+
343+ self.assertContentEqual([tm_diverged1, tm_diverged2], divergences)
344
345=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
346--- lib/lp/translations/tests/test_potmsgset.py 2010-07-02 13:03:30 +0000
347+++ lib/lp/translations/tests/test_potmsgset.py 2010-07-02 13:03:32 +0000
348@@ -960,8 +960,9 @@
349 self.assertTrue(translation.potemplate is None)
350
351 def test_resetCurrentTranslation_diverged_not_imported(self):
352- # Resettting a diverged current translation that was not imported, will
353- # change is_current_ubuntu to False and will make it shared.
354+ # Resettting a diverged current translation that was not
355+ # imported will change is_current_ubuntu to False and will make
356+ # it shared.
357
358 translation = self.factory.makeTranslationMessage(
359 self.pofile, self.potmsgset, translations=[u'Diverged text'],
360
361=== added file 'lib/lp/translations/tests/test_setcurrenttranslation.py'
362--- lib/lp/translations/tests/test_setcurrenttranslation.py 1970-01-01 00:00:00 +0000
363+++ lib/lp/translations/tests/test_setcurrenttranslation.py 2010-07-02 13:03:32 +0000
364@@ -0,0 +1,1194 @@
365+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
366+# GNU Affero General Public License version 3 (see the file LICENSE).
367+
368+# pylint: disable-msg=C0102
369+
370+__metaclass__ = type
371+
372+from zope.component import getUtility
373+
374+from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
375+from canonical.testing import ZopelessDatabaseLayer
376+
377+from lp.testing import TestCaseWithFactory
378+from lp.translations.interfaces.translationmessage import (
379+ RosettaTranslationOrigin)
380+from lp.translations.interfaces.translations import (
381+ TranslationSide)
382+from lp.translations.model.translationmessage import (
383+ TranslationMessage)
384+
385+from lp.translations.tests.helpers import (
386+ make_translationmessage_for_context,
387+ summarize_current_translations)
388+
389+
390+# This test is based on the matrix described on:
391+# https://dev.launchpad.net/Translations/Specs
392+# /UpstreamImportIntoUbuntu/FixingIsImported
393+# /setCurrentTranslation#Execution%20matrix
394+
395+class SetCurrentTranslationTestMixin:
396+ """Tests for `POTMsgSet.setCurrentTranslation`.
397+
398+ Depending on the setUp implementation available, this can test
399+ either from the perspective of translating an Ubuntu template or
400+ from the perspective of translating an upstream template.
401+ """
402+
403+ def constructTranslationMessage(self, pofile=None, potmsgset=None,
404+ current=True, other=False, diverged=False,
405+ translations=None):
406+ """Creates a TranslationMessage directly for `pofile` context."""
407+ if pofile is None:
408+ pofile = self.pofile
409+ if potmsgset is None:
410+ potmsgset = self.potmsgset
411+ return make_translationmessage_for_context(
412+ self.factory, pofile, potmsgset,
413+ current, other, diverged, translations)
414+
415+ def constructOtherTranslationMessage(self, potmsgset=None, current=True,
416+ other=False, diverged=False,
417+ translations=None):
418+ """Creates a TranslationMessage for self.other_pofile context."""
419+ return self.constructTranslationMessage(
420+ self.other_pofile, potmsgset, current, other, diverged,
421+ translations)
422+
423+ def constructDivergingTranslationMessage(self, potmsgset=None,
424+ current=True, other=False,
425+ diverged=False,
426+ translations=None):
427+ """Creates a TranslationMessage for self.diverging_pofile context."""
428+ return self.constructTranslationMessage(
429+ self.diverging_pofile, potmsgset, current, other, diverged,
430+ translations)
431+
432+ def setCurrentTranslation(self, translations,
433+ share_with_other_side=False):
434+ """Helper method to call 'setCurrentTranslation' method.
435+
436+ It passes all the same parameters we use throughout the tests,
437+ including self.potmsgset, self.pofile, self.pofile.owner and origin.
438+ """
439+ translations = dict(enumerate(translations))
440+ return self.potmsgset.setCurrentTranslation(
441+ self.pofile, self.pofile.owner, translations,
442+ origin=RosettaTranslationOrigin.ROSETTAWEB,
443+ translation_side=TranslationSide.UBUNTU,
444+ share_with_other_side=share_with_other_side)
445+
446+ def assert_Current_Diverged_Other_DivergencesElsewhere_are(
447+ self, current, diverged, other_shared, divergences_elsewhere):
448+ """Assert that 'important' translations match passed-in values.
449+
450+ Takes four parameters:
451+ * current: represents a current shared translation for this context.
452+ * diverged: represents a diverged translation for this context.
453+ * other_shared: represents a shared translation for "other" context.
454+ * divergences_elsewhere: a list of other divergences in both contexts.
455+ """
456+ new_current, new_diverged, new_other, new_divergences = (
457+ summarize_current_translations(self.pofile, self.potmsgset))
458+
459+ if new_current is None:
460+ self.assertIs(new_current, current)
461+ else:
462+ self.assertEquals(new_current, current)
463+ if new_diverged is None:
464+ self.assertIs(new_diverged, diverged)
465+ else:
466+ self.assertEquals(new_diverged, diverged)
467+ if new_other is None:
468+ self.assertIs(new_other, other_shared)
469+ else:
470+ self.assertEquals(new_other, other_shared)
471+
472+ self.assertContentEqual(new_divergences, divergences_elsewhere)
473+
474+ def assertTranslationMessageDeleted(self, translationmessage_id):
475+ """Assert that a translation message doesn't exist.
476+
477+ Until deletion of TMs is implemented, it just checks that
478+ translation message is not current in any context.
479+ """
480+ # XXX DaniloSegan 20100528: we should assert that tm_other
481+ # doesn't exist in the DB anymore instead.
482+ tm = TranslationMessage.get(translationmessage_id)
483+ self.assertFalse(tm.is_current_ubuntu)
484+ self.assertFalse(tm.is_current_upstream)
485+ self.assertIs(None, tm.potemplate)
486+
487+ # These tests follow a naming pattern to reflect exhaustive
488+ # coverage. We had to abbreviate them. In the names,
489+ # 'c' means the current message translating self.potmsgset in
490+ # self.pofile;
491+ # 'n' means the "new" message, i.e. a pre-existing translation for
492+ # self.potmsgset with the same translation text that the test
493+ # will set;
494+ # 'o' means a message on the "other side," i.e. a shared message
495+ # that is current there. (We don't care about diverged
496+ # messages on the other side since those would be for a
497+ # different template than the one we're working on).
498+
499+ def test_c_None__n_None__o_None(self):
500+ # Current translation is None, and we have found no
501+ # existing TM matching new translations.
502+ # There is neither 'other' current translation.
503+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
504+ None, None, None, [])
505+
506+ new_translations = [self.factory.getUniqueString()]
507+ tm = self.setCurrentTranslation(new_translations)
508+
509+ # We end up with a shared current translation.
510+ self.assertTrue(tm is not None)
511+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
512+ tm, None, None, [])
513+
514+ def test_c_None__n_None__o_None__follows(self):
515+ # Current translation is None, and we have found no
516+ # existing TM matching new translations.
517+ # There is neither 'other' current translation.
518+
519+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
520+ None, None, None, [])
521+
522+ new_translations = [self.factory.getUniqueString()]
523+ tm = self.setCurrentTranslation(
524+ new_translations, share_with_other_side=True)
525+
526+ # We end up with a shared current translation,
527+ # activated in other context as well.
528+ self.assertTrue(tm is not None)
529+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
530+ tm, None, tm, [])
531+
532+ def test_c_None__n_None__o_shared(self, follows=False):
533+ # Current translation is None, and we have found no
534+ # existing TM matching new translations.
535+ # There is a current translation in "other" context.
536+ tm_other = self.constructOtherTranslationMessage(
537+ current=True, other=False, diverged=False)
538+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
539+ None, None, tm_other, [])
540+
541+ new_translations = [self.factory.getUniqueString()]
542+ tm = self.setCurrentTranslation(
543+ new_translations, share_with_other_side=follows)
544+
545+ # We end up with a shared current translation.
546+ # Current for other context one stays the same.
547+ self.assertTrue(tm is not None)
548+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
549+ tm, None, tm_other, [])
550+
551+ def test_c_None__n_None__o_shared__follows(self):
552+ # There is no current translation, though there is a shared one
553+ # on the other side. There is no message with translations
554+ # identical to the one we're setting.
555+ # The sharing policy has no effect in this case.
556+ self.test_c_None__n_None__o_shared(follows=True)
557+
558+ def test_c_None__n_None__o_diverged(self):
559+ # Current translation is None, and we have found no
560+ # existing TM matching new translations.
561+ # There is a current but diverged translation in "other" context.
562+ tm_other = self.constructOtherTranslationMessage(
563+ current=True, other=False, diverged=True)
564+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
565+ None, None, None, [tm_other])
566+
567+ new_translations = [self.factory.getUniqueString()]
568+ tm = self.setCurrentTranslation(new_translations)
569+
570+ # We end up with a shared current translation.
571+ self.assertTrue(tm is not None)
572+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
573+ tm, None, None, [tm_other])
574+
575+ # Previously current is still diverged and current
576+ # in exactly one context.
577+ self.assertFalse(
578+ tm_other.is_current_upstream and tm_other.is_current_ubuntu)
579+ self.assertTrue(
580+ tm_other.is_current_upstream or tm_other.is_current_ubuntu)
581+ self.assertEquals(self.other_pofile.potemplate, tm_other.potemplate)
582+
583+ def test_c_None__n_None__o_diverged__follows(self):
584+ # Current translation is None, and we have found no
585+ # existing TM matching new translations.
586+ # There is a current but diverged translation in "other" context.
587+ tm_other = self.constructOtherTranslationMessage(
588+ current=True, other=False, diverged=True)
589+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
590+ None, None, None, [tm_other])
591+
592+ new_translations = [self.factory.getUniqueString()]
593+ tm = self.setCurrentTranslation(
594+ new_translations, share_with_other_side=True)
595+
596+ # We end up with a shared current translation.
597+ self.assertTrue(tm is not None)
598+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
599+ tm, None, tm, [tm_other])
600+
601+ # Previously current is still diverged and current
602+ # in exactly one context.
603+ self.assertFalse(tm_other.is_current_upstream and
604+ tm_other.is_current_ubuntu)
605+ self.assertTrue(tm_other.is_current_upstream or
606+ tm_other.is_current_ubuntu)
607+ self.assertEquals(self.other_pofile.potemplate, tm_other.potemplate)
608+
609+ def test_c_None__n_shared__o_None(self):
610+ # Current translation is None, and we have found a
611+ # shared existing TM matching new translations (a regular suggestion).
612+ # There is neither 'other' current translation.
613+ new_translations = [self.factory.getUniqueString()]
614+ tm_suggestion = self.constructTranslationMessage(
615+ current=False, other=False, diverged=False,
616+ translations=new_translations)
617+
618+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
619+ None, None, None, [])
620+
621+ tm = self.setCurrentTranslation(new_translations)
622+
623+ # We end up with tm_suggestion being activated.
624+ self.assertTrue(tm is not None)
625+ self.assertEquals(tm_suggestion, tm)
626+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
627+ tm, None, None, [])
628+
629+ def test_c_None__n_shared__o_None__follows(self):
630+ # Current translation is None, and we have found a
631+ # shared existing TM matching new translations (a regular suggestion).
632+ # There is neither 'other' current translation.
633+ new_translations = [self.factory.getUniqueString()]
634+ tm_suggestion = self.constructTranslationMessage(
635+ current=False, other=False, diverged=False,
636+ translations=new_translations)
637+
638+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
639+ None, None, None, [])
640+
641+ tm = self.setCurrentTranslation(
642+ new_translations, share_with_other_side=True)
643+
644+ # We end up with tm_suggestion being activated in both contexts.
645+ self.assertTrue(tm is not None)
646+ self.assertEquals(tm_suggestion, tm)
647+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
648+ tm, None, tm, [])
649+
650+ def test_c_None__n_shared__o_shared(self):
651+ # Current translation is None, and we have found a
652+ # shared existing TM matching new translations (a regular suggestion).
653+ # There is a current translation in "other" context.
654+ new_translations = [self.factory.getUniqueString()]
655+ tm_suggestion = self.constructTranslationMessage(
656+ current=False, other=False, diverged=False,
657+ translations=new_translations)
658+ tm_other = self.constructOtherTranslationMessage(
659+ current=True, other=False, diverged=False)
660+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
661+ None, None, tm_other, [])
662+
663+ tm = self.setCurrentTranslation(new_translations)
664+
665+ # tm_suggestion becomes current.
666+ # Current for other context one stays the same.
667+ self.assertTrue(tm is not None)
668+ self.assertEquals(tm_suggestion, tm)
669+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
670+ tm, None, tm_other, [])
671+
672+ def test_c_None__n_shared__o_shared__follows(self):
673+ # Current translation is None, and we have found a
674+ # shared existing TM matching new translations (a regular suggestion).
675+ # There is a current translation in "other" context.
676+ new_translations = [self.factory.getUniqueString()]
677+ tm_suggestion = self.constructTranslationMessage(
678+ current=False, other=False, diverged=False,
679+ translations=new_translations)
680+ tm_other = self.constructOtherTranslationMessage(
681+ current=True, other=False, diverged=False)
682+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
683+ None, None, tm_other, [])
684+
685+ tm = self.setCurrentTranslation(
686+ new_translations, share_with_other_side=True)
687+
688+ # tm_suggestion becomes current.
689+ # Current for other context one stays the same.
690+ self.assertTrue(tm is not None)
691+ self.assertEquals(tm_suggestion, tm)
692+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
693+ tm, None, tm_other, [])
694+
695+ def test_c_None__n_shared__o_shared__identical(self,
696+ follows=False):
697+ # Current translation is None, and we have found a
698+ # shared existing TM matching new translations and it's
699+ # also a current translation in "other" context.
700+ new_translations = [self.factory.getUniqueString()]
701+ tm_other = self.constructOtherTranslationMessage(
702+ current=True, other=False, diverged=False,
703+ translations=new_translations)
704+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
705+ None, None, tm_other, [])
706+
707+ tm = self.setCurrentTranslation(
708+ new_translations, share_with_other_side=follows)
709+
710+ # tm_other becomes current in this context as well,
711+ # and remains current for the other context.
712+ self.assertTrue(tm is not None)
713+ self.assertEquals(tm_other, tm)
714+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
715+ tm, None, tm, [])
716+
717+ def test_c_None__n_shared__o_shared__identical__follows(self):
718+ # As above, and 'share_with_other_side' is a no-op in this case.
719+ self.test_c_None__n_shared__o_shared__identical(follows=True)
720+
721+ def test_c_None__n_shared__o_diverged(self):
722+ # Current translation is None, and we have found a
723+ # shared existing TM matching new translations (a regular suggestion).
724+ # There is a current but diverged translation in "other" context.
725+ new_translations = [self.factory.getUniqueString()]
726+ tm_suggestion = self.constructTranslationMessage(
727+ current=False, other=False, diverged=False,
728+ translations=new_translations)
729+ tm_other = self.constructOtherTranslationMessage(
730+ current=True, other=False, diverged=True)
731+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
732+ None, None, None, [tm_other])
733+
734+ tm = self.setCurrentTranslation(new_translations)
735+
736+ # We end up with a shared current translation.
737+ self.assertTrue(tm is not None)
738+ self.assertEquals(tm_suggestion, tm)
739+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
740+ tm, None, None, [tm_other])
741+
742+ # Previously current is still diverged and current
743+ # in exactly one context.
744+ self.assertFalse(tm_other.is_current_upstream and
745+ tm_other.is_current_ubuntu)
746+ self.assertTrue(tm_other.is_current_upstream or
747+ tm_other.is_current_ubuntu)
748+ self.assertEquals(self.other_pofile.potemplate, tm_other.potemplate)
749+
750+ def test_c_None__n_shared__o_diverged__follows(self):
751+ # Current translation is None, and we have found a
752+ # shared existing TM matching new translations (a regular suggestion).
753+ # There is a current but diverged translation in "other" context.
754+ new_translations = [self.factory.getUniqueString()]
755+ tm_suggestion = self.constructTranslationMessage(
756+ current=False, other=False, diverged=False,
757+ translations=new_translations)
758+ tm_other = self.constructOtherTranslationMessage(
759+ current=True, other=False, diverged=True)
760+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
761+ None, None, None, [tm_other])
762+
763+ tm = self.setCurrentTranslation(
764+ new_translations, share_with_other_side=True)
765+
766+ # We end up with a shared current translation.
767+ self.assertTrue(tm is not None)
768+ self.assertEquals(tm_suggestion, tm)
769+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
770+ tm, None, tm, [tm_other])
771+
772+ # Previously current is still diverged and current
773+ # in exactly one context.
774+ self.assertFalse(
775+ tm_other.is_current_upstream and tm_other.is_current_ubuntu)
776+ self.assertTrue(
777+ tm_other.is_current_upstream or tm_other.is_current_ubuntu)
778+ self.assertEquals(self.other_pofile.potemplate, tm_other.potemplate)
779+
780+ def test_c_shared__n_None__o_None(self):
781+ # Current translation is 'shared', and we have found
782+ # no existing TM matching new translations.
783+ # There is neither a translation for "other" context.
784+ new_translations = [self.factory.getUniqueString()]
785+ tm_shared = self.constructTranslationMessage(
786+ current=True, other=False, diverged=False)
787+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
788+ tm_shared, None, None, [])
789+
790+ tm = self.setCurrentTranslation(new_translations)
791+
792+ # New translation message is shared and current only for
793+ # the active context.
794+ self.assertTrue(tm is not None)
795+ self.assertNotEquals(tm_shared, tm)
796+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
797+ tm, None, None, [])
798+
799+ # Previously current is not current anymore.
800+ self.assertFalse(
801+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
802+
803+ def test_c_shared__n_None__o_None__follows(self):
804+ # Current translation is 'shared', and we have found
805+ # no existing TM matching new translations.
806+ # There is neither a translation for "other" context.
807+ new_translations = [self.factory.getUniqueString()]
808+ tm_shared = self.constructTranslationMessage(
809+ current=True, other=False, diverged=False)
810+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
811+ tm_shared, None, None, [])
812+
813+ tm = self.setCurrentTranslation(
814+ new_translations, share_with_other_side=True)
815+
816+ # New translation message is shared and current for both
817+ # active and "other" context.
818+ self.assertTrue(tm is not None)
819+ self.assertNotEquals(tm_shared, tm)
820+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
821+ tm, None, tm, [])
822+
823+ # Previously current is not current anymore.
824+ self.assertFalse(
825+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
826+
827+ def test_c_shared__n_None__o_shared(self, follows=False):
828+ # Current translation is 'shared', and we have found
829+ # no existing TM matching new translations.
830+ # There is a shared translation for "other" context.
831+ new_translations = [self.factory.getUniqueString()]
832+ tm_shared = self.constructTranslationMessage(
833+ current=True, other=False, diverged=False)
834+ tm_other = self.constructOtherTranslationMessage(
835+ current=True, other=False, diverged=False)
836+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
837+ tm_shared, None, tm_other, [])
838+
839+ tm = self.setCurrentTranslation(
840+ new_translations, share_with_other_side=follows)
841+
842+ # New translation message is shared and current only for
843+ # the active context. Current for "other" context is left
844+ # untouched.
845+ self.assertTrue(tm is not None)
846+ self.assertNotEquals(tm_shared, tm)
847+ self.assertNotEquals(tm_other, tm)
848+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
849+ tm, None, tm_other, [])
850+
851+ # Previously current is not current anymore.
852+ self.assertFalse(
853+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
854+
855+ def test_c_shared__n_None__o_shared__follows(self):
856+ # The choice of sharing policy has no effect when the Ubuntu
857+ # translation differs from the upstream translation.
858+ self.test_c_shared__n_None__o_shared(follows=True)
859+
860+ def test_c_shared__n_shared__o_None(self):
861+ # Current translation is 'shared', and we have found
862+ # a shared existing TM matching new translations (a suggestion).
863+ # There is no translation for "other" context.
864+ new_translations = [self.factory.getUniqueString()]
865+ tm_shared = self.constructTranslationMessage(
866+ current=True, other=False, diverged=False)
867+ tm_suggestion = self.constructTranslationMessage(
868+ current=False, other=False, diverged=False,
869+ translations=new_translations)
870+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
871+ tm_shared, None, None, [])
872+
873+ tm = self.setCurrentTranslation(new_translations)
874+
875+ # New translation message is shared and current only for
876+ # the active context.
877+ self.assertTrue(tm is not None)
878+ self.assertNotEquals(tm_shared, tm)
879+ self.assertEquals(tm_suggestion, tm)
880+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
881+ tm, None, None, [])
882+
883+ # Previous shared translation is now a suggestion.
884+ self.assertFalse(
885+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
886+
887+ def test_c_shared__n_shared__o_None__follows(self):
888+ # Current translation is 'shared', and we have found
889+ # a shared existing TM matching new translations (a suggestion).
890+ # There is no translation for "other" context.
891+ new_translations = [self.factory.getUniqueString()]
892+ tm_shared = self.constructTranslationMessage(
893+ current=True, other=False, diverged=False)
894+ tm_suggestion = self.constructTranslationMessage(
895+ current=False, other=False, diverged=False,
896+ translations=new_translations)
897+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
898+ tm_shared, None, None, [])
899+
900+ tm = self.setCurrentTranslation(
901+ new_translations, share_with_other_side=True)
902+
903+ # New translation message is shared and current only for
904+ # the active context.
905+ self.assertTrue(tm is not None)
906+ self.assertNotEquals(tm_shared, tm)
907+ self.assertEquals(tm_suggestion, tm)
908+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
909+ tm, None, tm, [])
910+
911+ # Previous shared translation is now a suggestion.
912+ self.assertFalse(
913+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
914+
915+ def test_c_shared__n_shared__o_None__identical(self):
916+ # Current translation is 'shared', and we are trying
917+ # to change it to identical translations. NO-OP.
918+ # There is no translation for "other" context.
919+ new_translations = [self.factory.getUniqueString()]
920+ tm_shared = self.constructTranslationMessage(
921+ current=True, other=False, diverged=False,
922+ translations=new_translations)
923+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
924+ tm_shared, None, None, [])
925+
926+ tm = self.setCurrentTranslation(new_translations)
927+
928+ # New translation message is shared and current only for
929+ # the active context.
930+ self.assertTrue(tm is not None)
931+ self.assertEquals(tm_shared, tm)
932+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
933+ tm, None, None, [])
934+
935+ def test_c_shared__n_shared__o_None__identical__follows(self):
936+ # Current translation is 'shared', and we are trying
937+ # to change it to identical translations.
938+ # There is no translation for "other" context.
939+ new_translations = [self.factory.getUniqueString()]
940+ tm_shared = self.constructTranslationMessage(
941+ current=True, other=False, diverged=False,
942+ translations=new_translations)
943+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
944+ tm_shared, None, None, [])
945+
946+ tm = self.setCurrentTranslation(
947+ new_translations, share_with_other_side=True)
948+
949+ # New translation message is shared and current for both contexts.
950+ self.assertTrue(tm is not None)
951+ self.assertEquals(tm_shared, tm)
952+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
953+ tm, None, tm, [])
954+
955+ def test_c_shared__n_shared__o_shared(self, follows=False):
956+ # Current translation is 'shared', and we have found
957+ # a shared existing TM matching new translations (a suggestion).
958+ # There is a shared translation for "other" context.
959+ new_translations = [self.factory.getUniqueString()]
960+ tm_shared = self.constructTranslationMessage(
961+ current=True, other=False, diverged=False)
962+ tm_suggestion = self.constructTranslationMessage(
963+ current=False, other=False, diverged=False,
964+ translations=new_translations)
965+ tm_other = self.constructOtherTranslationMessage(
966+ current=True, other=False, diverged=False)
967+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
968+ tm_shared, None, tm_other, [])
969+
970+ tm = self.setCurrentTranslation(
971+ new_translations, share_with_other_side=follows)
972+
973+ # New translation message is shared and current only for
974+ # the active context. Translation for other context is untouched.
975+ self.assertTrue(tm is not None)
976+ self.assertNotEquals(tm_shared, tm)
977+ self.assertEquals(tm_suggestion, tm)
978+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
979+ tm, None, tm_other, [])
980+
981+ # Previous shared translation is now a suggestion.
982+ self.assertFalse(
983+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
984+
985+ def test_c_shared__n_shared__o_shared__follows(self):
986+ # The choice of sharing policy has no effect when the Ubuntu
987+ # translation differs from the upstream translation.
988+ self.test_c_shared__n_shared__o_shared(follows=True)
989+
990+ def test_c_shared__n_shared__o_shared__identical(self, follows=False):
991+ # Current translation is 'shared', and we have found
992+ # a shared existing TM matching new translations that is
993+ # also current for "other" context.
994+ new_translations = [self.factory.getUniqueString()]
995+ tm_shared = self.constructTranslationMessage(
996+ current=True, other=False, diverged=False)
997+ tm_other = self.constructOtherTranslationMessage(
998+ current=True, other=False, diverged=False,
999+ translations=new_translations)
1000+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1001+ tm_shared, None, tm_other, [])
1002+
1003+ tm = self.setCurrentTranslation(
1004+ new_translations, share_with_other_side=follows)
1005+
1006+ # New translation message is shared for both contexts.
1007+ self.assertTrue(tm is not None)
1008+ self.assertNotEquals(tm_shared, tm)
1009+ self.assertEquals(tm_other, tm)
1010+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1011+ tm, None, tm, [])
1012+
1013+ # Previous shared translation is now a suggestion.
1014+ self.assertFalse(
1015+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
1016+
1017+ def test_c_shared__n_shared__o_shared_identical_follows(self):
1018+ # Since we are converging to the 'other' context anyway, it behaves
1019+ # the same when 'share_with_other_side=True' is passed in.
1020+ self.test_c_shared__n_shared__o_shared__identical(follows=True)
1021+
1022+ def test_c_shared__n_shared__o_diverged__identical(self):
1023+ # Current translation is 'shared', and we have found
1024+ # a shared existing TM matching new translations (a suggestion).
1025+ # There is a divergence in the 'other' context that is
1026+ # exactly the same as the new translation.
1027+ new_translations = [self.factory.getUniqueString()]
1028+ tm_shared = self.constructTranslationMessage(
1029+ current=True, other=False, diverged=False)
1030+ tm_other_diverged = self.constructOtherTranslationMessage(
1031+ current=True, other=False, diverged=True,
1032+ translations=new_translations)
1033+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1034+ tm_shared, None, None, [tm_other_diverged])
1035+
1036+ tm = self.setCurrentTranslation(new_translations)
1037+
1038+ # New translation message is shared for current context,
1039+ # and identical divergence in other context is kept.
1040+ self.assertTrue(tm is not None)
1041+ self.assertNotEquals(tm_shared, tm)
1042+ self.assertNotEquals(tm_other_diverged, tm)
1043+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1044+ tm, None, None, [tm_other_diverged])
1045+
1046+ # Previous shared translation is now a suggestion.
1047+ self.assertFalse(
1048+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
1049+
1050+ def test_c_shared__n_diverged__o_diverged_shared(self):
1051+ # Current translation is 'shared', and we have found
1052+ # a diverged (in other context) existing TM matching new translations.
1053+ # There is also a shared translation for the "other" context.
1054+ new_translations = [self.factory.getUniqueString()]
1055+ tm_shared = self.constructTranslationMessage(
1056+ current=True, other=False, diverged=False)
1057+ tm_other = self.constructOtherTranslationMessage(
1058+ current=True, other=False, diverged=False)
1059+ tm_other_diverged = self.constructOtherTranslationMessage(
1060+ current=True, other=False, diverged=True,
1061+ translations=new_translations)
1062+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1063+ tm_shared, None, tm_other, [tm_other_diverged])
1064+
1065+ tm = self.setCurrentTranslation(new_translations)
1066+
1067+ # New translation message is shared and current only for
1068+ # the active context. "Other" translation is unchanged.
1069+ self.assertTrue(tm is not None)
1070+ self.assertNotEquals(tm_shared, tm)
1071+ self.assertNotEquals(tm_other, tm)
1072+ self.assertNotEquals(tm_other_diverged, tm)
1073+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1074+ tm, None, tm_other, [tm_other_diverged])
1075+
1076+ # Previous shared translation is now a suggestion.
1077+ self.assertFalse(
1078+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
1079+
1080+ def test_c_shared__n_diverged__o_diverged__identical(self):
1081+ # Current translation is 'shared', and we have found
1082+ # a diverged existing TM matching new translations
1083+ # for the "other" context.
1084+ new_translations = [self.factory.getUniqueString()]
1085+ tm_shared = self.constructTranslationMessage(
1086+ current=True, other=False, diverged=False)
1087+ tm_other_diverged = self.constructOtherTranslationMessage(
1088+ current=True, other=False, diverged=True,
1089+ translations=new_translations)
1090+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1091+ tm_shared, None, None, [tm_other_diverged])
1092+
1093+ tm = self.setCurrentTranslation(new_translations)
1094+
1095+ # New translation message is shared and current only for
1096+ # the active context. "Other" translation is unchanged.
1097+ self.assertTrue(tm is not None)
1098+ self.assertNotEquals(tm_shared, tm)
1099+ self.assertNotEquals(tm_other_diverged, tm)
1100+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1101+ tm, None, None, [tm_other_diverged])
1102+
1103+ # Previous shared translation is now a suggestion.
1104+ self.assertFalse(
1105+ tm_shared.is_current_ubuntu or tm_shared.is_current_upstream)
1106+
1107+ def test_c_diverged__n_None__o_None(self, follows=False):
1108+ # Current translation is 'diverged' (no shared), and we have found
1109+ # no existing TM matching new translations.
1110+ # There is neither a translation for "other" context.
1111+ new_translations = [self.factory.getUniqueString()]
1112+ tm_diverged = self.constructTranslationMessage(
1113+ current=True, other=False, diverged=True)
1114+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1115+ None, tm_diverged, None, [])
1116+
1117+ tm = self.setCurrentTranslation(
1118+ new_translations, share_with_other_side=follows)
1119+
1120+ # New translation message stays diverged and current only for
1121+ # the active context.
1122+ # XXX DaniloSegan 20100530: it'd be nice to have this
1123+ # converge the diverged translation (since shared is None),
1124+ # though it's not a requirement: (tm, None, None, [])
1125+ self.assertTrue(tm is not None)
1126+ self.assertNotEquals(tm_diverged, tm)
1127+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1128+ None, tm, None, [])
1129+
1130+ # Previously current is not current anymore.
1131+ self.assertFalse(
1132+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1133+
1134+ def test_c_diverged__n_None__o_None__follows(self):
1135+ # The choice of sharing policy has no effect when starting from
1136+ # a diverged translation.
1137+ self.test_c_diverged__n_None__o_None(follows=True)
1138+
1139+ def test_c_diverged__n_None__o_shared(self, follows=False):
1140+ # Current translation is 'diverged' (with shared), and we have found
1141+ # no existing TM matching new translations.
1142+ # There is neither a translation for "other" context.
1143+ new_translations = [self.factory.getUniqueString()]
1144+ tm_diverged = self.constructTranslationMessage(
1145+ current=True, other=False, diverged=True)
1146+ tm_other = self.constructOtherTranslationMessage(
1147+ current=True, other=False, diverged=False)
1148+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1149+ None, tm_diverged, tm_other, [])
1150+
1151+ tm = self.setCurrentTranslation(
1152+ new_translations, share_with_other_side=follows)
1153+
1154+ # New translation message stays diverged and current only for
1155+ # the active context.
1156+ self.assertTrue(tm is not None)
1157+ self.assertNotEquals(tm_diverged, tm)
1158+ self.assertNotEquals(tm_other, tm)
1159+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1160+ None, tm, tm_other, [])
1161+
1162+ # Previously current is not current anymore.
1163+ self.assertFalse(
1164+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1165+
1166+ def test_c_diverged__n_None__o_shared__follows(self):
1167+ # The choice of sharing policy has no effect when starting from
1168+ # a diverged translation.
1169+ self.test_c_diverged__n_None__o_shared(True)
1170+
1171+ def test_c_diverged__n_shared__o_None(self, follows=False):
1172+ # Current translation is 'diverged' (no shared), and we have found
1173+ # an existing shared TM matching new translations (a suggestion).
1174+ # There is no translation for "other" context.
1175+ new_translations = [self.factory.getUniqueString()]
1176+ tm_diverged = self.constructTranslationMessage(
1177+ current=True, other=False, diverged=True)
1178+ tm_suggestion = self.constructTranslationMessage(
1179+ current=False, other=False, diverged=False,
1180+ translations=new_translations)
1181+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1182+ None, tm_diverged, None, [])
1183+
1184+ tm = self.setCurrentTranslation(
1185+ new_translations, share_with_other_side=follows)
1186+
1187+ # New translation message stays diverged and current only for
1188+ # the active context.
1189+ # XXX DaniloSegan 20100530: it'd be nice to have this
1190+ # converge the diverged translation (since shared is None),
1191+ # though it's not a requirement: (tm, None, None, [])
1192+ self.assertTrue(tm is not None)
1193+ self.assertNotEquals(tm_diverged, tm)
1194+ self.assertEquals(tm_suggestion, tm)
1195+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1196+ None, tm, None, [])
1197+
1198+ # Previously current is not current anymore.
1199+ self.assertFalse(
1200+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1201+
1202+ def test_c_diverged__n_shared__o_None__follows(self):
1203+ # The choice of sharing policy has no effect when starting from
1204+ # a diverged translation.
1205+ self.test_c_diverged__n_shared__o_None(follows=True)
1206+
1207+ def test_c_diverged__n_shared__o_None__identical(self):
1208+ # Current translation is 'diverged', and we have found an existing
1209+ # current shared TM matching new translations (converging).
1210+ # There is no translation for "other" context.
1211+ new_translations = [self.factory.getUniqueString()]
1212+ tm_diverged = self.constructTranslationMessage(
1213+ current=True, other=False, diverged=True)
1214+ tm_shared = self.constructTranslationMessage(
1215+ current=True, other=False, diverged=False,
1216+ translations=new_translations)
1217+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1218+ tm_shared, tm_diverged, None, [])
1219+
1220+ tm = self.setCurrentTranslation(new_translations)
1221+
1222+ # New translation message converges for the active context.
1223+ self.assertTrue(tm is not None)
1224+ self.assertNotEquals(tm_diverged, tm)
1225+ self.assertEquals(tm_shared, tm)
1226+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1227+ tm, None, None, [])
1228+
1229+ # Previously current is not current anymore.
1230+ self.assertFalse(
1231+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1232+
1233+ def test_c_diverged__n_shared__o_None_identical_follows(self):
1234+ # Current translation is 'diverged', and we have found an existing
1235+ # current shared TM matching new translations (converging).
1236+ # There is no translation for "other" context.
1237+ new_translations = [self.factory.getUniqueString()]
1238+ tm_diverged = self.constructTranslationMessage(
1239+ current=True, other=False, diverged=True)
1240+ tm_shared = self.constructTranslationMessage(
1241+ current=True, other=False, diverged=False,
1242+ translations=new_translations)
1243+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1244+ tm_shared, tm_diverged, None, [])
1245+
1246+ tm = self.setCurrentTranslation(
1247+ new_translations, share_with_other_side=True)
1248+
1249+ # New translation message converges for the active context.
1250+ # The other side is not set because we're working on a diverged
1251+ # message.
1252+ self.assertTrue(tm is not None)
1253+ self.assertNotEquals(tm_diverged, tm)
1254+ self.assertEquals(tm_shared, tm)
1255+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1256+ tm, None, None, [])
1257+
1258+ # Previously current is not current anymore.
1259+ self.assertFalse(
1260+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1261+
1262+ def test_c_diverged__n_shared__o_shared(self, follows=False):
1263+ # Current translation is 'diverged' (no shared), and we have found
1264+ # an existing shared TM matching new translations (a suggestion).
1265+ # There is a shared translation for "other" context.
1266+ new_translations = [self.factory.getUniqueString()]
1267+ tm_diverged = self.constructTranslationMessage(
1268+ current=True, other=False, diverged=True)
1269+ tm_suggestion = self.constructTranslationMessage(
1270+ current=False, other=False, diverged=False,
1271+ translations=new_translations)
1272+ tm_other = self.constructOtherTranslationMessage(
1273+ current=True, other=False, diverged=False)
1274+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1275+ None, tm_diverged, tm_other, [])
1276+
1277+ tm = self.setCurrentTranslation(
1278+ new_translations, share_with_other_side=follows)
1279+
1280+ # New translation message stays diverged and current only for
1281+ # the active context.
1282+ # XXX DaniloSegan 20100530: it'd be nice to have this
1283+ # converge the diverged translation (since shared is None),
1284+ # though it's not a requirement: (tm, None, None, [])
1285+ self.assertTrue(tm is not None)
1286+ self.assertNotEquals(tm_diverged, tm)
1287+ self.assertEquals(tm_suggestion, tm)
1288+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1289+ None, tm, tm_other, [])
1290+
1291+ # Previously current is not current anymore.
1292+ self.assertFalse(
1293+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1294+
1295+ def test_c_diverged__n_shared__o_shared__follows(self):
1296+ # The choice of sharing policy has no effect when starting from
1297+ # a diverged translation.
1298+ self.test_c_diverged__n_shared__o_shared(follows=True)
1299+
1300+ def test_c_diverged__n_shared__o_shared__identical_other(self,
1301+ follows=False):
1302+ # Current translation is 'diverged' (no shared), and we have found
1303+ # a shared TM matching new translations, that is also
1304+ # current in "other" context. (Converging to 'other')
1305+ new_translations = [self.factory.getUniqueString()]
1306+ tm_diverged = self.constructTranslationMessage(
1307+ current=True, other=False, diverged=True)
1308+ tm_other = self.constructOtherTranslationMessage(
1309+ current=True, other=False, diverged=False,
1310+ translations=new_translations)
1311+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1312+ None, tm_diverged, tm_other, [])
1313+
1314+ tm = self.setCurrentTranslation(
1315+ new_translations, share_with_other_side=follows)
1316+
1317+ # New translation message is diverged and current only for
1318+ # the active context.
1319+ # XXX DaniloSegan 20100530: it'd be nice to have this
1320+ # converge the diverged translation (since shared is None),
1321+ # though it's not a requirement: tm_other==tm and (tm, None, tm, [])
1322+ self.assertTrue(tm is not None)
1323+ self.assertNotEquals(tm_diverged, tm)
1324+ self.assertNotEquals(tm_other, tm)
1325+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1326+ None, tm, tm_other, [])
1327+
1328+ # Previously current is not current anymore.
1329+ self.assertFalse(
1330+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1331+
1332+ def test_c_diverged__n_shared__o_shared__identical_o__follows(self):
1333+ # The choice of sharing policy has no effect when starting from
1334+ # a diverged translation.
1335+ self.test_c_diverged__n_shared__o_shared__identical_other(
1336+ follows=True)
1337+
1338+ def test_c_diverged__n_shared__o_shared__identical_shared(self,
1339+ follows=False):
1340+ # Current translation is 'diverged' (no shared), and we have found
1341+ # a shared TM matching new translations, that is also
1342+ # currently shared in "this" context. (Converging to 'shared')
1343+ # There is a shared translation in "other" context.
1344+ new_translations = [self.factory.getUniqueString()]
1345+ tm_shared = self.constructTranslationMessage(
1346+ current=True, other=False, diverged=False,
1347+ translations=new_translations)
1348+ tm_diverged = self.constructTranslationMessage(
1349+ current=True, other=False, diverged=True)
1350+ tm_other = self.constructOtherTranslationMessage(
1351+ current=True, other=False, diverged=False)
1352+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1353+ tm_shared, tm_diverged, tm_other, [])
1354+
1355+ tm = self.setCurrentTranslation(
1356+ new_translations, share_with_other_side=follows)
1357+
1358+ # New translation message is shared for current context.
1359+ self.assertTrue(tm is not None)
1360+ self.assertNotEquals(tm_diverged, tm)
1361+ self.assertNotEquals(tm_other, tm)
1362+ self.assertEquals(tm_shared, tm)
1363+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1364+ tm, None, tm_other, [])
1365+
1366+ # Previously current is not current anymore.
1367+ self.assertFalse(
1368+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1369+
1370+ def test_c_diverged__n_shared__o_shared__identical_shared__follows(self):
1371+ # The choice of sharing policy has no effect when starting from
1372+ # a diverged translation.
1373+ self.test_c_diverged__n_shared__o_shared__identical_shared(
1374+ follows=True)
1375+
1376+ def test_c_diverged__n_diverged__o_None(self, follows=False):
1377+ # Current translation is 'diverged' (no shared), and we have found
1378+ # an existing diverged elsewhere TM matching new translations.
1379+ # There is no translation for "other" context.
1380+ new_translations = [self.factory.getUniqueString()]
1381+ tm_diverged = self.constructTranslationMessage(
1382+ current=True, other=False, diverged=True)
1383+ tm_diverged_elsewhere = self.constructDivergingTranslationMessage(
1384+ current=True, other=False, diverged=True,
1385+ translations=new_translations)
1386+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1387+ None, tm_diverged, None, [tm_diverged_elsewhere])
1388+
1389+ tm = self.setCurrentTranslation(
1390+ new_translations, share_with_other_side=follows)
1391+
1392+ # New translation message stays diverged and current only for
1393+ # the active context. Existing divergence elsewhere is untouched.
1394+ # XXX DaniloSegan 20100530: it'd be nice to have this
1395+ # converge the diverged translation (since shared is None),
1396+ # though it's not a requirement: (tm, None, None, [])
1397+ self.assertTrue(tm is not None)
1398+ self.assertNotEquals(tm_diverged, tm)
1399+ self.assertNotEquals(tm_diverged_elsewhere, tm)
1400+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1401+ None, tm, None, [tm_diverged_elsewhere])
1402+
1403+ # Previously current is not current anymore.
1404+ self.assertFalse(
1405+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1406+
1407+ def test_c_diverged__n_diverged__o_None__follows(self):
1408+ # The choice of sharing policy has no effect when starting from
1409+ # a diverged translation.
1410+ self.test_c_diverged__n_diverged__o_None(follows=True)
1411+
1412+ def test_c_diverged__n_diverged__o_shared(self, follows=False):
1413+ # Current translation is 'diverged' (no shared), and we have found
1414+ # an existing diverged elsewhere TM matching new translations.
1415+ # There is a shared translation for "other" context.
1416+ new_translations = [self.factory.getUniqueString()]
1417+ tm_diverged = self.constructTranslationMessage(
1418+ current=True, other=False, diverged=True)
1419+ tm_diverged_elsewhere = self.constructDivergingTranslationMessage(
1420+ current=True, other=False, diverged=True,
1421+ translations=new_translations)
1422+ tm_other = self.constructOtherTranslationMessage(
1423+ current=True, other=False, diverged=False)
1424+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1425+ None, tm_diverged, tm_other, [tm_diverged_elsewhere])
1426+
1427+ tm = self.setCurrentTranslation(
1428+ new_translations, share_with_other_side=follows)
1429+
1430+ # New translation message stays diverged and current only for
1431+ # the active context. Existing divergence elsewhere is untouched.
1432+ # XXX DaniloSegan 20100530: it'd be nice to have this
1433+ # converge the diverged translation (since shared is None),
1434+ # though it's not a requirement: (tm, None, tm_other, [])
1435+ self.assertTrue(tm is not None)
1436+ self.assertNotEquals(tm_diverged, tm)
1437+ self.assertNotEquals(tm_diverged_elsewhere, tm)
1438+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1439+ None, tm, tm_other, [tm_diverged_elsewhere])
1440+
1441+ # Previously current is not current anymore.
1442+ self.assertFalse(
1443+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1444+
1445+ def test_c_diverged__n_diverged__o_shared__follows(self):
1446+ # The choice of sharing policy has no effect when starting from
1447+ # a diverged translation.
1448+ self.test_c_diverged__n_diverged__o_shared(follows=True)
1449+
1450+ def test_c_diverged__n_diverged__o_diverged(self, follows=False):
1451+ # Current translation is 'diverged' (no shared), and we have found
1452+ # an existing diverged in other context TM matching new translations.
1453+ new_translations = [self.factory.getUniqueString()]
1454+ tm_diverged = self.constructTranslationMessage(
1455+ current=True, other=False, diverged=True)
1456+ tm_other_diverged = self.constructOtherTranslationMessage(
1457+ current=True, other=False, diverged=True,
1458+ translations=new_translations)
1459+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1460+ None, tm_diverged, None, [tm_other_diverged])
1461+
1462+ tm = self.setCurrentTranslation(
1463+ new_translations, share_with_other_side=follows)
1464+
1465+ # New translation message stays diverged and current only for
1466+ # the active context. Existing divergence elsewhere is untouched.
1467+ # XXX DaniloSegan 20100530: it'd be nice to have this
1468+ # converge the diverged translation (since shared is None),
1469+ # though it's not a requirement: (tm, None, tm_other, [])
1470+ self.assertTrue(tm is not None)
1471+ self.assertNotEquals(tm_diverged, tm)
1472+ self.assertNotEquals(tm_other_diverged, tm)
1473+ self.assert_Current_Diverged_Other_DivergencesElsewhere_are(
1474+ None, tm, None, [tm_other_diverged])
1475+
1476+ # Previously current is not current anymore.
1477+ self.assertFalse(
1478+ tm_diverged.is_current_ubuntu or tm_diverged.is_current_upstream)
1479+
1480+ def test_c_diverged__n_diverged__o_diverged__follows(self):
1481+ # The choice of sharing policy has no effect when starting from
1482+ # a diverged translation.
1483+ self.test_c_diverged__n_diverged__o_diverged(follows=True)
1484+
1485+
1486+class TestSetCurrentTranslation_Ubuntu(SetCurrentTranslationTestMixin,
1487+ TestCaseWithFactory):
1488+ layer = ZopelessDatabaseLayer
1489+
1490+ def setUp(self):
1491+ super(TestSetCurrentTranslation_Ubuntu, self).setUp()
1492+ ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
1493+ sharing_series = self.factory.makeDistroRelease(distribution=ubuntu)
1494+ sourcepackagename = self.factory.makeSourcePackageName()
1495+ potemplate = self.factory.makePOTemplate(
1496+ distroseries=ubuntu.currentseries,
1497+ sourcepackagename=sourcepackagename)
1498+ sharing_potemplate = self.factory.makePOTemplate(
1499+ distroseries=sharing_series,
1500+ sourcepackagename=sourcepackagename,
1501+ name=potemplate.name)
1502+ self.pofile = self.factory.makePOFile(
1503+ 'sr', potemplate=potemplate, create_sharing=True)
1504+
1505+ # A POFile in the same context as self.pofile, used for diverged
1506+ # translations.
1507+ self.diverging_pofile = sharing_potemplate.getPOFileByLang(
1508+ self.pofile.language.code, self.pofile.variant)
1509+
1510+ # A POFile in a different context from self.pofile and
1511+ # self.diverging_pofile.
1512+ self.other_pofile = self.factory.makePOFile(
1513+ language_code=self.pofile.language.code,
1514+ variant=self.pofile.variant)
1515+
1516+ self.potmsgset = self.factory.makePOTMsgSet(
1517+ potemplate=potemplate, sequence=1)
1518+
1519+
1520+# XXX JeroenVermeulen 2010-06-29 bug=546310: we can activate this once
1521+# getCurrentTranslation and getImportedTranslation "change sides" based
1522+# on the current template: lp:~danilo/launchpad/use-upstream-translations.
1523+
1524+#class TestSetCurrentTranslation_Upstream(SetCurrentTranslationTestMixin,
1525+# TestCaseWithFactory):
1526+#
1527+# layer = ZopelessDatabaseLayer
1528+#
1529+# def setUp(self):
1530+# super(TestSetCurrentTranslation_Upstream, self).setUp()
1531+# series = self.factory.makeProductSeries()
1532+# sharing_series = self.factory.makeProductSeries(
1533+# product=series.product)
1534+# potemplate = self.factory.makePOTemplate(productseries=series)
1535+# sharing_potemplate = self.factory.makePOTemplate(
1536+# productseries=sharing_series, name=potemplate.name)
1537+# self.pofile = self.factory.makePOFile('sr', potemplate=potemplate,
1538+# create_sharing=True)
1539+#
1540+# # A POFile in the same context as self.pofile, used for diverged
1541+# # translations.
1542+# self.diverging_pofile = sharing_potemplate.getPOFileByLang(
1543+# self.pofile.language.code, self.pofile.variant)
1544+#
1545+# # A POFile in a different context from self.pofile and
1546+# # self.diverging_pofile.
1547+# ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
1548+# sourcepackagename = self.factory.makeSourcePackageName()
1549+# ubuntu_template = self.factory.makePOTemplate(
1550+# distroseries=ubuntu.currentseries,
1551+# sourcepackagename=sourcepackagename)
1552+# self.other_pofile = self.factory.makePOFile(
1553+# potemplate=ubuntu_template,
1554+# language_code=self.pofile.language.code,
1555+# variant=self.pofile.variant)
1556+#
1557+# self.potmsgset = self.factory.makePOTMsgSet(potemplate=potemplate,
1558+# sequence=1)

Subscribers

People subscribed via source and target branches