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

Subscribers

People subscribed via source and target branches