Merge lp:~henninge/launchpad/bug-595925-second-attempt into lp:~launchpad/launchpad/recife

Proposed by Henning Eggers
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 9156
Proposed branch: lp:~henninge/launchpad/bug-595925-second-attempt
Merge into: lp:~launchpad/launchpad/recife
Diff against target: 1856 lines (+498/-406)
12 files modified
lib/lp/testing/factory.py (+37/-2)
lib/lp/translations/browser/tests/test_pofile_view.py (+2/-8)
lib/lp/translations/browser/tests/test_translationmessage_view.py (+14/-7)
lib/lp/translations/browser/translationmessage.py (+3/-7)
lib/lp/translations/tests/test_pofile.py (+342/-299)
lib/lp/translations/tests/test_potmsgset.py (+49/-54)
lib/lp/translations/tests/test_translatablemessage.py (+16/-12)
lib/lp/translations/tests/test_translations_to_review.py (+4/-2)
lib/lp/translations/utilities/sanitize.py (+4/-3)
lib/lp/translations/utilities/tests/test_sanitize.py (+19/-6)
lib/lp/translations/utilities/tests/test_superfastimports.py (+2/-2)
lib/lp/translations/windmill/tests/test_pofile_translate.py (+6/-4)
To merge this branch: bzr merge lp:~henninge/launchpad/bug-595925-second-attempt
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) code Approve
Review via email: mp+32736@code.launchpad.net

Description of the change

= Bug 595925 =

This branch only replaces calls in test code. The two production call sites will be updated in later branches. The first call site is in the view code and depends on bug 597539 being fixed or else many page tests do fail (I tried). The second is in the import code and requires some untangling or restructuring of code.

== Implementation details ==

This branch creates a new factory method "makeSuggestion" that makes use of the new "submitSuggestion" method. This factory method is then used in all test locations where "makeTranslationMessage(suggestion=True)" was used before.

In test_pofile.py I created TestTranslationSharedPOFileSourcePackage to move some tests there that were failing in TestTranslationSharedPOFile because it uses a product series.

I also fixed some tests in test_potmsgset.py that were using "set" to compare lists instead of assertContentEqual. Probably my doing.

I made sanitize_translations_from_webui work with lists for the translations because that is nice and robust.

I had to add an XXX to a windmill test because it depends on bug 597539, too.

== Tests ==

Run all the changed tests.

bin/test -vvcm lp.translations.browser.tests \
    -t test_pofile_view \
    -t test_translationmessage_view \
    -t translationmessage
bin/test -vvcm lp.translations.tests \
    -t test_pofile \
    -t test_potmsgset \
    -t test_translatablemessage \
    -t test_translations_to_review
bin/test -vvcm lp.translations.utilities.tests \
    -t test_sanitize \
    -t test_superfastimports
bin/test -vvcm lp.translations.windmill.tests \
    -t test_pofile_translate

But I already ran the full test suite on the branch successfully. ;-)

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/testing/factory.py
  lib/lp/translations/browser/translationmessage.py
  lib/lp/translations/browser/tests/test_pofile_view.py
  lib/lp/translations/browser/tests/test_translationmessage_view.py
  lib/lp/translations/tests/test_pofile.py
  lib/lp/translations/tests/test_potmsgset.py
  lib/lp/translations/tests/test_translatablemessage.py
  lib/lp/translations/tests/test_translations_to_review.py
  lib/lp/translations/utilities/sanitize.py
  lib/lp/translations/utilities/tests/test_sanitize.py
  lib/lp/translations/utilities/tests/test_superfastimports.py
  lib/lp/translations/windmill/tests/test_pofile_translate.py

./lib/lp/testing/factory.py
    2873: E301 expected 1 blank line, found 2
./lib/lp/translations/browser/translationmessage.py
     293: W602 deprecated form of raising exception
     300: W602 deprecated form of raising exception
     313: W602 deprecated form of raising exception
     339: E301 expected 1 blank line, found 2
     367: E301 expected 1 blank line, found 2
     511: E301 expected 1 blank line, found 2
     744: E301 expected 1 blank line, found 2
     827: E301 expected 1 blank line, found 2
     894: E301 expected 1 blank line, found 2
    1337: E301 expected 1 blank line, found 2
    1475: E302 expected 2 blank lines, found 3
    1509: E302 expected 2 blank lines, found 3
    1556: E302 expected 2 blank lines, found 1
./lib/lp/translations/tests/test_potmsgset.py
    1592: E202 whitespace before ']'

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :
Download full text (5.9 KiB)

Wow, big branch. I know it wasn't easy. Lots of goodness here, including lint cleanups all over the place. But you also inherited some uglier things, and it seems to me that your "make lint" run was incomplete somehow. I hope we can make some more headway with that, but in the interest of getting the branch in it's not as important as cleaning up the new bits.

We discussed some of these on IRC, but most we didn't.

=== lib/lp/testing/factory.py ===

Might as well make the "translations" parameter to _makeTranslationsDict default to None.

The docstring for _makeTranslationsDict goes "Make sure translations are in the right format." That's a bit ambiguous as to what happens when the translations are not in the right format. Consider saying something like "Convert translations" (and adding a note saying that it returns the original translations if they are already in the desired format).

In the same docstring, don't lead with "the right format"--name the format! An example like '{0: "foo"}' may say it most effectively.

Naming all types of sequence that might make up a non-dict translations list is probably a losing game: is it really necessary to accept tuples? What about ResultSets? If it's really needed, consider rearranging the conditions: "if translations is None / elif isinstance(translations, dict) / else" (where the "else" part returns dict(enumerate(translations))).

In makeSuggestion: it's no longer necessary to setSequence on a POTMsgSet you get from makePOTMsgSet. Just pass a sequence number to makePOTMsgSet.

In makeSuggestion, this line lacks spaces around the assignment operator:

        translations=self._makeTranslationsDict(translations)

And why does it set naked_translation_message.date_created to date_updated? I'd expect date_updated to set date_updated, not date_created.

== lib/lp/translations/browser/tests/test_pofile_view.py ==

Thanks for cleaning up the lint! While you're at it, could you chuck the entire test_suite function? We no longer need those, so they're just cruft now.

== lib/lp/translations/browser/translationmessage.py ==

More lint cleanups. Good show.

== lib/lp/translations/tests/test_pofile.py ==

There's a lot of code here that you clearly only moved, so you're probably more a victim than a perpetrator. But still I hope you can fix some of this, if it doesn't mean too much extra work.

In setUp, this comment:

# POTemplate is 'shared' if it has the same name ('messages').

...is rather confusing. I'd rather say that two POTemplates share if they have the same name. And separately, that these particular two templates both have "messages" for a name.

In the names devel_sr_pofile and stable_sr_pofile, unless the "sr" part is actually relevant to the tests, I'd leave it out of the names.

This comment:

# Create a single POTMsgSet that is used across all tests,
# and add it to only one of the POTemplates.

...commits the standard mistake of repeating what the code does. That's useless. The only interesting part is that the potmsgset is only added to one of the templates... *Why* is that?

And right below that, once again: no need to self.potmsgset.setSequence. Just pass the seq...

Read more...

Revision history for this message
Henning Eggers (henninge) wrote :
Download full text (8.4 KiB)

Am 16.08.2010 16:37, schrieb Jeroen T. Vermeulen:
> Wow, big branch. I know it wasn't easy. Lots of goodness here, including lint cleanups all over the place. But you also inherited some uglier things, and it seems to me that your "make lint" run was incomplete somehow. I hope we can make some more headway with that, but in the interest of getting the branch in it's not as important as cleaning up the new bits.
>
> We discussed some of these on IRC, but most we didn't.
>
>
> === lib/lp/testing/factory.py ===
>
> Might as well make the "translations" parameter to _makeTranslationsDict default to None.
>
> The docstring for _makeTranslationsDict goes "Make sure translations are in the right format." That's a bit ambiguous as to what happens when the translations are not in the right format. Consider saying something like "Convert translations" (and adding a note saying that it returns the original translations if they are already in the desired format).
>
> In the same docstring, don't lead with "the right format"--name the format! An example like '{0: "foo"}' may say it most effectively.
>
> Naming all types of sequence that might make up a non-dict translations list is probably a losing game: is it really necessary to accept tuples? What about ResultSets? If it's really needed, consider rearranging the conditions: "if translations is None / elif isinstance(translations, dict) / else" (where the "else" part returns dict(enumerate(translations))).

I fixed all this as per our IRC discussion.

>
> In makeSuggestion: it's no longer necessary to setSequence on a POTMsgSet you get from makePOTMsgSet. Just pass a sequence number to makePOTMsgSet.

Ah yes, I copied and pasted makeSuggestion from makeTranslationMessage. I
added fixed it there, too. Funny enough, it was me who introduced the
parameter to the factory method in the first place. ;)

>
> In makeSuggestion, this line lacks spaces around the assignment operator:
>
> translations=self._makeTranslationsDict(translations)

Yes, I had it directly in the function call at first. Thanks.

>
> And why does it set naked_translation_message.date_created to date_updated? I'd expect date_updated to set date_updated, not date_created.
>

Again, copied from makeTranslationMessage where it is a bit more approriate
although it sets "date_created" and "date_reviewed" there. I renamed the
parameter in makeSuggestion to date_created and update all call sites.

>
> == lib/lp/translations/browser/tests/test_pofile_view.py ==
>
> Thanks for cleaning up the lint! While you're at it, could you chuck the entire test_suite function? We no longer need those, so they're just cruft now.

Ah yes, right. I am always happy to remove cruft! ;-)

>
>
> == lib/lp/translations/browser/translationmessage.py ==
>
> More lint cleanups. Good show.

Thank you for the applause! ;)

>
>
> == lib/lp/translations/tests/test_pofile.py ==
>
> There's a lot of code here that you clearly only moved, so you're probably more a victim than a perpetrator. But still I hope you can fix some of this, if it doesn't mean too much extra work.

Well, let's see .. ;-)

>
> In setUp, this comment:
>
> # POT...

Read more...

1=== modified file 'lib/lp/testing/factory.py'
2--- lib/lp/testing/factory.py 2010-08-16 09:10:59 +0000
3+++ lib/lp/testing/factory.py 2010-08-16 15:07:24 +0000
4@@ -2057,8 +2057,7 @@
5 if pofile is None:
6 pofile = self.makePOFile('sr')
7 if potmsgset is None:
8- potmsgset = self.makePOTMsgSet(pofile.potemplate)
9- potmsgset.setSequence(pofile.potemplate, 1)
10+ potmsgset = self.makePOTMsgSet(pofile.potemplate, sequence=1)
11 if translator is None:
12 translator = self.makePerson()
13 if translations is None:
14@@ -2077,37 +2076,39 @@
15 naked_translation_message.sync()
16 return translation_message
17
18- def _makeTranslationsDict(self, translations):
19- """Make sure translations are in the right format (dict, not list).
20+ def _makeTranslationsDict(self, translations=None):
21+ """Make sure translations are stored in a dict, e.g. {0: "foo"}.
22
23- Create an arbitrary single translation if translations are None.
24+ If translations is already dict, it is returned unchanged.
25+ If translations is a sequence, it is enumerated into a dict.
26+ If translations is None, an arbitrary single translation is created.
27 """
28 if translations is None:
29 return {0: self.getUniqueString()}
30- if isinstance(translations, (tuple, list)):
31- return dict(enumerate(translations))
32- assert isinstance(translations, dict)
33- return translations
34+ if isinstance(translations, dict):
35+ return translations
36+ assert isinstance(translations, (list, tuple)), (
37+ "Expecting either a dict or a sequence." )
38+ return dict(enumerate(translations))
39
40 def makeSuggestion(self, pofile=None, potmsgset=None, translator=None,
41- translations=None, date_updated=None):
42+ translations=None, date_created=None):
43 """Make a new suggested `TranslationMessage` in the given PO file."""
44 if pofile is None:
45 pofile = self.makePOFile('sr')
46 if potmsgset is None:
47- potmsgset = self.makePOTMsgSet(pofile.potemplate)
48- potmsgset.setSequence(pofile.potemplate, 1)
49+ potmsgset = self.makePOTMsgSet(pofile.potemplate, sequence=1)
50 if translator is None:
51 translator = self.makePerson()
52- translations=self._makeTranslationsDict(translations)
53+ translations = self._makeTranslationsDict(translations)
54 translation_message = potmsgset.submitSuggestion(
55 pofile, translator, translations)
56 assert translation_message is not None, (
57 "Cannot make suggestion on translation credits POTMsgSet.")
58- if date_updated is not None:
59+ if date_created is not None:
60 naked_translation_message = removeSecurityProxy(
61 translation_message)
62- naked_translation_message.date_created = date_updated
63+ naked_translation_message.date_created = date_created
64 naked_translation_message.sync()
65 return translation_message
66
67
68=== modified file 'lib/lp/translations/browser/tests/test_pofile_view.py'
69--- lib/lp/translations/browser/tests/test_pofile_view.py 2010-08-16 09:01:35 +0000
70+++ lib/lp/translations/browser/tests/test_pofile_view.py 2010-08-16 15:18:40 +0000
71@@ -46,7 +46,7 @@
72 self.pofile, self.new_suggestion,
73 date_updated=self.now())
74 self.factory.makeSuggestion(
75- self.pofile, self.new_suggestion, date_updated=self.now())
76+ self.pofile, self.new_suggestion, date_created=self.now())
77 # An upstream that was changed in Ubuntu.
78 self.changed = self.factory.makePOTMsgSet(
79 self.potemplate, sequence=4)
80@@ -170,7 +170,3 @@
81 def setUp(self):
82 super(TestPOFileTranslateViewInvalidFiltering, self).setUp()
83 self.pofile = self.factory.makePOFile('eo')
84-
85-
86-def test_suite():
87- return TestLoader().loadTestsFromName(__name__)
88
89=== modified file 'lib/lp/translations/browser/tests/test_translationmessage_view.py'
90--- lib/lp/translations/browser/tests/test_translationmessage_view.py 2010-08-11 10:37:59 +0000
91+++ lib/lp/translations/browser/tests/test_translationmessage_view.py 2010-08-16 15:11:30 +0000
92@@ -56,7 +56,7 @@
93 self.pofile, self.potmsgset,
94 translations=translations,
95 translator=self.owner,
96- date_updated=self.now())
97+ date_created=self.now())
98 else:
99 message = self.factory.makeTranslationMessage(
100 self.pofile, self.potmsgset,
101
102=== modified file 'lib/lp/translations/tests/test_pofile.py'
103--- lib/lp/translations/tests/test_pofile.py 2010-08-13 14:24:30 +0000
104+++ lib/lp/translations/tests/test_pofile.py 2010-08-16 15:56:36 +0000
105@@ -1,8 +1,6 @@
106 # Copyright 2009-2010 Canonical Ltd. This software is licensed under the
107 # GNU Affero General Public License version 3 (see the file LICENSE).
108
109-# pylint: disable-msg=C0102
110-
111 __metaclass__ = type
112
113 from datetime import datetime, timedelta
114@@ -43,7 +41,8 @@
115 self.foo.official_rosetta = True
116 self.sourcepackagename = self.factory.makeSourcePackageName()
117
118- # POTemplate is 'shared' if it has the same name ('messages').
119+ # Two POTemplates share translations if they have the same name,
120+ # in this case 'messages'.
121 self.devel_potemplate = self.factory.makePOTemplate(
122 distroseries=self.foo_devel,
123 sourcepackagename=self.sourcepackagename,
124@@ -54,41 +53,40 @@
125 name="messages")
126
127 # We'll use two PO files, one for each series.
128- self.devel_sr_pofile = self.factory.makePOFile(
129+ self.devel_pofile = self.factory.makePOFile(
130 'sr', self.devel_potemplate)
131- self.stable_sr_pofile = self.factory.makePOFile(
132+ self.stable_pofile = self.factory.makePOFile(
133 'sr', self.stable_potemplate)
134
135- # Create a single POTMsgSet that is used across all tests,
136- # and add it to only one of the POTemplates.
137- self.potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
138- self.potmsgset.setSequence(self.devel_potemplate, 1)
139+ # The POTMsgSet is added to only one of the POTemplates.
140+ self.potmsgset = self.factory.makePOTMsgSet(
141+ self.devel_potemplate, sequence=1)
142
143- def test_getPOTMsgSetWithNewSuggestions_Shared(self):
144+ def test_getPOTMsgSetWithNewSuggestions_shared(self):
145 # Test listing of suggestions for POTMsgSets with a shared
146 # translation.
147
148 # A POTMsgSet has a shared, current translation created 5 days ago.
149- date_created = datetime.now(pytz.UTC)-timedelta(5)
150+ date_created = datetime.now(pytz.UTC) - timedelta(5)
151 translation = self.factory.makeSuggestion(
152- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
153- translations=[u"Translation"], date_updated=date_created)
154- translation.is_current_ubuntu= True
155+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
156+ translations=[u"Translation"], date_created=date_created)
157+ translation.is_current_ubuntu = True
158
159 # When there are no suggestions, nothing is returned.
160 found_translations = list(
161- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
162+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
163 self.assertEquals(found_translations, [])
164
165 # When a suggestion is added one day after, the potmsgset is returned.
166 suggestion_date = date_created + timedelta(1)
167 suggestion = self.factory.makeSuggestion(
168- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
169- translations=[u"Suggestion"], date_updated=suggestion_date)
170+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
171+ translations=[u"Suggestion"], date_created=suggestion_date)
172 self.assertEquals(suggestion.is_current_ubuntu, False)
173
174 found_translations = list(
175- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
176+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
177 self.assertEquals(found_translations, [self.potmsgset])
178
179 # Setting a suggestion as current makes it have no unreviewed
180@@ -96,22 +94,22 @@
181 translation.is_current_ubuntu = False
182 suggestion.is_current_ubuntu = True
183 found_translations = list(
184- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
185+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
186 self.assertEquals(found_translations, [])
187
188 # And adding another suggestion 2 days later, the potmsgset is
189 # again returned.
190 suggestion_date += timedelta(2)
191 translation = self.factory.makeSuggestion(
192- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
193- translations=[u"New suggestion"], date_updated=suggestion_date)
194+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
195+ translations=[u"New suggestion"], date_created=suggestion_date)
196 self.assertEquals(translation.is_current_ubuntu, False)
197
198 found_translations = list(
199- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
200+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
201 self.assertEquals(found_translations, [self.potmsgset])
202
203- def test_getPOTMsgSetWithNewSuggestions_Diverged(self):
204+ def test_getPOTMsgSetWithNewSuggestions_diverged(self):
205 # Test listing of suggestions for POTMsgSets with a shared
206 # translation and a later diverged one.
207
208@@ -124,18 +122,18 @@
209 # * Suggestion is made active (nothing).
210
211 # A POTMsgSet has a shared, current translation created 5 days ago.
212- date_created = datetime.now(pytz.UTC)-timedelta(5)
213+ date_created = datetime.now(pytz.UTC) - timedelta(5)
214 translation = self.factory.makeSuggestion(
215- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
216- translations=[u"Shared translation"], date_updated=date_created)
217+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
218+ translations=[u"Shared translation"], date_created=date_created)
219 translation.is_current_ubuntu = True
220
221- # And we also have a diverged translation created a day after shared
222+ # And we also have a diverged translation created a day after a shared
223 # current translation.
224 diverged_date = date_created + timedelta(1)
225 diverged_translation = self.factory.makeSuggestion(
226- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
227- translations=[u"Old translation"], date_updated=diverged_date)
228+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
229+ translations=[u"Old translation"], date_created=diverged_date)
230 diverged_translation.potemplate = self.devel_potemplate
231 diverged_translation.is_current_ubuntu = True
232
233@@ -143,37 +141,37 @@
234 # created 2 days after the shared translation.
235 suggestion_date = date_created + timedelta(2)
236 suggestion = self.factory.makeSuggestion(
237- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
238- translations=[u"Shared suggestion"], date_updated=suggestion_date)
239+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
240+ translations=[u"Shared suggestion"], date_created=suggestion_date)
241 self.assertEquals(suggestion.is_current_ubuntu, False)
242
243- # Shared suggestion is shown since diverged_date < suggestion_date.
244+ # A suggestion is shown since diverged_date < suggestion_date.
245 found_translations = list(
246- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
247+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
248 self.assertEquals(found_translations, [self.potmsgset])
249
250- # When a diverged translation is done after the shared suggestion,
251+ # When a diverged translation is added after the shared suggestion,
252 # there are no unreviewed suggestions.
253 diverged_date = suggestion_date + timedelta(1)
254 diverged_translation_2 = self.factory.makeTranslationMessage(
255- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
256+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
257 translations=[u"Translation"], date_updated=diverged_date)
258 diverged_translation.is_current_ubuntu = False
259 diverged_translation_2.potemplate = self.devel_potemplate
260 diverged_translation_2.is_current_ubuntu = True
261 found_translations = list(
262- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
263+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
264 self.assertEquals(found_translations, [])
265
266 # When a suggestion is added one day after, the potmsgset is returned.
267 suggestion_date = diverged_date + timedelta(1)
268 suggestion = self.factory.makeSuggestion(
269- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
270- translations=[u"Suggestion"], date_updated=suggestion_date)
271+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
272+ translations=[u"Suggestion"], date_created=suggestion_date)
273 self.assertEquals(suggestion.is_current_ubuntu, False)
274
275 found_translations = list(
276- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
277+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
278 self.assertEquals(found_translations, [self.potmsgset])
279
280 # Setting a suggestion as current makes it have no unreviewed
281@@ -181,7 +179,7 @@
282 translation.is_current_ubuntu = False
283 suggestion.is_current_ubuntu = True
284 found_translations = list(
285- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
286+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
287 self.assertEquals(found_translations, [])
288
289
290@@ -201,22 +199,22 @@
291 name='stable', product=self.foo)
292 self.foo.official_rosetta = True
293
294- # POTemplate is 'shared' if it has the same name ('messages').
295+ # Two POTemplates share translations if they have the same name,
296+ # in this case 'messages'.
297 self.devel_potemplate = self.factory.makePOTemplate(
298 productseries=self.foo_devel, name="messages")
299 self.stable_potemplate = self.factory.makePOTemplate(self.foo_stable,
300 name="messages")
301
302 # We'll use two PO files, one for each series.
303- self.devel_sr_pofile = self.factory.makePOFile(
304+ self.devel_pofile = self.factory.makePOFile(
305 'sr', self.devel_potemplate)
306- self.stable_sr_pofile = self.factory.makePOFile(
307+ self.stable_pofile = self.factory.makePOFile(
308 'sr', self.stable_potemplate)
309
310- # Create a single POTMsgSet that is used across all tests,
311- # and add it to only one of the POTemplates.
312- self.potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
313- self.potmsgset.setSequence(self.devel_potemplate, 1)
314+ # The POTMsgSet is added to only one of the POTemplates.
315+ self.potmsgset = self.factory.makePOTMsgSet(
316+ self.devel_potemplate, sequence=1)
317
318 def test_findPOTMsgSetsContaining(self):
319 # Test that search works correctly.
320@@ -227,14 +225,14 @@
321 potmsgset.setSequence(self.devel_potemplate, 2)
322
323 found_potmsgsets = list(
324- self.devel_sr_pofile.findPOTMsgSetsContaining(u"wild"))
325+ self.devel_pofile.findPOTMsgSetsContaining(u"wild"))
326 self.assertEquals(found_potmsgsets, [potmsgset])
327
328 # Just linking an existing POTMsgSet into another POTemplate
329 # will make it be returned in searches.
330 potmsgset.setSequence(self.stable_potemplate, 2)
331 found_potmsgsets = list(
332- self.stable_sr_pofile.findPOTMsgSetsContaining(u"wild"))
333+ self.stable_pofile.findPOTMsgSetsContaining(u"wild"))
334 self.assertEquals(found_potmsgsets, [potmsgset])
335
336 # Searching for singular in plural messages works as well.
337@@ -244,49 +242,49 @@
338 plural_potmsgset.setSequence(self.devel_potemplate, 3)
339
340 found_potmsgsets = list(
341- self.devel_sr_pofile.findPOTMsgSetsContaining(u"singular"))
342+ self.devel_pofile.findPOTMsgSetsContaining(u"singular"))
343 self.assertEquals(found_potmsgsets, [plural_potmsgset])
344
345 # And searching for plural text returns only the matching plural
346 # message.
347 found_potmsgsets = list(
348- self.devel_sr_pofile.findPOTMsgSetsContaining(u"plural"))
349+ self.devel_pofile.findPOTMsgSetsContaining(u"plural"))
350 self.assertEquals(found_potmsgsets, [plural_potmsgset])
351
352 # Search translations as well.
353 self.factory.makeTranslationMessage(
354- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
355+ pofile=self.devel_pofile, potmsgset=potmsgset,
356 translations=[u"One translation message"])
357 found_potmsgsets = list(
358- self.devel_sr_pofile.findPOTMsgSetsContaining(u"translation"))
359+ self.devel_pofile.findPOTMsgSetsContaining(u"translation"))
360 self.assertEquals(found_potmsgsets, [potmsgset])
361
362 # Search matches all plural forms.
363 self.factory.makeTranslationMessage(
364- pofile=self.devel_sr_pofile, potmsgset=plural_potmsgset,
365+ pofile=self.devel_pofile, potmsgset=plural_potmsgset,
366 translations=[u"One translation message",
367 u"Plural translation message",
368 u"Third translation message"])
369 found_potmsgsets = list(
370- self.devel_sr_pofile.findPOTMsgSetsContaining(
371+ self.devel_pofile.findPOTMsgSetsContaining(
372 u"Plural translation"))
373 self.assertEquals(found_potmsgsets, [plural_potmsgset])
374
375 # Search works case insensitively for English strings.
376 found_potmsgsets = list(
377- self.devel_sr_pofile.findPOTMsgSetsContaining(u"WiLd"))
378+ self.devel_pofile.findPOTMsgSetsContaining(u"WiLd"))
379 self.assertEquals(found_potmsgsets, [potmsgset])
380 # ...English plural forms.
381 found_potmsgsets = list(
382- self.devel_sr_pofile.findPOTMsgSetsContaining(u"PLurAl"))
383+ self.devel_pofile.findPOTMsgSetsContaining(u"PLurAl"))
384 self.assertEquals(found_potmsgsets, [plural_potmsgset])
385 # ...translations.
386 found_potmsgsets = list(
387- self.devel_sr_pofile.findPOTMsgSetsContaining(u"tRANSlaTIon"))
388+ self.devel_pofile.findPOTMsgSetsContaining(u"tRANSlaTIon"))
389 self.assertEquals(found_potmsgsets, [potmsgset, plural_potmsgset])
390 # ...and translated plurals.
391 found_potmsgsets = list(
392- self.devel_sr_pofile.findPOTMsgSetsContaining(u"THIRD"))
393+ self.devel_pofile.findPOTMsgSetsContaining(u"THIRD"))
394 self.assertEquals(found_potmsgsets, [plural_potmsgset])
395
396 def test_getTranslationsFilteredBy(self):
397@@ -299,27 +297,27 @@
398
399 # When there are no translations, empty list is returned.
400 found_translations = list(
401- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
402+ self.devel_pofile.getTranslationsFilteredBy(submitter))
403 self.assertEquals(found_translations, [])
404
405 # If 'submitter' provides a translation, it's returned in a list.
406 translation = self.factory.makeTranslationMessage(
407- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
408+ pofile=self.devel_pofile, potmsgset=potmsgset,
409 translations=[u"Translation message"],
410 translator=submitter)
411 found_translations = list(
412- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
413+ self.devel_pofile.getTranslationsFilteredBy(submitter))
414 self.assertEquals(found_translations, [translation])
415
416 # If somebody else provides a translation, it's not added to the
417 # list of submitter's translations.
418 someone_else = self.factory.makePerson()
419 self.factory.makeTranslationMessage(
420- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
421+ pofile=self.devel_pofile, potmsgset=potmsgset,
422 translations=[u"Another translation"],
423 translator=someone_else)
424 found_translations = list(
425- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
426+ self.devel_pofile.getTranslationsFilteredBy(submitter))
427 self.assertEquals(found_translations, [translation])
428
429 # Adding a translation for same POTMsgSet, but to a different
430@@ -332,17 +330,17 @@
431 translations=[u"Yet another translation"],
432 translator=submitter)
433 found_translations = list(
434- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
435+ self.devel_pofile.getTranslationsFilteredBy(submitter))
436 self.assertEquals(found_translations, [translation])
437
438 # If a POTMsgSet is shared between two templates, a
439 # translation is listed on both.
440 potmsgset.setSequence(self.stable_potemplate, 1)
441 found_translations = list(
442- self.stable_sr_pofile.getTranslationsFilteredBy(submitter))
443+ self.stable_pofile.getTranslationsFilteredBy(submitter))
444 self.assertEquals(found_translations, [translation])
445 found_translations = list(
446- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
447+ self.devel_pofile.getTranslationsFilteredBy(submitter))
448 self.assertEquals(found_translations, [translation])
449
450 def test_getPOTMsgSetTranslated_NoShared(self):
451@@ -351,23 +349,23 @@
452
453 # When there is no diverged translation either, nothing is returned.
454 found_translations = list(
455- self.devel_sr_pofile.getPOTMsgSetTranslated())
456+ self.devel_pofile.getPOTMsgSetTranslated())
457 self.assertEquals(found_translations, [])
458
459 # When a diverged translation is added, the potmsgset is returned.
460 self.factory.makeTranslationMessage(
461- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
462+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
463 translations=[u"Translation"])
464 found_translations = list(
465- self.devel_sr_pofile.getPOTMsgSetTranslated())
466+ self.devel_pofile.getPOTMsgSetTranslated())
467 self.assertEquals(found_translations, [self.potmsgset])
468
469 # If diverged translation is empty, POTMsgSet is not listed.
470 self.factory.makeTranslationMessage(
471- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
472+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
473 translations=[u""])
474 found_translations = list(
475- self.devel_sr_pofile.getPOTMsgSetTranslated())
476+ self.devel_pofile.getPOTMsgSetTranslated())
477 self.assertEquals(found_translations, [])
478
479 def test_getPOTMsgSetTranslated_Shared(self):
480@@ -376,28 +374,28 @@
481
482 # We create a shared translation first.
483 self.factory.makeSharedTranslationMessage(
484- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
485+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
486 translations=[u"Shared translation"])
487
488 # When there is no diverged translation, shared one is returned.
489 found_translations = list(
490- self.devel_sr_pofile.getPOTMsgSetTranslated())
491+ self.devel_pofile.getPOTMsgSetTranslated())
492 self.assertEquals(found_translations, [self.potmsgset])
493
494 # When an empty diverged translation is added, nothing is listed.
495 self.factory.makeTranslationMessage(
496- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
497+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
498 translations=[u""])
499 found_translations = list(
500- self.devel_sr_pofile.getPOTMsgSetTranslated())
501+ self.devel_pofile.getPOTMsgSetTranslated())
502 self.assertEquals(found_translations, [])
503
504 # If diverged translation is non-empty, POTMsgSet is listed.
505 self.factory.makeTranslationMessage(
506- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
507+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
508 translations=[u"Translation"])
509 found_translations = list(
510- self.devel_sr_pofile.getPOTMsgSetTranslated())
511+ self.devel_pofile.getPOTMsgSetTranslated())
512 self.assertEquals(found_translations, [self.potmsgset])
513
514 def test_getPOTMsgSetTranslated_EmptyShared(self):
515@@ -406,29 +404,29 @@
516
517 # We create an empty shared translation first.
518 self.factory.makeSharedTranslationMessage(
519- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
520+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
521 translations=[u""])
522
523 # When there is no diverged translation, shared one is returned,
524 # but since it's empty, there are no results.
525 found_translations = list(
526- self.devel_sr_pofile.getPOTMsgSetTranslated())
527+ self.devel_pofile.getPOTMsgSetTranslated())
528 self.assertEquals(found_translations, [])
529
530 # When an empty diverged translation is added, nothing is listed.
531 self.factory.makeTranslationMessage(
532- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
533+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
534 translations=[u""])
535 found_translations = list(
536- self.devel_sr_pofile.getPOTMsgSetTranslated())
537+ self.devel_pofile.getPOTMsgSetTranslated())
538 self.assertEquals(found_translations, [])
539
540 # If diverged translation is non-empty, POTMsgSet is listed.
541 self.factory.makeTranslationMessage(
542- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
543+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
544 translations=[u"Translation"])
545 found_translations = list(
546- self.devel_sr_pofile.getPOTMsgSetTranslated())
547+ self.devel_pofile.getPOTMsgSetTranslated())
548 self.assertEquals(found_translations, [self.potmsgset])
549
550 def test_getPOTMsgSetTranslated_Multiple(self):
551@@ -437,7 +435,7 @@
552
553 # Add a diverged translation on the included POTMsgSet...
554 self.factory.makeTranslationMessage(
555- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
556+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
557 translations=[u"Diverged translation"])
558
559 # and a shared translation on newly added POTMsgSet...
560@@ -446,12 +444,12 @@
561 potmsgset.setSequence(self.devel_potemplate, 2)
562
563 self.factory.makeSharedTranslationMessage(
564- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
565+ pofile=self.devel_pofile, potmsgset=potmsgset,
566 translations=[u"Shared translation"])
567
568 # Both POTMsgSets are listed.
569 found_translations = list(
570- self.devel_sr_pofile.getPOTMsgSetTranslated())
571+ self.devel_pofile.getPOTMsgSetTranslated())
572 self.assertEquals(found_translations, [self.potmsgset, potmsgset])
573
574 def test_getPOTMsgSetUntranslated_NoShared(self):
575@@ -460,23 +458,23 @@
576
577 # When there is no diverged translation either, nothing is returned.
578 found_translations = list(
579- self.devel_sr_pofile.getPOTMsgSetUntranslated())
580+ self.devel_pofile.getPOTMsgSetUntranslated())
581 self.assertEquals(found_translations, [self.potmsgset])
582
583 # When a diverged translation is added, the potmsgset is returned.
584 self.factory.makeTranslationMessage(
585- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
586+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
587 translations=[u"Translation"])
588 found_translations = list(
589- self.devel_sr_pofile.getPOTMsgSetUntranslated())
590+ self.devel_pofile.getPOTMsgSetUntranslated())
591 self.assertEquals(found_translations, [])
592
593 # If diverged translation is empty, POTMsgSet is not listed.
594 self.factory.makeTranslationMessage(
595- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
596+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
597 translations=[u""])
598 found_translations = list(
599- self.devel_sr_pofile.getPOTMsgSetUntranslated())
600+ self.devel_pofile.getPOTMsgSetUntranslated())
601 self.assertEquals(found_translations, [self.potmsgset])
602
603 def test_getPOTMsgSetUntranslated_Shared(self):
604@@ -485,28 +483,28 @@
605
606 # We create a shared translation first.
607 self.factory.makeSharedTranslationMessage(
608- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
609+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
610 translations=[u"Shared translation"])
611
612 # When there is no diverged translation, shared one is returned.
613 found_translations = list(
614- self.devel_sr_pofile.getPOTMsgSetUntranslated())
615+ self.devel_pofile.getPOTMsgSetUntranslated())
616 self.assertEquals(found_translations, [])
617
618 # When an empty diverged translation is added, nothing is listed.
619 self.factory.makeTranslationMessage(
620- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
621+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
622 translations=[u""])
623 found_translations = list(
624- self.devel_sr_pofile.getPOTMsgSetUntranslated())
625+ self.devel_pofile.getPOTMsgSetUntranslated())
626 self.assertEquals(found_translations, [self.potmsgset])
627
628 # If diverged translation is non-empty, POTMsgSet is listed.
629 self.factory.makeTranslationMessage(
630- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
631+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
632 translations=[u"Translation"])
633 found_translations = list(
634- self.devel_sr_pofile.getPOTMsgSetUntranslated())
635+ self.devel_pofile.getPOTMsgSetUntranslated())
636 self.assertEquals(found_translations, [])
637
638 def test_getPOTMsgSetUntranslated_EmptyShared(self):
639@@ -515,29 +513,29 @@
640
641 # We create an empty shared translation first.
642 self.factory.makeSharedTranslationMessage(
643- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
644+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
645 translations=[u""])
646
647 # When there is no diverged translation, shared one is returned,
648 # but since it's empty, there are no results.
649 found_translations = list(
650- self.devel_sr_pofile.getPOTMsgSetUntranslated())
651+ self.devel_pofile.getPOTMsgSetUntranslated())
652 self.assertEquals(found_translations, [self.potmsgset])
653
654 # When an empty diverged translation is added, nothing is listed.
655 self.factory.makeTranslationMessage(
656- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
657+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
658 translations=[u""])
659 found_translations = list(
660- self.devel_sr_pofile.getPOTMsgSetUntranslated())
661+ self.devel_pofile.getPOTMsgSetUntranslated())
662 self.assertEquals(found_translations, [self.potmsgset])
663
664 # If diverged translation is non-empty, POTMsgSet is listed.
665 self.factory.makeTranslationMessage(
666- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
667+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
668 translations=[u"Translation"])
669 found_translations = list(
670- self.devel_sr_pofile.getPOTMsgSetUntranslated())
671+ self.devel_pofile.getPOTMsgSetUntranslated())
672 self.assertEquals(found_translations, [])
673
674 def test_getPOTMsgSetUntranslated_Multiple(self):
675@@ -546,7 +544,7 @@
676
677 # Add an empty translation to the included POTMsgSet...
678 self.factory.makeTranslationMessage(
679- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
680+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
681 translations=[u""])
682
683 # ...and a new untranslated POTMsgSet.
684@@ -556,7 +554,7 @@
685
686 # Both POTMsgSets are listed.
687 found_translations = list(
688- self.devel_sr_pofile.getPOTMsgSetUntranslated())
689+ self.devel_pofile.getPOTMsgSetUntranslated())
690 self.assertEquals(found_translations, [self.potmsgset, potmsgset])
691
692 def test_getPOTMsgSetWithNewSuggestions(self):
693@@ -564,17 +562,17 @@
694
695 # When there are no suggestions, nothing is returned.
696 found_translations = list(
697- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
698+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
699 self.assertEquals(found_translations, [])
700
701 # When a suggestion is added, the potmsgset is returned.
702 translation = self.factory.makeSuggestion(
703- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
704+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
705 translations=[u"Suggestion"])
706 self.assertEquals(translation.is_current_ubuntu, False)
707
708 found_translations = list(
709- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
710+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
711 self.assertEquals(found_translations, [self.potmsgset])
712
713 def test_getPOTMsgSetWithNewSuggestions_multiple(self):
714@@ -582,7 +580,7 @@
715
716 # One POTMsgSet has no translations, but only a suggestion.
717 self.factory.makeSuggestion(
718- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
719+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
720 translations=[u"New suggestion"])
721
722 # Another POTMsgSet has both a translation and a suggestion.
723@@ -591,36 +589,36 @@
724 potmsgset.setSequence(self.devel_potemplate, 2)
725 date_created = datetime.now(pytz.UTC) - timedelta(5)
726 self.factory.makeTranslationMessage(
727- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
728+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
729 translations=[u"Translation"], date_updated=date_created)
730 suggestion_date = date_created + timedelta(1)
731 self.factory.makeSuggestion(
732- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
733- translations=[u"New suggestion"], date_updated=suggestion_date)
734+ pofile=self.devel_pofile, potmsgset=potmsgset,
735+ translations=[u"New suggestion"], date_created=suggestion_date)
736
737 # Both POTMsgSets are listed.
738 found_translations = list(
739- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
740+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
741 self.assertEquals(found_translations, [self.potmsgset, potmsgset])
742
743 def test_getPOTMsgSetWithNewSuggestions_distinct(self):
744 # Provide two suggestions on a single message and make sure
745 # a POTMsgSet is returned only once.
746 self.factory.makeSuggestion(
747- pofile=self.devel_sr_pofile,
748+ pofile=self.devel_pofile,
749 potmsgset=self.potmsgset,
750 translations=["A suggestion"])
751 self.factory.makeSuggestion(
752- pofile=self.devel_sr_pofile,
753+ pofile=self.devel_pofile,
754 potmsgset=self.potmsgset,
755 translations=["Another suggestion"])
756
757 potmsgsets = list(
758- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
759+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
760 self.assertEquals(potmsgsets,
761 [self.potmsgset])
762 self.assertEquals(
763- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions().count(),
764+ self.devel_pofile.getPOTMsgSetWithNewSuggestions().count(),
765 1)
766
767 def test_getPOTMsgSetWithNewSuggestions_empty(self):
768@@ -628,12 +626,12 @@
769
770 # When an empty suggestion is added, the potmsgset is NOT returned.
771 translation = self.factory.makeSuggestion(
772- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
773- translations=[None])
774+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
775+ translations=[])
776 self.assertEquals(False, translation.is_current_ubuntu)
777
778 found_translations = list(
779- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
780+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
781 self.assertEquals([], found_translations)
782
783 def test_getPOTMsgSetChangedInUbuntu(self):
784@@ -641,72 +639,72 @@
785
786 # If there are no translations in Ubuntu, nothing is listed.
787 found_translations = list(
788- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
789+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
790 self.assertEquals(found_translations, [])
791
792 # Adding a non-imported current translation doesn't change anything.
793 translation = self.factory.makeSharedTranslationMessage(
794- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
795+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
796 translations=[u"Non-imported translation"])
797 self.assertEquals(translation.is_current_upstream, False)
798 found_translations = list(
799- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
800+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
801 self.assertEquals(found_translations, [])
802
803 # Adding an imported translation which is also current indicates
804 # that there are no changes.
805 translation = self.factory.makeSharedTranslationMessage(
806- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
807+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
808 translations=[u"Imported translation"], is_current_upstream=True)
809 self.assertEquals(translation.is_current_upstream, True)
810 self.assertEquals(translation.is_current_ubuntu, True)
811 found_translations = list(
812- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
813+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
814 self.assertEquals(found_translations, [])
815
816 # However, changing current translation to a non-imported one
817 # makes this a changed in Ubuntu translation.
818 translation = self.factory.makeSharedTranslationMessage(
819- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
820+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
821 translations=[u"Changed translation"], is_current_upstream=False)
822 self.assertEquals(translation.is_current_upstream, False)
823 self.assertEquals(translation.is_current_ubuntu, True)
824 found_translations = list(
825- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
826+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
827 self.assertEquals(found_translations, [self.potmsgset])
828
829 # Adding a diverged, non-imported translation, still lists
830 # it as a changed translation.
831 translation = self.factory.makeTranslationMessage(
832- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
833+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
834 translations=[u"Diverged translation"], is_current_upstream=False)
835 self.assertEquals(translation.is_current_upstream, False)
836 self.assertEquals(translation.is_current_ubuntu, True)
837 found_translations = list(
838- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
839+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
840 self.assertEquals(found_translations, [self.potmsgset])
841
842 # But adding a diverged current and imported translation means
843 # that it's not changed anymore.
844 translation = self.factory.makeTranslationMessage(
845- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
846+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
847 translations=[u"Diverged imported"], is_current_upstream=True,
848 force_diverged=True)
849 self.assertEquals(translation.is_current_upstream, True)
850 self.assertEquals(translation.is_current_ubuntu, True)
851 found_translations = list(
852- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
853+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
854 self.assertEquals(found_translations, [])
855
856 # Changing from a diverged, imported translation is correctly
857 # detected.
858 translation = self.factory.makeTranslationMessage(
859- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
860+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
861 translations=[u"Diverged changed"], is_current_upstream=False)
862 self.assertEquals(translation.is_current_upstream, False)
863 self.assertEquals(translation.is_current_ubuntu, True)
864 found_translations = list(
865- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
866+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
867 self.assertEquals(found_translations, [self.potmsgset])
868
869 def test_getPOTMsgSetChangedInUbuntu_diverged_imported(self):
870@@ -720,11 +718,11 @@
871 # 1) Shared imported and current translation.
872 # 2) Diverged, imported, non-current message.
873 shared = self.factory.makeSharedTranslationMessage(
874- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
875+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
876 translations=[u"Shared imported current"],
877 is_current_upstream=True)
878 diverged = self.factory.makeTranslationMessage(
879- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
880+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
881 translations=[u"Diverged imported non-current"],
882 is_current_upstream=True, force_diverged=True)
883 # As we can't come to this situation using existing code,
884@@ -740,7 +738,7 @@
885
886 # Such POTMsgSet is not considered changed in this PO file.
887 found_translations = list(
888- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
889+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
890 self.assertEquals(found_translations, [])
891
892 def test_getPOTMsgSetChangedInUbuntu_SharedDiverged(self):
893@@ -749,34 +747,34 @@
894 # Adding an imported translation which is also current indicates
895 # that there are no changes.
896 translation = self.factory.makeSharedTranslationMessage(
897- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
898+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
899 translations=[u"Imported translation"], is_current_upstream=True)
900 self.assertEquals(translation.is_current_upstream, True)
901 self.assertEquals(translation.is_current_ubuntu, True)
902 found_translations = list(
903- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
904+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
905 self.assertEquals(found_translations, [])
906
907 # Adding a diverged, non-imported translation makes it appear
908 # as changed.
909 translation = self.factory.makeTranslationMessage(
910- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
911+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
912 translations=[u"Changed translation"], is_current_upstream=False)
913 self.assertEquals(translation.is_current_upstream, False)
914 self.assertEquals(translation.is_current_ubuntu, True)
915 found_translations = list(
916- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
917+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
918 self.assertEquals(found_translations, [self.potmsgset])
919
920 def test_getPOTMsgSetWithErrors(self):
921 # Test listing of POTMsgSets with errors in translations.
922 translation = self.factory.makeSharedTranslationMessage(
923- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
924+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
925 translations=[u"Imported translation"], is_current_upstream=True)
926 removeSecurityProxy(translation).validation_status = (
927 TranslationValidationStatus.UNKNOWNERROR)
928 found_translations = list(
929- self.devel_sr_pofile.getPOTMsgSetWithErrors())
930+ self.devel_pofile.getPOTMsgSetWithErrors())
931 self.assertEquals(found_translations, [self.potmsgset])
932
933 def test_updateStatistics(self):
934@@ -796,71 +794,71 @@
935 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
936 potmsgset.setSequence(self.devel_potemplate, 2)
937 self.factory.makeSuggestion(
938- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
939+ pofile=self.devel_pofile, potmsgset=potmsgset,
940 translations=[u"Unreviewed suggestion"])
941
942 # Third POTMsgSet is translated, and with a suggestion.
943 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
944 potmsgset.setSequence(self.devel_potemplate, 3)
945 self.factory.makeTranslationMessage(
946- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
947+ pofile=self.devel_pofile, potmsgset=potmsgset,
948 translations=[u"Translation"],
949 date_updated=datetime.now(pytz.UTC)-timedelta(1))
950 self.factory.makeSuggestion(
951- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
952+ pofile=self.devel_pofile, potmsgset=potmsgset,
953 translations=[u"Another suggestion"])
954
955 # Fourth POTMsgSet is translated in import.
956 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
957 potmsgset.setSequence(self.devel_potemplate, 4)
958 self.factory.makeTranslationMessage(
959- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
960+ pofile=self.devel_pofile, potmsgset=potmsgset,
961 translations=[u"Imported translation"], is_current_upstream=True)
962
963 # Fifth POTMsgSet is translated in import, but changed in Ubuntu.
964 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
965 potmsgset.setSequence(self.devel_potemplate, 5)
966 self.factory.makeTranslationMessage(
967- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
968+ pofile=self.devel_pofile, potmsgset=potmsgset,
969 translations=[u"Imported translation"], is_current_upstream=True)
970 translation = self.factory.makeTranslationMessage(
971- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
972+ pofile=self.devel_pofile, potmsgset=potmsgset,
973 translations=[u"LP translation"], is_current_upstream=False)
974
975 # Sixth POTMsgSet is translated in LP only.
976 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
977 potmsgset.setSequence(self.devel_potemplate, 6)
978 self.factory.makeTranslationMessage(
979- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
980+ pofile=self.devel_pofile, potmsgset=potmsgset,
981 translations=[u"New translation"], is_current_upstream=False)
982
983 removeSecurityProxy(self.devel_potemplate).messagecount = (
984 self.devel_potemplate.getPOTMsgSetsCount())
985
986 # Returns current, updates, rosetta, unreviewed counts.
987- stats = self.devel_sr_pofile.updateStatistics()
988+ stats = self.devel_pofile.updateStatistics()
989 self.assertEquals((1, 1, 3, 2), stats)
990
991- self.assertEquals(6, self.devel_sr_pofile.messageCount())
992- self.assertEquals(4, self.devel_sr_pofile.translatedCount())
993- self.assertEquals(2, self.devel_sr_pofile.untranslatedCount())
994- self.assertEquals(1, self.devel_sr_pofile.currentCount())
995- self.assertEquals(3, self.devel_sr_pofile.rosettaCount())
996- self.assertEquals(1, self.devel_sr_pofile.updatesCount())
997- self.assertEquals(2, self.devel_sr_pofile.unreviewedCount())
998+ self.assertEquals(6, self.devel_pofile.messageCount())
999+ self.assertEquals(4, self.devel_pofile.translatedCount())
1000+ self.assertEquals(2, self.devel_pofile.untranslatedCount())
1001+ self.assertEquals(1, self.devel_pofile.currentCount())
1002+ self.assertEquals(3, self.devel_pofile.rosettaCount())
1003+ self.assertEquals(1, self.devel_pofile.updatesCount())
1004+ self.assertEquals(2, self.devel_pofile.unreviewedCount())
1005
1006 def test_TranslationFileData_adapter(self):
1007 # Test that exporting works correctly with shared and diverged
1008 # messages.
1009 self.factory.makeSharedTranslationMessage(
1010- pofile=self.devel_sr_pofile,
1011+ pofile=self.devel_pofile,
1012 potmsgset=self.potmsgset,
1013 translations=["Shared translation"])
1014
1015 # Get the adapter and extract only English singular and
1016 # first translation form from all messages.
1017 translation_file_data = getAdapter(
1018- self.devel_sr_pofile, ITranslationFileData, 'all_messages')
1019+ self.devel_pofile, ITranslationFileData, 'all_messages')
1020 exported_messages = [
1021 (msg.singular_text, msg.translations[0])
1022 for msg in translation_file_data.messages]
1023@@ -870,7 +868,7 @@
1024
1025 # When we add a diverged translation, only that is exported.
1026 self.factory.makeTranslationMessage(
1027- pofile=self.devel_sr_pofile,
1028+ pofile=self.devel_pofile,
1029 potmsgset=self.potmsgset,
1030 translations=["Diverged translation"],
1031 force_diverged=True)
1032@@ -878,7 +876,7 @@
1033 # Get the adapter and extract only English singular and
1034 # first translation form from all messages.
1035 translation_file_data = getAdapter(
1036- self.devel_sr_pofile, ITranslationFileData, 'all_messages')
1037+ self.devel_pofile, ITranslationFileData, 'all_messages')
1038 exported_messages = [
1039 (msg.singular_text, msg.translations[0])
1040 for msg in translation_file_data.messages]
1041@@ -1041,9 +1039,9 @@
1042 name="messages")
1043
1044 # We'll use two PO files, one for each series.
1045- self.devel_sr_pofile = self.factory.makePOFile(
1046+ self.devel_pofile = self.factory.makePOFile(
1047 'sr', self.devel_potemplate)
1048- self.stable_sr_pofile = self.factory.makePOFile(
1049+ self.stable_pofile = self.factory.makePOFile(
1050 'sr', self.stable_potemplate)
1051
1052 # Create two POTMsgSets that can be used to test in what order
1053@@ -1054,19 +1052,19 @@
1054 self.potmsgset2.setSequence(self.devel_potemplate, 2)
1055
1056 def test_getPOTMsgSetTranslated_ordering(self):
1057- # Translate both POTMsgSets in devel_sr_pofile, so
1058+ # Translate both POTMsgSets in devel_pofile, so
1059 # they are returned with getPOTMsgSetTranslated() call.
1060 self.factory.makeSharedTranslationMessage(
1061- pofile=self.devel_sr_pofile,
1062+ pofile=self.devel_pofile,
1063 potmsgset=self.potmsgset1,
1064 translations=["Shared translation"])
1065 self.factory.makeSharedTranslationMessage(
1066- pofile=self.devel_sr_pofile,
1067+ pofile=self.devel_pofile,
1068 potmsgset=self.potmsgset2,
1069 translations=["Another shared translation"])
1070
1071 translated_potmsgsets = list(
1072- self.devel_sr_pofile.getPOTMsgSetTranslated())
1073+ self.devel_pofile.getPOTMsgSetTranslated())
1074 self.assertEquals(
1075 [self.potmsgset1, self.potmsgset2], translated_potmsgsets)
1076
1077@@ -1077,20 +1075,20 @@
1078
1079 # And they are returned in the new order as desired.
1080 translated_potmsgsets = list(
1081- self.stable_sr_pofile.getPOTMsgSetTranslated())
1082+ self.stable_pofile.getPOTMsgSetTranslated())
1083 self.assertEquals(
1084 [self.potmsgset2, self.potmsgset1], translated_potmsgsets)
1085
1086 # Order is unchanged for the previous template.
1087 translated_potmsgsets = list(
1088- self.devel_sr_pofile.getPOTMsgSetTranslated())
1089+ self.devel_pofile.getPOTMsgSetTranslated())
1090 self.assertEquals(
1091 [self.potmsgset1, self.potmsgset2], translated_potmsgsets)
1092
1093 def test_getPOTMsgSetUntranslated_ordering(self):
1094- # Both POTMsgSets in devel_sr_pofile are untranslated.
1095+ # Both POTMsgSets in devel_pofile are untranslated.
1096 untranslated_potmsgsets = list(
1097- self.devel_sr_pofile.getPOTMsgSetUntranslated())
1098+ self.devel_pofile.getPOTMsgSetUntranslated())
1099 self.assertEquals(
1100 [self.potmsgset1, self.potmsgset2], untranslated_potmsgsets)
1101
1102@@ -1101,42 +1099,42 @@
1103
1104 # And they are returned in the new order as desired.
1105 untranslated_potmsgsets = list(
1106- self.stable_sr_pofile.getPOTMsgSetUntranslated())
1107+ self.stable_pofile.getPOTMsgSetUntranslated())
1108 self.assertEquals(
1109 [self.potmsgset2, self.potmsgset1], untranslated_potmsgsets)
1110
1111 # Order is unchanged for the previous template.
1112 untranslated_potmsgsets = list(
1113- self.devel_sr_pofile.getPOTMsgSetUntranslated())
1114+ self.devel_pofile.getPOTMsgSetUntranslated())
1115 self.assertEquals(
1116 [self.potmsgset1, self.potmsgset2], untranslated_potmsgsets)
1117
1118 def test_getPOTMsgSetChangedInUbuntu_ordering(self):
1119- # Suggest a translation on both POTMsgSets in devel_sr_pofile,
1120+ # Suggest a translation on both POTMsgSets in devel_pofile,
1121 # so they are returned with getPOTMsgSetWithNewSuggestions() call.
1122 self.factory.makeSharedTranslationMessage(
1123- pofile=self.devel_sr_pofile,
1124+ pofile=self.devel_pofile,
1125 potmsgset=self.potmsgset1,
1126 translations=["Imported"],
1127 is_current_upstream=True)
1128 self.factory.makeSharedTranslationMessage(
1129- pofile=self.devel_sr_pofile,
1130+ pofile=self.devel_pofile,
1131 potmsgset=self.potmsgset1,
1132 translations=["Changed"],
1133 is_current_upstream=False)
1134 self.factory.makeSharedTranslationMessage(
1135- pofile=self.devel_sr_pofile,
1136+ pofile=self.devel_pofile,
1137 potmsgset=self.potmsgset2,
1138 translations=["Another imported"],
1139 is_current_upstream=True)
1140 self.factory.makeSharedTranslationMessage(
1141- pofile=self.devel_sr_pofile,
1142+ pofile=self.devel_pofile,
1143 potmsgset=self.potmsgset2,
1144 translations=["Another changed"],
1145 is_current_upstream=False)
1146
1147 potmsgsets = list(
1148- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1149+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1150 self.assertEquals(
1151 [self.potmsgset1, self.potmsgset2], potmsgsets)
1152
1153@@ -1147,28 +1145,28 @@
1154
1155 # And they are returned in the new order as desired.
1156 potmsgsets = list(
1157- self.stable_sr_pofile.getPOTMsgSetChangedInUbuntu())
1158+ self.stable_pofile.getPOTMsgSetChangedInUbuntu())
1159 self.assertEquals(
1160 [self.potmsgset2, self.potmsgset1], potmsgsets)
1161
1162 # Order is unchanged for the previous template.
1163 potmsgsets = list(
1164- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1165+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1166 self.assertEquals(
1167 [self.potmsgset1, self.potmsgset2], potmsgsets)
1168
1169 def test_getPOTMsgSetWithErrors_ordering(self):
1170- # Suggest a translation on both POTMsgSets in devel_sr_pofile,
1171+ # Suggest a translation on both POTMsgSets in devel_pofile,
1172 # so they are returned with getPOTMsgSetWithNewSuggestions() call.
1173 imported1 = self.factory.makeSharedTranslationMessage(
1174- pofile=self.devel_sr_pofile,
1175+ pofile=self.devel_pofile,
1176 potmsgset=self.potmsgset1,
1177 translations=["Imported"],
1178 is_current_upstream=True)
1179 removeSecurityProxy(imported1).validation_status = (
1180 TranslationValidationStatus.UNKNOWNERROR)
1181 imported2 = self.factory.makeSharedTranslationMessage(
1182- pofile=self.devel_sr_pofile,
1183+ pofile=self.devel_pofile,
1184 potmsgset=self.potmsgset2,
1185 translations=["Another imported"],
1186 is_current_upstream=True)
1187@@ -1176,7 +1174,7 @@
1188 TranslationValidationStatus.UNKNOWNERROR)
1189
1190 potmsgsets = list(
1191- self.devel_sr_pofile.getPOTMsgSetWithErrors())
1192+ self.devel_pofile.getPOTMsgSetWithErrors())
1193 self.assertEquals(
1194 [self.potmsgset1, self.potmsgset2], potmsgsets)
1195
1196@@ -1187,13 +1185,13 @@
1197
1198 # And they are returned in the new order as desired.
1199 potmsgsets = list(
1200- self.stable_sr_pofile.getPOTMsgSetWithErrors())
1201+ self.stable_pofile.getPOTMsgSetWithErrors())
1202 self.assertEquals(
1203 [self.potmsgset2, self.potmsgset1], potmsgsets)
1204
1205 # Order is unchanged for the previous template.
1206 potmsgsets = list(
1207- self.devel_sr_pofile.getPOTMsgSetWithErrors())
1208+ self.devel_pofile.getPOTMsgSetWithErrors())
1209 self.assertEquals(
1210 [self.potmsgset1, self.potmsgset2], potmsgsets)
1211
1212@@ -1228,11 +1226,11 @@
1213
1214 # Give the method something to search for.
1215 self.factory.makeSharedTranslationMessage(
1216- pofile=self.devel_sr_pofile,
1217+ pofile=self.devel_pofile,
1218 potmsgset=self.potmsgset1,
1219 translations=["Shared translation"])
1220 self.factory.makeSharedTranslationMessage(
1221- pofile=self.devel_sr_pofile,
1222+ pofile=self.devel_pofile,
1223 potmsgset=self.potmsgset2,
1224 translations=["Another shared translation"])
1225
1226@@ -1241,7 +1239,7 @@
1227 removeSecurityProxy(self.potmsgset2).sequence = 1
1228
1229 potmsgsets = list(
1230- self.devel_sr_pofile.findPOTMsgSetsContaining("translation"))
1231+ self.devel_pofile.findPOTMsgSetsContaining("translation"))
1232
1233 # Order ignores potmsgset.sequence.
1234 self.assertEquals(
1235
1236=== modified file 'lib/lp/translations/tests/test_translatablemessage.py'
1237--- lib/lp/translations/tests/test_translatablemessage.py 2010-08-16 09:01:35 +0000
1238+++ lib/lp/translations/tests/test_translatablemessage.py 2010-08-16 15:11:45 +0000
1239@@ -47,7 +47,7 @@
1240 if is_suggestion:
1241 return self.factory.makeSuggestion(
1242 pofile=self.pofile, potmsgset=self.potmsgset,
1243- translations=translation, date_updated=date_updated)
1244+ translations=translation, date_created=date_updated)
1245 else:
1246 return self.factory.makeTranslationMessage(
1247 pofile=self.pofile, potmsgset=self.potmsgset,
1248
1249=== modified file 'lib/lp/translations/tests/test_translations_to_review.py'
1250--- lib/lp/translations/tests/test_translations_to_review.py 2010-08-16 09:01:35 +0000
1251+++ lib/lp/translations/tests/test_translations_to_review.py 2010-08-16 15:11:55 +0000
1252@@ -86,7 +86,7 @@
1253 self.factory.makeSuggestion(
1254 potmsgset=self.potmsgset, pofile=self.pofile,
1255 translator=self.factory.makePerson(), translations=['wi'],
1256- date_updated=later_time))
1257+ date_created=later_time))
1258
1259 self.assertTrue(self.translation.is_current_ubuntu)
1260 self.pofile.updateStatistics()
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Thanks for all the work you put in cleaning things up! I'm perfectly happy for you to reject cleanups I suggested (but did not require) in pre-existing code. The goal of a review is to get the branch in, not to keep it out or delay it. It's good as it is.

The only part of this tome that needs any further follow-up AFAIC is this bit:

>> # Setting a suggestion as current makes it have no unreviewed
>> # suggestions.
>>
>> As far as I know, that only happens if the review date is also updated.
>> (The creation or last-update date may be used as a fallback if the review
>> date is not set; I don't recall off the top of my head). In that case,
>> the new current translation is presumably newer than all suggestions and
>> so leaves no new suggestions. But the test code there only sets the
>> flag. I think this passes more or less by accident; what if there's
>> another suggestion that's newer than the suggestion that's being made
>> current?
>
> Didn't the old validators do all that? I agree though, that this most
> likely passes by accident now and I am pretty sure there may be more tests
> that do.

The validators only disabled the incumbent current message (if any). They did not set the review timestamp.

> This branch was meant as a mechanical replacement, though, so I think
> trying to check and fix all tests is beyond the scope.

That's fine with me. Could you add a note though, so we don't miss this when we debug problems with this test in the future? No need even to be completely 100% sure of what happens, just point out to future readers that there may possibly be a pitfall there.

Oh, and... Congratulations. :-)

Jeroen

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/testing/factory.py'
2--- lib/lp/testing/factory.py 2010-08-10 17:28:08 +0000
3+++ lib/lp/testing/factory.py 2010-08-17 09:48:55 +0000
4@@ -2072,8 +2072,7 @@
5 if pofile is None:
6 pofile = self.makePOFile('sr')
7 if potmsgset is None:
8- potmsgset = self.makePOTMsgSet(pofile.potemplate)
9- potmsgset.setSequence(pofile.potemplate, 1)
10+ potmsgset = self.makePOTMsgSet(pofile.potemplate, sequence=1)
11 if translator is None:
12 translator = self.makePerson()
13 if translations is None:
14@@ -2092,6 +2091,42 @@
15 naked_translation_message.sync()
16 return translation_message
17
18+ def _makeTranslationsDict(self, translations=None):
19+ """Make sure translations are stored in a dict, e.g. {0: "foo"}.
20+
21+ If translations is already dict, it is returned unchanged.
22+ If translations is a sequence, it is enumerated into a dict.
23+ If translations is None, an arbitrary single translation is created.
24+ """
25+ if translations is None:
26+ return {0: self.getUniqueString()}
27+ if isinstance(translations, dict):
28+ return translations
29+ assert isinstance(translations, (list, tuple)), (
30+ "Expecting either a dict or a sequence." )
31+ return dict(enumerate(translations))
32+
33+ def makeSuggestion(self, pofile=None, potmsgset=None, translator=None,
34+ translations=None, date_created=None):
35+ """Make a new suggested `TranslationMessage` in the given PO file."""
36+ if pofile is None:
37+ pofile = self.makePOFile('sr')
38+ if potmsgset is None:
39+ potmsgset = self.makePOTMsgSet(pofile.potemplate, sequence=1)
40+ if translator is None:
41+ translator = self.makePerson()
42+ translations = self._makeTranslationsDict(translations)
43+ translation_message = potmsgset.submitSuggestion(
44+ pofile, translator, translations)
45+ assert translation_message is not None, (
46+ "Cannot make suggestion on translation credits POTMsgSet.")
47+ if date_created is not None:
48+ naked_translation_message = removeSecurityProxy(
49+ translation_message)
50+ naked_translation_message.date_created = date_created
51+ naked_translation_message.sync()
52+ return translation_message
53+
54 def makeSharedTranslationMessage(self, pofile=None, potmsgset=None,
55 translator=None, suggestion=False,
56 reviewer=None, translations=None,
57
58=== modified file 'lib/lp/translations/browser/tests/test_pofile_view.py'
59--- lib/lp/translations/browser/tests/test_pofile_view.py 2010-08-04 11:00:51 +0000
60+++ lib/lp/translations/browser/tests/test_pofile_view.py 2010-08-17 09:48:55 +0000
61@@ -45,9 +45,8 @@
62 self.factory.makeTranslationMessage(
63 self.pofile, self.new_suggestion,
64 date_updated=self.now())
65- self.factory.makeTranslationMessage(
66- self.pofile, self.new_suggestion, suggestion=True,
67- date_updated=self.now())
68+ self.factory.makeSuggestion(
69+ self.pofile, self.new_suggestion, date_created=self.now())
70 # An upstream that was changed in Ubuntu.
71 self.changed = self.factory.makePOTMsgSet(
72 self.potemplate, sequence=4)
73@@ -171,8 +170,3 @@
74 def setUp(self):
75 super(TestPOFileTranslateViewInvalidFiltering, self).setUp()
76 self.pofile = self.factory.makePOFile('eo')
77-
78-
79-def test_suite():
80- return TestLoader().loadTestsFromName(__name__)
81-
82
83=== modified file 'lib/lp/translations/browser/tests/test_translationmessage_view.py'
84--- lib/lp/translations/browser/tests/test_translationmessage_view.py 2010-03-23 19:49:56 +0000
85+++ lib/lp/translations/browser/tests/test_translationmessage_view.py 2010-08-17 09:48:55 +0000
86@@ -51,13 +51,20 @@
87 translations = translation
88 else:
89 translations = [translation]
90- message = self.factory.makeTranslationMessage(
91- self.pofile, self.potmsgset,
92- translations=translations,
93- suggestion=suggestion,
94- is_current_upstream=is_packaged,
95- translator=self.owner,
96- date_updated=self.now())
97+ if suggestion:
98+ message = self.factory.makeSuggestion(
99+ self.pofile, self.potmsgset,
100+ translations=translations,
101+ translator=self.owner,
102+ date_created=self.now())
103+ else:
104+ message = self.factory.makeTranslationMessage(
105+ self.pofile, self.potmsgset,
106+ translations=translations,
107+ suggestion=suggestion,
108+ is_current_upstream=is_packaged,
109+ translator=self.owner,
110+ date_updated=self.now())
111 message.browser_pofile = self.pofile
112 return message
113
114
115=== modified file 'lib/lp/translations/browser/translationmessage.py'
116--- lib/lp/translations/browser/translationmessage.py 2010-08-04 11:00:51 +0000
117+++ lib/lp/translations/browser/translationmessage.py 2010-08-17 09:48:55 +0000
118@@ -58,12 +58,10 @@
119 from canonical.launchpad.webapp.batching import BatchNavigator
120 from canonical.launchpad.webapp.menu import structured
121
122-
123 #
124 # Exceptions and helper classes
125 #
126
127-
128 class POTMsgSetBatchNavigator(BatchNavigator):
129
130 def __init__(self, results, request, start=0, size=1):
131@@ -138,6 +136,7 @@
132 #
133 # Standard UI classes
134 #
135+
136 class CurrentTranslationMessageFacets(POTemplateFacets):
137 usedfor = ITranslationMessage
138
139@@ -171,6 +170,7 @@
140 #
141 # Views
142 #
143+
144 class CurrentTranslationMessageIndexView:
145 """A view to forward to the translation form."""
146
147@@ -536,7 +536,7 @@
148 elif fallback_language is not None:
149 # If there's a standard alternative language and no
150 # user-specified language was provided, preselect it.
151- alternative_language = fallback_language
152+ alternative_language = fallback_language
153 second_lang_code = fallback_language.code
154 else:
155 # The second_lang_code is None and there is no fallback_language.
156@@ -1511,10 +1511,6 @@
157
158 implements(ITranslationMessageSuggestions)
159
160- def isFromSamePOFile(self, submission):
161- """Return if submission is from the same PO file as a POMsgSet."""
162- return self.pofile == submission['pofile']
163-
164 def __init__(self, title, translation, submissions,
165 user_is_official_translator, form_is_writeable,
166 plural_form, seen_translations=None, legal_warning=False):
167
168=== modified file 'lib/lp/translations/tests/test_pofile.py'
169--- lib/lp/translations/tests/test_pofile.py 2010-08-10 14:39:46 +0000
170+++ lib/lp/translations/tests/test_pofile.py 2010-08-17 09:48:55 +0000
171@@ -1,8 +1,6 @@
172 # Copyright 2009-2010 Canonical Ltd. This software is licensed under the
173 # GNU Affero General Public License version 3 (see the file LICENSE).
174
175-# pylint: disable-msg=C0102
176-
177 __metaclass__ = type
178
179 from datetime import datetime, timedelta
180@@ -25,6 +23,171 @@
181 from canonical.launchpad.webapp.publisher import canonical_url
182
183
184+class TestTranslationSharedPOFileSourcePackage(TestCaseWithFactory):
185+ """Test behavior of PO files with shared POTMsgSets on a source package.
186+ """
187+
188+ layer = ZopelessDatabaseLayer
189+
190+ def setUp(self):
191+ # Create a product with two series and a shared POTemplate
192+ # in different series ('devel' and 'stable').
193+ super(TestTranslationSharedPOFileSourcePackage, self).setUp()
194+ self.foo = self.factory.makeDistribution()
195+ self.foo_devel = self.factory.makeDistroSeries(
196+ name='devel', distribution=self.foo)
197+ self.foo_stable = self.factory.makeDistroSeries(
198+ name='stable', distribution=self.foo)
199+ self.foo.official_rosetta = True
200+ self.sourcepackagename = self.factory.makeSourcePackageName()
201+
202+ # Two POTemplates share translations if they have the same name,
203+ # in this case 'messages'.
204+ self.devel_potemplate = self.factory.makePOTemplate(
205+ distroseries=self.foo_devel,
206+ sourcepackagename=self.sourcepackagename,
207+ name="messages")
208+ self.stable_potemplate = self.factory.makePOTemplate(
209+ distroseries=self.foo_stable,
210+ sourcepackagename=self.sourcepackagename,
211+ name="messages")
212+
213+ # We'll use two PO files, one for each series.
214+ self.devel_pofile = self.factory.makePOFile(
215+ 'sr', self.devel_potemplate)
216+ self.stable_pofile = self.factory.makePOFile(
217+ 'sr', self.stable_potemplate)
218+
219+ # The POTMsgSet is added to only one of the POTemplates.
220+ self.potmsgset = self.factory.makePOTMsgSet(
221+ self.devel_potemplate, sequence=1)
222+
223+ def test_getPOTMsgSetWithNewSuggestions_shared(self):
224+ # Test listing of suggestions for POTMsgSets with a shared
225+ # translation.
226+
227+ # A POTMsgSet has a shared, current translation created 5 days ago.
228+ date_created = datetime.now(pytz.UTC) - timedelta(5)
229+ translation = self.factory.makeSuggestion(
230+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
231+ translations=[u"Translation"], date_created=date_created)
232+ translation.is_current_ubuntu = True
233+
234+ # When there are no suggestions, nothing is returned.
235+ found_translations = list(
236+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
237+ self.assertEquals(found_translations, [])
238+
239+ # When a suggestion is added one day after, the potmsgset is returned.
240+ suggestion_date = date_created + timedelta(1)
241+ suggestion = self.factory.makeSuggestion(
242+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
243+ translations=[u"Suggestion"], date_created=suggestion_date)
244+ self.assertEquals(suggestion.is_current_ubuntu, False)
245+
246+ found_translations = list(
247+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
248+ self.assertEquals(found_translations, [self.potmsgset])
249+
250+ # Setting a suggestion as current makes it have no unreviewed
251+ # suggestions.
252+ # XXX henninge 2010-08-17: It looks like this test passes by
253+ # accident as the suggestion already is the newest translation
254+ # available. Other tests may be passing just by accident, too.
255+ # This will have to be investigated when all bits and pieces are in
256+ # place.
257+ translation.is_current_ubuntu = False
258+ suggestion.is_current_ubuntu = True
259+ found_translations = list(
260+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
261+ self.assertEquals(found_translations, [])
262+
263+ # And adding another suggestion 2 days later, the potmsgset is
264+ # again returned.
265+ suggestion_date += timedelta(2)
266+ translation = self.factory.makeSuggestion(
267+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
268+ translations=[u"New suggestion"], date_created=suggestion_date)
269+ self.assertEquals(translation.is_current_ubuntu, False)
270+
271+ found_translations = list(
272+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
273+ self.assertEquals(found_translations, [self.potmsgset])
274+
275+ def test_getPOTMsgSetWithNewSuggestions_diverged(self):
276+ # Test listing of suggestions for POTMsgSets with a shared
277+ # translation and a later diverged one.
278+
279+ # First we create a shared translation (5 days old), a diverged
280+ # translation 1 day later.
281+ # Then we make sure that getting unreviewed messages works when:
282+ # * A suggestion is added 1 day after (shows as unreviewed).
283+ # * A new diverged translation is added another day later (nothing).
284+ # * A new suggestion is added after another day (shows).
285+ # * Suggestion is made active (nothing).
286+
287+ # A POTMsgSet has a shared, current translation created 5 days ago.
288+ date_created = datetime.now(pytz.UTC) - timedelta(5)
289+ translation = self.factory.makeSuggestion(
290+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
291+ translations=[u"Shared translation"], date_created=date_created)
292+ translation.is_current_ubuntu = True
293+
294+ # And we also have a diverged translation created a day after a shared
295+ # current translation.
296+ diverged_date = date_created + timedelta(1)
297+ diverged_translation = self.factory.makeSuggestion(
298+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
299+ translations=[u"Old translation"], date_created=diverged_date)
300+ diverged_translation.potemplate = self.devel_potemplate
301+ diverged_translation.is_current_ubuntu = True
302+
303+ # There is also a suggestion against the shared translation
304+ # created 2 days after the shared translation.
305+ suggestion_date = date_created + timedelta(2)
306+ suggestion = self.factory.makeSuggestion(
307+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
308+ translations=[u"Shared suggestion"], date_created=suggestion_date)
309+ self.assertEquals(suggestion.is_current_ubuntu, False)
310+
311+ # A suggestion is shown since diverged_date < suggestion_date.
312+ found_translations = list(
313+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
314+ self.assertEquals(found_translations, [self.potmsgset])
315+
316+ # When a diverged translation is added after the shared suggestion,
317+ # there are no unreviewed suggestions.
318+ diverged_date = suggestion_date + timedelta(1)
319+ diverged_translation_2 = self.factory.makeTranslationMessage(
320+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
321+ translations=[u"Translation"], date_updated=diverged_date)
322+ diverged_translation.is_current_ubuntu = False
323+ diverged_translation_2.potemplate = self.devel_potemplate
324+ diverged_translation_2.is_current_ubuntu = True
325+ found_translations = list(
326+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
327+ self.assertEquals(found_translations, [])
328+
329+ # When a suggestion is added one day after, the potmsgset is returned.
330+ suggestion_date = diverged_date + timedelta(1)
331+ suggestion = self.factory.makeSuggestion(
332+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
333+ translations=[u"Suggestion"], date_created=suggestion_date)
334+ self.assertEquals(suggestion.is_current_ubuntu, False)
335+
336+ found_translations = list(
337+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
338+ self.assertEquals(found_translations, [self.potmsgset])
339+
340+ # Setting a suggestion as current makes it have no unreviewed
341+ # suggestions.
342+ translation.is_current_ubuntu = False
343+ suggestion.is_current_ubuntu = True
344+ found_translations = list(
345+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
346+ self.assertEquals(found_translations, [])
347+
348+
349 class TestTranslationSharedPOFile(TestCaseWithFactory):
350 """Test behaviour of PO files with shared POTMsgSets."""
351
352@@ -41,22 +204,22 @@
353 name='stable', product=self.foo)
354 self.foo.official_rosetta = True
355
356- # POTemplate is 'shared' if it has the same name ('messages').
357+ # Two POTemplates share translations if they have the same name,
358+ # in this case 'messages'.
359 self.devel_potemplate = self.factory.makePOTemplate(
360 productseries=self.foo_devel, name="messages")
361 self.stable_potemplate = self.factory.makePOTemplate(self.foo_stable,
362 name="messages")
363
364 # We'll use two PO files, one for each series.
365- self.devel_sr_pofile = self.factory.makePOFile(
366+ self.devel_pofile = self.factory.makePOFile(
367 'sr', self.devel_potemplate)
368- self.stable_sr_pofile = self.factory.makePOFile(
369+ self.stable_pofile = self.factory.makePOFile(
370 'sr', self.stable_potemplate)
371
372- # Create a single POTMsgSet that is used across all tests,
373- # and add it to only one of the POTemplates.
374- self.potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
375- self.potmsgset.setSequence(self.devel_potemplate, 1)
376+ # The POTMsgSet is added to only one of the POTemplates.
377+ self.potmsgset = self.factory.makePOTMsgSet(
378+ self.devel_potemplate, sequence=1)
379
380 def test_findPOTMsgSetsContaining(self):
381 # Test that search works correctly.
382@@ -67,14 +230,14 @@
383 potmsgset.setSequence(self.devel_potemplate, 2)
384
385 found_potmsgsets = list(
386- self.devel_sr_pofile.findPOTMsgSetsContaining(u"wild"))
387+ self.devel_pofile.findPOTMsgSetsContaining(u"wild"))
388 self.assertEquals(found_potmsgsets, [potmsgset])
389
390 # Just linking an existing POTMsgSet into another POTemplate
391 # will make it be returned in searches.
392 potmsgset.setSequence(self.stable_potemplate, 2)
393 found_potmsgsets = list(
394- self.stable_sr_pofile.findPOTMsgSetsContaining(u"wild"))
395+ self.stable_pofile.findPOTMsgSetsContaining(u"wild"))
396 self.assertEquals(found_potmsgsets, [potmsgset])
397
398 # Searching for singular in plural messages works as well.
399@@ -84,49 +247,49 @@
400 plural_potmsgset.setSequence(self.devel_potemplate, 3)
401
402 found_potmsgsets = list(
403- self.devel_sr_pofile.findPOTMsgSetsContaining(u"singular"))
404+ self.devel_pofile.findPOTMsgSetsContaining(u"singular"))
405 self.assertEquals(found_potmsgsets, [plural_potmsgset])
406
407 # And searching for plural text returns only the matching plural
408 # message.
409 found_potmsgsets = list(
410- self.devel_sr_pofile.findPOTMsgSetsContaining(u"plural"))
411+ self.devel_pofile.findPOTMsgSetsContaining(u"plural"))
412 self.assertEquals(found_potmsgsets, [plural_potmsgset])
413
414 # Search translations as well.
415 self.factory.makeTranslationMessage(
416- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
417+ pofile=self.devel_pofile, potmsgset=potmsgset,
418 translations=[u"One translation message"])
419 found_potmsgsets = list(
420- self.devel_sr_pofile.findPOTMsgSetsContaining(u"translation"))
421+ self.devel_pofile.findPOTMsgSetsContaining(u"translation"))
422 self.assertEquals(found_potmsgsets, [potmsgset])
423
424 # Search matches all plural forms.
425 self.factory.makeTranslationMessage(
426- pofile=self.devel_sr_pofile, potmsgset=plural_potmsgset,
427+ pofile=self.devel_pofile, potmsgset=plural_potmsgset,
428 translations=[u"One translation message",
429 u"Plural translation message",
430 u"Third translation message"])
431 found_potmsgsets = list(
432- self.devel_sr_pofile.findPOTMsgSetsContaining(
433+ self.devel_pofile.findPOTMsgSetsContaining(
434 u"Plural translation"))
435 self.assertEquals(found_potmsgsets, [plural_potmsgset])
436
437 # Search works case insensitively for English strings.
438 found_potmsgsets = list(
439- self.devel_sr_pofile.findPOTMsgSetsContaining(u"WiLd"))
440+ self.devel_pofile.findPOTMsgSetsContaining(u"WiLd"))
441 self.assertEquals(found_potmsgsets, [potmsgset])
442 # ...English plural forms.
443 found_potmsgsets = list(
444- self.devel_sr_pofile.findPOTMsgSetsContaining(u"PLurAl"))
445+ self.devel_pofile.findPOTMsgSetsContaining(u"PLurAl"))
446 self.assertEquals(found_potmsgsets, [plural_potmsgset])
447 # ...translations.
448 found_potmsgsets = list(
449- self.devel_sr_pofile.findPOTMsgSetsContaining(u"tRANSlaTIon"))
450+ self.devel_pofile.findPOTMsgSetsContaining(u"tRANSlaTIon"))
451 self.assertEquals(found_potmsgsets, [potmsgset, plural_potmsgset])
452 # ...and translated plurals.
453 found_potmsgsets = list(
454- self.devel_sr_pofile.findPOTMsgSetsContaining(u"THIRD"))
455+ self.devel_pofile.findPOTMsgSetsContaining(u"THIRD"))
456 self.assertEquals(found_potmsgsets, [plural_potmsgset])
457
458 def test_getTranslationsFilteredBy(self):
459@@ -139,27 +302,27 @@
460
461 # When there are no translations, empty list is returned.
462 found_translations = list(
463- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
464+ self.devel_pofile.getTranslationsFilteredBy(submitter))
465 self.assertEquals(found_translations, [])
466
467 # If 'submitter' provides a translation, it's returned in a list.
468 translation = self.factory.makeTranslationMessage(
469- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
470+ pofile=self.devel_pofile, potmsgset=potmsgset,
471 translations=[u"Translation message"],
472 translator=submitter)
473 found_translations = list(
474- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
475+ self.devel_pofile.getTranslationsFilteredBy(submitter))
476 self.assertEquals(found_translations, [translation])
477
478 # If somebody else provides a translation, it's not added to the
479 # list of submitter's translations.
480 someone_else = self.factory.makePerson()
481 self.factory.makeTranslationMessage(
482- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
483+ pofile=self.devel_pofile, potmsgset=potmsgset,
484 translations=[u"Another translation"],
485 translator=someone_else)
486 found_translations = list(
487- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
488+ self.devel_pofile.getTranslationsFilteredBy(submitter))
489 self.assertEquals(found_translations, [translation])
490
491 # Adding a translation for same POTMsgSet, but to a different
492@@ -175,17 +338,17 @@
493 translations=[u"Yet another translation"],
494 translator=submitter)
495 found_translations = list(
496- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
497+ self.devel_pofile.getTranslationsFilteredBy(submitter))
498 self.assertEquals(found_translations, [translation])
499
500 # If a POTMsgSet is shared between two templates, a
501 # translation is listed on both.
502 potmsgset.setSequence(self.stable_potemplate, 1)
503 found_translations = list(
504- self.stable_sr_pofile.getTranslationsFilteredBy(submitter))
505+ self.stable_pofile.getTranslationsFilteredBy(submitter))
506 self.assertEquals(found_translations, [translation])
507 found_translations = list(
508- self.devel_sr_pofile.getTranslationsFilteredBy(submitter))
509+ self.devel_pofile.getTranslationsFilteredBy(submitter))
510 self.assertEquals(found_translations, [translation])
511
512 def test_getPOTMsgSetTranslated_NoShared(self):
513@@ -194,23 +357,23 @@
514
515 # When there is no diverged translation either, nothing is returned.
516 found_translations = list(
517- self.devel_sr_pofile.getPOTMsgSetTranslated())
518+ self.devel_pofile.getPOTMsgSetTranslated())
519 self.assertEquals(found_translations, [])
520
521 # When a diverged translation is added, the potmsgset is returned.
522 self.factory.makeTranslationMessage(
523- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
524+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
525 translations=[u"Translation"])
526 found_translations = list(
527- self.devel_sr_pofile.getPOTMsgSetTranslated())
528+ self.devel_pofile.getPOTMsgSetTranslated())
529 self.assertEquals(found_translations, [self.potmsgset])
530
531 # If diverged translation is empty, POTMsgSet is not listed.
532 self.factory.makeTranslationMessage(
533- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
534+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
535 translations=[u""])
536 found_translations = list(
537- self.devel_sr_pofile.getPOTMsgSetTranslated())
538+ self.devel_pofile.getPOTMsgSetTranslated())
539 self.assertEquals(found_translations, [])
540
541 def test_getPOTMsgSetTranslated_Shared(self):
542@@ -219,28 +382,28 @@
543
544 # We create a shared translation first.
545 self.factory.makeSharedTranslationMessage(
546- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
547+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
548 translations=[u"Shared translation"])
549
550 # When there is no diverged translation, shared one is returned.
551 found_translations = list(
552- self.devel_sr_pofile.getPOTMsgSetTranslated())
553+ self.devel_pofile.getPOTMsgSetTranslated())
554 self.assertEquals(found_translations, [self.potmsgset])
555
556 # When an empty diverged translation is added, nothing is listed.
557 self.factory.makeTranslationMessage(
558- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
559+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
560 translations=[u""])
561 found_translations = list(
562- self.devel_sr_pofile.getPOTMsgSetTranslated())
563+ self.devel_pofile.getPOTMsgSetTranslated())
564 self.assertEquals(found_translations, [])
565
566 # If diverged translation is non-empty, POTMsgSet is listed.
567 self.factory.makeTranslationMessage(
568- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
569+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
570 translations=[u"Translation"])
571 found_translations = list(
572- self.devel_sr_pofile.getPOTMsgSetTranslated())
573+ self.devel_pofile.getPOTMsgSetTranslated())
574 self.assertEquals(found_translations, [self.potmsgset])
575
576 def test_getPOTMsgSetTranslated_EmptyShared(self):
577@@ -249,29 +412,29 @@
578
579 # We create an empty shared translation first.
580 self.factory.makeSharedTranslationMessage(
581- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
582+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
583 translations=[u""])
584
585 # When there is no diverged translation, shared one is returned,
586 # but since it's empty, there are no results.
587 found_translations = list(
588- self.devel_sr_pofile.getPOTMsgSetTranslated())
589+ self.devel_pofile.getPOTMsgSetTranslated())
590 self.assertEquals(found_translations, [])
591
592 # When an empty diverged translation is added, nothing is listed.
593 self.factory.makeTranslationMessage(
594- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
595+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
596 translations=[u""])
597 found_translations = list(
598- self.devel_sr_pofile.getPOTMsgSetTranslated())
599+ self.devel_pofile.getPOTMsgSetTranslated())
600 self.assertEquals(found_translations, [])
601
602 # If diverged translation is non-empty, POTMsgSet is listed.
603 self.factory.makeTranslationMessage(
604- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
605+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
606 translations=[u"Translation"])
607 found_translations = list(
608- self.devel_sr_pofile.getPOTMsgSetTranslated())
609+ self.devel_pofile.getPOTMsgSetTranslated())
610 self.assertEquals(found_translations, [self.potmsgset])
611
612 def test_getPOTMsgSetTranslated_Multiple(self):
613@@ -280,7 +443,7 @@
614
615 # Add a diverged translation on the included POTMsgSet...
616 self.factory.makeTranslationMessage(
617- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
618+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
619 translations=[u"Diverged translation"])
620
621 # and a shared translation on newly added POTMsgSet...
622@@ -289,12 +452,12 @@
623 potmsgset.setSequence(self.devel_potemplate, 2)
624
625 self.factory.makeSharedTranslationMessage(
626- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
627+ pofile=self.devel_pofile, potmsgset=potmsgset,
628 translations=[u"Shared translation"])
629
630 # Both POTMsgSets are listed.
631 found_translations = list(
632- self.devel_sr_pofile.getPOTMsgSetTranslated())
633+ self.devel_pofile.getPOTMsgSetTranslated())
634 self.assertEquals(found_translations, [self.potmsgset, potmsgset])
635
636 def test_getPOTMsgSetUntranslated_NoShared(self):
637@@ -303,23 +466,23 @@
638
639 # When there is no diverged translation either, nothing is returned.
640 found_translations = list(
641- self.devel_sr_pofile.getPOTMsgSetUntranslated())
642+ self.devel_pofile.getPOTMsgSetUntranslated())
643 self.assertEquals(found_translations, [self.potmsgset])
644
645 # When a diverged translation is added, the potmsgset is returned.
646 self.factory.makeTranslationMessage(
647- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
648+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
649 translations=[u"Translation"])
650 found_translations = list(
651- self.devel_sr_pofile.getPOTMsgSetUntranslated())
652+ self.devel_pofile.getPOTMsgSetUntranslated())
653 self.assertEquals(found_translations, [])
654
655 # If diverged translation is empty, POTMsgSet is not listed.
656 self.factory.makeTranslationMessage(
657- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
658+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
659 translations=[u""])
660 found_translations = list(
661- self.devel_sr_pofile.getPOTMsgSetUntranslated())
662+ self.devel_pofile.getPOTMsgSetUntranslated())
663 self.assertEquals(found_translations, [self.potmsgset])
664
665 def test_getPOTMsgSetUntranslated_Shared(self):
666@@ -328,28 +491,28 @@
667
668 # We create a shared translation first.
669 self.factory.makeSharedTranslationMessage(
670- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
671+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
672 translations=[u"Shared translation"])
673
674 # When there is no diverged translation, shared one is returned.
675 found_translations = list(
676- self.devel_sr_pofile.getPOTMsgSetUntranslated())
677+ self.devel_pofile.getPOTMsgSetUntranslated())
678 self.assertEquals(found_translations, [])
679
680 # When an empty diverged translation is added, nothing is listed.
681 self.factory.makeTranslationMessage(
682- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
683+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
684 translations=[u""])
685 found_translations = list(
686- self.devel_sr_pofile.getPOTMsgSetUntranslated())
687+ self.devel_pofile.getPOTMsgSetUntranslated())
688 self.assertEquals(found_translations, [self.potmsgset])
689
690 # If diverged translation is non-empty, POTMsgSet is listed.
691 self.factory.makeTranslationMessage(
692- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
693+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
694 translations=[u"Translation"])
695 found_translations = list(
696- self.devel_sr_pofile.getPOTMsgSetUntranslated())
697+ self.devel_pofile.getPOTMsgSetUntranslated())
698 self.assertEquals(found_translations, [])
699
700 def test_getPOTMsgSetUntranslated_EmptyShared(self):
701@@ -358,29 +521,29 @@
702
703 # We create an empty shared translation first.
704 self.factory.makeSharedTranslationMessage(
705- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
706+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
707 translations=[u""])
708
709 # When there is no diverged translation, shared one is returned,
710 # but since it's empty, there are no results.
711 found_translations = list(
712- self.devel_sr_pofile.getPOTMsgSetUntranslated())
713+ self.devel_pofile.getPOTMsgSetUntranslated())
714 self.assertEquals(found_translations, [self.potmsgset])
715
716 # When an empty diverged translation is added, nothing is listed.
717 self.factory.makeTranslationMessage(
718- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
719+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
720 translations=[u""])
721 found_translations = list(
722- self.devel_sr_pofile.getPOTMsgSetUntranslated())
723+ self.devel_pofile.getPOTMsgSetUntranslated())
724 self.assertEquals(found_translations, [self.potmsgset])
725
726 # If diverged translation is non-empty, POTMsgSet is listed.
727 self.factory.makeTranslationMessage(
728- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
729+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
730 translations=[u"Translation"])
731 found_translations = list(
732- self.devel_sr_pofile.getPOTMsgSetUntranslated())
733+ self.devel_pofile.getPOTMsgSetUntranslated())
734 self.assertEquals(found_translations, [])
735
736 def test_getPOTMsgSetUntranslated_Multiple(self):
737@@ -389,7 +552,7 @@
738
739 # Add an empty translation to the included POTMsgSet...
740 self.factory.makeTranslationMessage(
741- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
742+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
743 translations=[u""])
744
745 # ...and a new untranslated POTMsgSet.
746@@ -399,7 +562,7 @@
747
748 # Both POTMsgSets are listed.
749 found_translations = list(
750- self.devel_sr_pofile.getPOTMsgSetUntranslated())
751+ self.devel_pofile.getPOTMsgSetUntranslated())
752 self.assertEquals(found_translations, [self.potmsgset, potmsgset])
753
754 def test_getPOTMsgSetWithNewSuggestions(self):
755@@ -407,142 +570,26 @@
756
757 # When there are no suggestions, nothing is returned.
758 found_translations = list(
759- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
760+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
761 self.assertEquals(found_translations, [])
762
763 # When a suggestion is added, the potmsgset is returned.
764- translation = self.factory.makeTranslationMessage(
765- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
766- translations=[u"Suggestion"], suggestion=True)
767- self.assertEquals(translation.is_current_ubuntu, False)
768-
769- found_translations = list(
770- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
771- self.assertEquals(found_translations, [self.potmsgset])
772-
773- def test_getPOTMsgSetWithNewSuggestions_Shared(self):
774- # Test listing of suggestions for POTMsgSets with a shared
775- # translation.
776-
777- # A POTMsgSet has a shared, current translation created 5 days ago.
778- date_created = datetime.now(pytz.UTC)-timedelta(5)
779- translation = self.factory.makeSharedTranslationMessage(
780- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
781- translations=[u"Translation"], date_updated=date_created)
782- self.assertEquals(translation.is_current_ubuntu, True)
783-
784- # When there are no suggestions, nothing is returned.
785- found_translations = list(
786- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
787- self.assertEquals(found_translations, [])
788-
789- # When a suggestion is added one day after, the potmsgset is returned.
790- suggestion_date = date_created + timedelta(1)
791- translation = self.factory.makeTranslationMessage(
792- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
793- translations=[u"Suggestion"], suggestion=True,
794- date_updated=suggestion_date)
795- self.assertEquals(translation.is_current_ubuntu, False)
796-
797- found_translations = list(
798- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
799- self.assertEquals(found_translations, [self.potmsgset])
800-
801- # Setting a suggestion as current makes it have no unreviewed
802- # suggestions.
803- translation.is_current_ubuntu = True
804- found_translations = list(
805- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
806- self.assertEquals(found_translations, [])
807-
808- # And adding another suggestion 2 days later, the potmsgset is
809- # again returned.
810- suggestion_date += timedelta(2)
811- translation = self.factory.makeTranslationMessage(
812- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
813- translations=[u"New suggestion"], suggestion=True,
814- date_updated=suggestion_date)
815- self.assertEquals(translation.is_current_ubuntu, False)
816-
817- found_translations = list(
818- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
819- self.assertEquals(found_translations, [self.potmsgset])
820-
821- def test_getPOTMsgSetWithNewSuggestions_Diverged(self):
822- # Test listing of suggestions for POTMsgSets with a shared
823- # translation and a later diverged one.
824-
825- # First we create a shared translation (5 days old), a diverged
826- # translation 1 day later.
827- # Then we make sure that getting unreviewed messages works when:
828- # * A suggestion is added 1 day after (shows as unreviewed).
829- # * A new diverged translation is added another day later (nothing).
830- # * A new suggestion is added after another day (shows).
831- # * Suggestion is made active (nothing).
832-
833- # A POTMsgSet has a shared, current translation created 5 days ago.
834- date_created = datetime.now(pytz.UTC)-timedelta(5)
835- self.factory.makeSharedTranslationMessage(
836- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
837- translations=[u"Shared translation"], date_updated=date_created)
838-
839- # And we also have a diverged translation created a day after shared
840- # current translation.
841- diverged_date = date_created + timedelta(1)
842- self.factory.makeTranslationMessage(
843- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
844- translations=[u"Old translation"], date_updated=diverged_date)
845-
846- # There is also a suggestion against the shared translation
847- # created 2 days after the shared translation.
848- suggestion_date = date_created + timedelta(2)
849- translation = self.factory.makeSharedTranslationMessage(
850- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
851- translations=[u"Shared suggestion"], suggestion=True,
852- date_updated=suggestion_date)
853- self.assertEquals(translation.is_current_ubuntu, False)
854-
855- # Shared suggestion is shown since diverged_date < suggestion_date.
856- found_translations = list(
857- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
858- self.assertEquals(found_translations, [self.potmsgset])
859-
860- # When a diverged translation is done after the shared suggestion,
861- # there are no unreviewed suggestions.
862- diverged_date = suggestion_date + timedelta(1)
863- translation = self.factory.makeTranslationMessage(
864- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
865- translations=[u"Translation"], date_updated=diverged_date)
866- found_translations = list(
867- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
868- self.assertEquals(found_translations, [])
869-
870- # When a suggestion is added one day after, the potmsgset is returned.
871- suggestion_date = diverged_date + timedelta(1)
872- translation = self.factory.makeTranslationMessage(
873- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
874- translations=[u"Suggestion"], suggestion=True,
875- date_updated=suggestion_date)
876- self.assertEquals(translation.is_current_ubuntu, False)
877-
878- found_translations = list(
879- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
880- self.assertEquals(found_translations, [self.potmsgset])
881-
882- # Setting a suggestion as current makes it have no unreviewed
883- # suggestions.
884- translation.is_current_ubuntu = True
885- found_translations = list(
886- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
887- self.assertEquals(found_translations, [])
888-
889- def test_getPOTMsgSetWithNewSuggestions_Multiple(self):
890+ translation = self.factory.makeSuggestion(
891+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
892+ translations=[u"Suggestion"])
893+ self.assertEquals(translation.is_current_ubuntu, False)
894+
895+ found_translations = list(
896+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
897+ self.assertEquals(found_translations, [self.potmsgset])
898+
899+ def test_getPOTMsgSetWithNewSuggestions_multiple(self):
900 # Test that multiple unreviewed POTMsgSets are returned.
901
902 # One POTMsgSet has no translations, but only a suggestion.
903- self.factory.makeTranslationMessage(
904- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
905- translations=[u"New suggestion"], suggestion=True)
906+ self.factory.makeSuggestion(
907+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
908+ translations=[u"New suggestion"])
909
910 # Another POTMsgSet has both a translation and a suggestion.
911 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate,
912@@ -550,52 +597,49 @@
913 potmsgset.setSequence(self.devel_potemplate, 2)
914 date_created = datetime.now(pytz.UTC) - timedelta(5)
915 self.factory.makeTranslationMessage(
916- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
917+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
918 translations=[u"Translation"], date_updated=date_created)
919 suggestion_date = date_created + timedelta(1)
920- self.factory.makeTranslationMessage(
921- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
922- translations=[u"New suggestion"], suggestion=True,
923- date_updated=suggestion_date)
924+ self.factory.makeSuggestion(
925+ pofile=self.devel_pofile, potmsgset=potmsgset,
926+ translations=[u"New suggestion"], date_created=suggestion_date)
927
928 # Both POTMsgSets are listed.
929 found_translations = list(
930- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
931+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
932 self.assertEquals(found_translations, [self.potmsgset, potmsgset])
933
934 def test_getPOTMsgSetWithNewSuggestions_distinct(self):
935 # Provide two suggestions on a single message and make sure
936 # a POTMsgSet is returned only once.
937- self.factory.makeSharedTranslationMessage(
938- pofile=self.devel_sr_pofile,
939- potmsgset=self.potmsgset,
940- translations=["A suggestion"],
941- suggestion=True)
942- self.factory.makeSharedTranslationMessage(
943- pofile=self.devel_sr_pofile,
944- potmsgset=self.potmsgset,
945- translations=["Another suggestion"],
946- suggestion=True)
947+ self.factory.makeSuggestion(
948+ pofile=self.devel_pofile,
949+ potmsgset=self.potmsgset,
950+ translations=["A suggestion"])
951+ self.factory.makeSuggestion(
952+ pofile=self.devel_pofile,
953+ potmsgset=self.potmsgset,
954+ translations=["Another suggestion"])
955
956 potmsgsets = list(
957- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
958+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
959 self.assertEquals(potmsgsets,
960 [self.potmsgset])
961 self.assertEquals(
962- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions().count(),
963+ self.devel_pofile.getPOTMsgSetWithNewSuggestions().count(),
964 1)
965
966 def test_getPOTMsgSetWithNewSuggestions_empty(self):
967 # Test listing of POTMsgSets with empty strings as suggestions.
968
969 # When an empty suggestion is added, the potmsgset is NOT returned.
970- translation = self.factory.makeTranslationMessage(
971- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
972- translations=[u""], suggestion=True)
973+ translation = self.factory.makeSuggestion(
974+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
975+ translations=[])
976 self.assertEquals(False, translation.is_current_ubuntu)
977
978 found_translations = list(
979- self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
980+ self.devel_pofile.getPOTMsgSetWithNewSuggestions())
981 self.assertEquals([], found_translations)
982
983 def test_getPOTMsgSetChangedInUbuntu(self):
984@@ -603,72 +647,72 @@
985
986 # If there are no translations in Ubuntu, nothing is listed.
987 found_translations = list(
988- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
989+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
990 self.assertEquals(found_translations, [])
991
992 # Adding a non-imported current translation doesn't change anything.
993 translation = self.factory.makeSharedTranslationMessage(
994- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
995+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
996 translations=[u"Non-imported translation"])
997 self.assertEquals(translation.is_current_upstream, False)
998 found_translations = list(
999- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1000+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1001 self.assertEquals(found_translations, [])
1002
1003 # Adding an imported translation which is also current indicates
1004 # that there are no changes.
1005 translation = self.factory.makeSharedTranslationMessage(
1006- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1007+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1008 translations=[u"Imported translation"], is_current_upstream=True)
1009 self.assertEquals(translation.is_current_upstream, True)
1010 self.assertEquals(translation.is_current_ubuntu, True)
1011 found_translations = list(
1012- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1013+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1014 self.assertEquals(found_translations, [])
1015
1016 # However, changing current translation to a non-imported one
1017 # makes this a changed in Ubuntu translation.
1018 translation = self.factory.makeSharedTranslationMessage(
1019- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1020+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1021 translations=[u"Changed translation"], is_current_upstream=False)
1022 self.assertEquals(translation.is_current_upstream, False)
1023 self.assertEquals(translation.is_current_ubuntu, True)
1024 found_translations = list(
1025- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1026+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1027 self.assertEquals(found_translations, [self.potmsgset])
1028
1029 # Adding a diverged, non-imported translation, still lists
1030 # it as a changed translation.
1031 translation = self.factory.makeTranslationMessage(
1032- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1033+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1034 translations=[u"Diverged translation"], is_current_upstream=False)
1035 self.assertEquals(translation.is_current_upstream, False)
1036 self.assertEquals(translation.is_current_ubuntu, True)
1037 found_translations = list(
1038- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1039+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1040 self.assertEquals(found_translations, [self.potmsgset])
1041
1042 # But adding a diverged current and imported translation means
1043 # that it's not changed anymore.
1044 translation = self.factory.makeTranslationMessage(
1045- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1046+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1047 translations=[u"Diverged imported"], is_current_upstream=True,
1048 force_diverged=True)
1049 self.assertEquals(translation.is_current_upstream, True)
1050 self.assertEquals(translation.is_current_ubuntu, True)
1051 found_translations = list(
1052- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1053+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1054 self.assertEquals(found_translations, [])
1055
1056 # Changing from a diverged, imported translation is correctly
1057 # detected.
1058 translation = self.factory.makeTranslationMessage(
1059- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1060+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1061 translations=[u"Diverged changed"], is_current_upstream=False)
1062 self.assertEquals(translation.is_current_upstream, False)
1063 self.assertEquals(translation.is_current_ubuntu, True)
1064 found_translations = list(
1065- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1066+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1067 self.assertEquals(found_translations, [self.potmsgset])
1068
1069 def test_getPOTMsgSetChangedInUbuntu_diverged_imported(self):
1070@@ -682,11 +726,11 @@
1071 # 1) Shared imported and current translation.
1072 # 2) Diverged, imported, non-current message.
1073 shared = self.factory.makeSharedTranslationMessage(
1074- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1075+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1076 translations=[u"Shared imported current"],
1077 is_current_upstream=True)
1078 diverged = self.factory.makeTranslationMessage(
1079- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1080+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1081 translations=[u"Diverged imported non-current"],
1082 is_current_upstream=True, force_diverged=True)
1083 # As we can't come to this situation using existing code,
1084@@ -702,7 +746,7 @@
1085
1086 # Such POTMsgSet is not considered changed in this PO file.
1087 found_translations = list(
1088- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1089+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1090 self.assertEquals(found_translations, [])
1091
1092 def test_getPOTMsgSetChangedInUbuntu_SharedDiverged(self):
1093@@ -711,34 +755,34 @@
1094 # Adding an imported translation which is also current indicates
1095 # that there are no changes.
1096 translation = self.factory.makeSharedTranslationMessage(
1097- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1098+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1099 translations=[u"Imported translation"], is_current_upstream=True)
1100 self.assertEquals(translation.is_current_upstream, True)
1101 self.assertEquals(translation.is_current_ubuntu, True)
1102 found_translations = list(
1103- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1104+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1105 self.assertEquals(found_translations, [])
1106
1107 # Adding a diverged, non-imported translation makes it appear
1108 # as changed.
1109 translation = self.factory.makeTranslationMessage(
1110- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1111+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1112 translations=[u"Changed translation"], is_current_upstream=False)
1113 self.assertEquals(translation.is_current_upstream, False)
1114 self.assertEquals(translation.is_current_ubuntu, True)
1115 found_translations = list(
1116- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1117+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1118 self.assertEquals(found_translations, [self.potmsgset])
1119
1120 def test_getPOTMsgSetWithErrors(self):
1121 # Test listing of POTMsgSets with errors in translations.
1122 translation = self.factory.makeSharedTranslationMessage(
1123- pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
1124+ pofile=self.devel_pofile, potmsgset=self.potmsgset,
1125 translations=[u"Imported translation"], is_current_upstream=True)
1126 removeSecurityProxy(translation).validation_status = (
1127 TranslationValidationStatus.UNKNOWNERROR)
1128 found_translations = list(
1129- self.devel_sr_pofile.getPOTMsgSetWithErrors())
1130+ self.devel_pofile.getPOTMsgSetWithErrors())
1131 self.assertEquals(found_translations, [self.potmsgset])
1132
1133 def test_updateStatistics(self):
1134@@ -757,72 +801,72 @@
1135 # Second POTMsgSet is untranslated, but with a suggestion.
1136 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
1137 potmsgset.setSequence(self.devel_potemplate, 2)
1138- self.factory.makeTranslationMessage(
1139- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1140- translations=[u"Unreviewed suggestion"], suggestion=True)
1141+ self.factory.makeSuggestion(
1142+ pofile=self.devel_pofile, potmsgset=potmsgset,
1143+ translations=[u"Unreviewed suggestion"])
1144
1145 # Third POTMsgSet is translated, and with a suggestion.
1146 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
1147 potmsgset.setSequence(self.devel_potemplate, 3)
1148 self.factory.makeTranslationMessage(
1149- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1150- translations=[u"Translation"], suggestion=False,
1151+ pofile=self.devel_pofile, potmsgset=potmsgset,
1152+ translations=[u"Translation"],
1153 date_updated=datetime.now(pytz.UTC)-timedelta(1))
1154- self.factory.makeTranslationMessage(
1155- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1156- translations=[u"Another suggestion"], suggestion=True)
1157+ self.factory.makeSuggestion(
1158+ pofile=self.devel_pofile, potmsgset=potmsgset,
1159+ translations=[u"Another suggestion"])
1160
1161 # Fourth POTMsgSet is translated in import.
1162 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
1163 potmsgset.setSequence(self.devel_potemplate, 4)
1164 self.factory.makeTranslationMessage(
1165- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1166+ pofile=self.devel_pofile, potmsgset=potmsgset,
1167 translations=[u"Imported translation"], is_current_upstream=True)
1168
1169 # Fifth POTMsgSet is translated in import, but changed in Ubuntu.
1170 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
1171 potmsgset.setSequence(self.devel_potemplate, 5)
1172 self.factory.makeTranslationMessage(
1173- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1174+ pofile=self.devel_pofile, potmsgset=potmsgset,
1175 translations=[u"Imported translation"], is_current_upstream=True)
1176 translation = self.factory.makeTranslationMessage(
1177- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1178+ pofile=self.devel_pofile, potmsgset=potmsgset,
1179 translations=[u"LP translation"], is_current_upstream=False)
1180
1181 # Sixth POTMsgSet is translated in LP only.
1182 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
1183 potmsgset.setSequence(self.devel_potemplate, 6)
1184 self.factory.makeTranslationMessage(
1185- pofile=self.devel_sr_pofile, potmsgset=potmsgset,
1186+ pofile=self.devel_pofile, potmsgset=potmsgset,
1187 translations=[u"New translation"], is_current_upstream=False)
1188
1189 removeSecurityProxy(self.devel_potemplate).messagecount = (
1190 self.devel_potemplate.getPOTMsgSetsCount())
1191
1192 # Returns current, updates, rosetta, unreviewed counts.
1193- stats = self.devel_sr_pofile.updateStatistics()
1194- self.assertEquals(stats, (1, 1, 3, 2))
1195+ stats = self.devel_pofile.updateStatistics()
1196+ self.assertEquals((1, 1, 3, 2), stats)
1197
1198- self.assertEquals(self.devel_sr_pofile.messageCount(), 6)
1199- self.assertEquals(self.devel_sr_pofile.translatedCount(), 4)
1200- self.assertEquals(self.devel_sr_pofile.untranslatedCount(), 2)
1201- self.assertEquals(self.devel_sr_pofile.currentCount(), 1)
1202- self.assertEquals(self.devel_sr_pofile.rosettaCount(), 3)
1203- self.assertEquals(self.devel_sr_pofile.updatesCount(), 1)
1204- self.assertEquals(self.devel_sr_pofile.unreviewedCount(), 2)
1205+ self.assertEquals(6, self.devel_pofile.messageCount())
1206+ self.assertEquals(4, self.devel_pofile.translatedCount())
1207+ self.assertEquals(2, self.devel_pofile.untranslatedCount())
1208+ self.assertEquals(1, self.devel_pofile.currentCount())
1209+ self.assertEquals(3, self.devel_pofile.rosettaCount())
1210+ self.assertEquals(1, self.devel_pofile.updatesCount())
1211+ self.assertEquals(2, self.devel_pofile.unreviewedCount())
1212
1213 def test_TranslationFileData_adapter(self):
1214 # Test that exporting works correctly with shared and diverged
1215 # messages.
1216 self.factory.makeSharedTranslationMessage(
1217- pofile=self.devel_sr_pofile,
1218+ pofile=self.devel_pofile,
1219 potmsgset=self.potmsgset,
1220 translations=["Shared translation"])
1221
1222 # Get the adapter and extract only English singular and
1223 # first translation form from all messages.
1224 translation_file_data = getAdapter(
1225- self.devel_sr_pofile, ITranslationFileData, 'all_messages')
1226+ self.devel_pofile, ITranslationFileData, 'all_messages')
1227 exported_messages = [
1228 (msg.singular_text, msg.translations[0])
1229 for msg in translation_file_data.messages]
1230@@ -832,7 +876,7 @@
1231
1232 # When we add a diverged translation, only that is exported.
1233 self.factory.makeTranslationMessage(
1234- pofile=self.devel_sr_pofile,
1235+ pofile=self.devel_pofile,
1236 potmsgset=self.potmsgset,
1237 translations=["Diverged translation"],
1238 force_diverged=True)
1239@@ -840,7 +884,7 @@
1240 # Get the adapter and extract only English singular and
1241 # first translation form from all messages.
1242 translation_file_data = getAdapter(
1243- self.devel_sr_pofile, ITranslationFileData, 'all_messages')
1244+ self.devel_pofile, ITranslationFileData, 'all_messages')
1245 exported_messages = [
1246 (msg.singular_text, msg.translations[0])
1247 for msg in translation_file_data.messages]
1248@@ -1003,9 +1047,9 @@
1249 name="messages")
1250
1251 # We'll use two PO files, one for each series.
1252- self.devel_sr_pofile = self.factory.makePOFile(
1253+ self.devel_pofile = self.factory.makePOFile(
1254 'sr', self.devel_potemplate)
1255- self.stable_sr_pofile = self.factory.makePOFile(
1256+ self.stable_pofile = self.factory.makePOFile(
1257 'sr', self.stable_potemplate)
1258
1259 # Create two POTMsgSets that can be used to test in what order
1260@@ -1016,19 +1060,19 @@
1261 self.potmsgset2.setSequence(self.devel_potemplate, 2)
1262
1263 def test_getPOTMsgSetTranslated_ordering(self):
1264- # Translate both POTMsgSets in devel_sr_pofile, so
1265+ # Translate both POTMsgSets in devel_pofile, so
1266 # they are returned with getPOTMsgSetTranslated() call.
1267 self.factory.makeSharedTranslationMessage(
1268- pofile=self.devel_sr_pofile,
1269+ pofile=self.devel_pofile,
1270 potmsgset=self.potmsgset1,
1271 translations=["Shared translation"])
1272 self.factory.makeSharedTranslationMessage(
1273- pofile=self.devel_sr_pofile,
1274+ pofile=self.devel_pofile,
1275 potmsgset=self.potmsgset2,
1276 translations=["Another shared translation"])
1277
1278 translated_potmsgsets = list(
1279- self.devel_sr_pofile.getPOTMsgSetTranslated())
1280+ self.devel_pofile.getPOTMsgSetTranslated())
1281 self.assertEquals(
1282 [self.potmsgset1, self.potmsgset2], translated_potmsgsets)
1283
1284@@ -1039,20 +1083,20 @@
1285
1286 # And they are returned in the new order as desired.
1287 translated_potmsgsets = list(
1288- self.stable_sr_pofile.getPOTMsgSetTranslated())
1289+ self.stable_pofile.getPOTMsgSetTranslated())
1290 self.assertEquals(
1291 [self.potmsgset2, self.potmsgset1], translated_potmsgsets)
1292
1293 # Order is unchanged for the previous template.
1294 translated_potmsgsets = list(
1295- self.devel_sr_pofile.getPOTMsgSetTranslated())
1296+ self.devel_pofile.getPOTMsgSetTranslated())
1297 self.assertEquals(
1298 [self.potmsgset1, self.potmsgset2], translated_potmsgsets)
1299
1300 def test_getPOTMsgSetUntranslated_ordering(self):
1301- # Both POTMsgSets in devel_sr_pofile are untranslated.
1302+ # Both POTMsgSets in devel_pofile are untranslated.
1303 untranslated_potmsgsets = list(
1304- self.devel_sr_pofile.getPOTMsgSetUntranslated())
1305+ self.devel_pofile.getPOTMsgSetUntranslated())
1306 self.assertEquals(
1307 [self.potmsgset1, self.potmsgset2], untranslated_potmsgsets)
1308
1309@@ -1063,42 +1107,42 @@
1310
1311 # And they are returned in the new order as desired.
1312 untranslated_potmsgsets = list(
1313- self.stable_sr_pofile.getPOTMsgSetUntranslated())
1314+ self.stable_pofile.getPOTMsgSetUntranslated())
1315 self.assertEquals(
1316 [self.potmsgset2, self.potmsgset1], untranslated_potmsgsets)
1317
1318 # Order is unchanged for the previous template.
1319 untranslated_potmsgsets = list(
1320- self.devel_sr_pofile.getPOTMsgSetUntranslated())
1321+ self.devel_pofile.getPOTMsgSetUntranslated())
1322 self.assertEquals(
1323 [self.potmsgset1, self.potmsgset2], untranslated_potmsgsets)
1324
1325 def test_getPOTMsgSetChangedInUbuntu_ordering(self):
1326- # Suggest a translation on both POTMsgSets in devel_sr_pofile,
1327+ # Suggest a translation on both POTMsgSets in devel_pofile,
1328 # so they are returned with getPOTMsgSetWithNewSuggestions() call.
1329 self.factory.makeSharedTranslationMessage(
1330- pofile=self.devel_sr_pofile,
1331+ pofile=self.devel_pofile,
1332 potmsgset=self.potmsgset1,
1333 translations=["Imported"],
1334 is_current_upstream=True)
1335 self.factory.makeSharedTranslationMessage(
1336- pofile=self.devel_sr_pofile,
1337+ pofile=self.devel_pofile,
1338 potmsgset=self.potmsgset1,
1339 translations=["Changed"],
1340 is_current_upstream=False)
1341 self.factory.makeSharedTranslationMessage(
1342- pofile=self.devel_sr_pofile,
1343+ pofile=self.devel_pofile,
1344 potmsgset=self.potmsgset2,
1345 translations=["Another imported"],
1346 is_current_upstream=True)
1347 self.factory.makeSharedTranslationMessage(
1348- pofile=self.devel_sr_pofile,
1349+ pofile=self.devel_pofile,
1350 potmsgset=self.potmsgset2,
1351 translations=["Another changed"],
1352 is_current_upstream=False)
1353
1354 potmsgsets = list(
1355- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1356+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1357 self.assertEquals(
1358 [self.potmsgset1, self.potmsgset2], potmsgsets)
1359
1360@@ -1109,28 +1153,28 @@
1361
1362 # And they are returned in the new order as desired.
1363 potmsgsets = list(
1364- self.stable_sr_pofile.getPOTMsgSetChangedInUbuntu())
1365+ self.stable_pofile.getPOTMsgSetChangedInUbuntu())
1366 self.assertEquals(
1367 [self.potmsgset2, self.potmsgset1], potmsgsets)
1368
1369 # Order is unchanged for the previous template.
1370 potmsgsets = list(
1371- self.devel_sr_pofile.getPOTMsgSetChangedInUbuntu())
1372+ self.devel_pofile.getPOTMsgSetChangedInUbuntu())
1373 self.assertEquals(
1374 [self.potmsgset1, self.potmsgset2], potmsgsets)
1375
1376 def test_getPOTMsgSetWithErrors_ordering(self):
1377- # Suggest a translation on both POTMsgSets in devel_sr_pofile,
1378+ # Suggest a translation on both POTMsgSets in devel_pofile,
1379 # so they are returned with getPOTMsgSetWithNewSuggestions() call.
1380 imported1 = self.factory.makeSharedTranslationMessage(
1381- pofile=self.devel_sr_pofile,
1382+ pofile=self.devel_pofile,
1383 potmsgset=self.potmsgset1,
1384 translations=["Imported"],
1385 is_current_upstream=True)
1386 removeSecurityProxy(imported1).validation_status = (
1387 TranslationValidationStatus.UNKNOWNERROR)
1388 imported2 = self.factory.makeSharedTranslationMessage(
1389- pofile=self.devel_sr_pofile,
1390+ pofile=self.devel_pofile,
1391 potmsgset=self.potmsgset2,
1392 translations=["Another imported"],
1393 is_current_upstream=True)
1394@@ -1138,7 +1182,7 @@
1395 TranslationValidationStatus.UNKNOWNERROR)
1396
1397 potmsgsets = list(
1398- self.devel_sr_pofile.getPOTMsgSetWithErrors())
1399+ self.devel_pofile.getPOTMsgSetWithErrors())
1400 self.assertEquals(
1401 [self.potmsgset1, self.potmsgset2], potmsgsets)
1402
1403@@ -1149,13 +1193,13 @@
1404
1405 # And they are returned in the new order as desired.
1406 potmsgsets = list(
1407- self.stable_sr_pofile.getPOTMsgSetWithErrors())
1408+ self.stable_pofile.getPOTMsgSetWithErrors())
1409 self.assertEquals(
1410 [self.potmsgset2, self.potmsgset1], potmsgsets)
1411
1412 # Order is unchanged for the previous template.
1413 potmsgsets = list(
1414- self.devel_sr_pofile.getPOTMsgSetWithErrors())
1415+ self.devel_pofile.getPOTMsgSetWithErrors())
1416 self.assertEquals(
1417 [self.potmsgset1, self.potmsgset2], potmsgsets)
1418
1419@@ -1190,11 +1234,11 @@
1420
1421 # Give the method something to search for.
1422 self.factory.makeSharedTranslationMessage(
1423- pofile=self.devel_sr_pofile,
1424+ pofile=self.devel_pofile,
1425 potmsgset=self.potmsgset1,
1426 translations=["Shared translation"])
1427 self.factory.makeSharedTranslationMessage(
1428- pofile=self.devel_sr_pofile,
1429+ pofile=self.devel_pofile,
1430 potmsgset=self.potmsgset2,
1431 translations=["Another shared translation"])
1432
1433@@ -1203,7 +1247,7 @@
1434 removeSecurityProxy(self.potmsgset2).sequence = 1
1435
1436 potmsgsets = list(
1437- self.devel_sr_pofile.findPOTMsgSetsContaining("translation"))
1438+ self.devel_pofile.findPOTMsgSetsContaining("translation"))
1439
1440 # Order ignores potmsgset.sequence.
1441 self.assertEquals(
1442@@ -1627,11 +1671,10 @@
1443 # Adding a suggestion (i.e. unused translation)
1444 # will not change the current count when there's
1445 # already an imported message.
1446- self.factory.makeTranslationMessage(
1447+ self.factory.makeSuggestion(
1448 pofile=self.pofile,
1449 potmsgset=self.potmsgset,
1450- translations=["A suggestion"],
1451- suggestion=True)
1452+ translations=["A suggestion"])
1453 self.pofile.updateStatistics()
1454 self.assertEquals(self.pofile.currentCount(), 1)
1455
1456
1457=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
1458--- lib/lp/translations/tests/test_potmsgset.py 2010-08-13 05:02:57 +0000
1459+++ lib/lp/translations/tests/test_potmsgset.py 2010-08-17 09:48:55 +0000
1460@@ -273,56 +273,54 @@
1461 serbian = sr_pofile.language
1462
1463 # When there are no suggestions, empty list is returned.
1464- self.assertEquals(
1465- set(self.potmsgset.getLocalTranslationMessages(
1466- self.devel_potemplate, serbian)),
1467- set([]))
1468+ self.assertContentEqual(
1469+ [],
1470+ self.potmsgset.getLocalTranslationMessages(
1471+ self.devel_potemplate, serbian))
1472
1473 # A shared suggestion is shown in both templates.
1474- shared_suggestion = self.factory.makeSharedTranslationMessage(
1475- pofile=sr_pofile, potmsgset=self.potmsgset, suggestion=True)
1476- self.assertEquals(
1477- set(self.potmsgset.getLocalTranslationMessages(
1478- self.devel_potemplate, serbian)),
1479- set([shared_suggestion]))
1480- self.assertEquals(
1481- set(self.potmsgset.getLocalTranslationMessages(
1482- self.stable_potemplate, serbian)),
1483- set([shared_suggestion]))
1484+ shared_suggestion = self.factory.makeSuggestion(
1485+ pofile=sr_pofile, potmsgset=self.potmsgset)
1486+ self.assertContentEqual(
1487+ [shared_suggestion],
1488+ self.potmsgset.getLocalTranslationMessages(
1489+ self.devel_potemplate, serbian))
1490+ self.assertContentEqual(
1491+ [shared_suggestion],
1492+ self.potmsgset.getLocalTranslationMessages(
1493+ self.stable_potemplate, serbian))
1494
1495 # A suggestion on another PO file is still shown in both templates.
1496- another_suggestion = self.factory.makeSharedTranslationMessage(
1497- pofile=sr_stable_pofile, potmsgset=self.potmsgset,
1498- suggestion=True)
1499- self.assertEquals(
1500- set(self.potmsgset.getLocalTranslationMessages(
1501- self.devel_potemplate, serbian)),
1502- set([shared_suggestion, another_suggestion]))
1503- self.assertEquals(
1504- set(self.potmsgset.getLocalTranslationMessages(
1505- self.stable_potemplate, serbian)),
1506- set([shared_suggestion, another_suggestion]))
1507+ another_suggestion = self.factory.makeSuggestion(
1508+ pofile=sr_stable_pofile, potmsgset=self.potmsgset)
1509+ self.assertContentEqual(
1510+ [shared_suggestion, another_suggestion],
1511+ self.potmsgset.getLocalTranslationMessages(
1512+ self.devel_potemplate, serbian))
1513+ self.assertContentEqual(
1514+ [shared_suggestion, another_suggestion],
1515+ self.potmsgset.getLocalTranslationMessages(
1516+ self.stable_potemplate, serbian))
1517
1518 # Setting one of the suggestions as current will leave
1519 # them both 'reviewed' and thus hidden.
1520 current_translation = self.factory.makeSharedTranslationMessage(
1521- pofile=sr_pofile, potmsgset=self.potmsgset, suggestion=False)
1522- self.assertEquals(
1523- set(self.potmsgset.getLocalTranslationMessages(
1524- self.devel_potemplate, serbian)),
1525- set([]))
1526+ pofile=sr_pofile, potmsgset=self.potmsgset)
1527+ self.assertContentEqual(
1528+ [],
1529+ self.potmsgset.getLocalTranslationMessages(
1530+ self.devel_potemplate, serbian))
1531
1532 def test_getLocalTranslationMessages_empty_message(self):
1533 # An empty suggestion is never returned.
1534 self.potmsgset.setSequence(self.stable_potemplate, 1)
1535 pofile = self.factory.makePOFile('sr', self.stable_potemplate)
1536- empty_suggestion = self.factory.makeSharedTranslationMessage(
1537- pofile=pofile, potmsgset=self.potmsgset, suggestion=True,
1538- translations=[""])
1539- self.assertEquals(
1540- set([]),
1541- set(self.potmsgset.getLocalTranslationMessages(
1542- self.stable_potemplate, pofile.language)))
1543+ empty_suggestion = self.factory.makeSuggestion(
1544+ pofile=pofile, potmsgset=self.potmsgset, translations=[None])
1545+ self.assertContentEqual(
1546+ [],
1547+ self.potmsgset.getLocalTranslationMessages(
1548+ self.stable_potemplate, pofile.language))
1549
1550 def test_getExternallyUsedTranslationMessages(self):
1551 """Test retrieval of externally used translations."""
1552@@ -349,9 +347,8 @@
1553
1554 # If there are only suggestions on the external POTMsgSet,
1555 # no externally used suggestions are returned.
1556- external_suggestion = self.factory.makeSharedTranslationMessage(
1557- pofile=external_pofile, potmsgset=external_potmsgset,
1558- suggestion=True)
1559+ external_suggestion = self.factory.makeSuggestion(
1560+ pofile=external_pofile, potmsgset=external_potmsgset)
1561
1562 transaction.commit()
1563
1564@@ -363,7 +360,7 @@
1565 # it is returned as the externally used suggestion.
1566 imported_translation = self.factory.makeSharedTranslationMessage(
1567 pofile=external_pofile, potmsgset=external_potmsgset,
1568- suggestion=False, is_current_upstream=True)
1569+ is_current_upstream=True)
1570 imported_translation.makeCurrentUbuntu(False)
1571
1572 transaction.commit()
1573@@ -376,7 +373,7 @@
1574 # it is returned as the externally used suggestion as well.
1575 current_translation = self.factory.makeSharedTranslationMessage(
1576 pofile=external_pofile, potmsgset=external_potmsgset,
1577- suggestion=False, is_current_upstream=False)
1578+ is_current_upstream=False)
1579
1580 transaction.commit()
1581
1582@@ -409,9 +406,8 @@
1583
1584 # If there is a suggestion on the external POTMsgSet,
1585 # it is returned.
1586- external_suggestion = self.factory.makeSharedTranslationMessage(
1587- pofile=external_pofile, potmsgset=external_potmsgset,
1588- suggestion=True)
1589+ external_suggestion = self.factory.makeSuggestion(
1590+ pofile=external_pofile, potmsgset=external_potmsgset)
1591
1592 transaction.commit()
1593
1594@@ -423,7 +419,7 @@
1595 # POTMsgSet, it is not returned as the external suggestion.
1596 imported_translation = self.factory.makeSharedTranslationMessage(
1597 pofile=external_pofile, potmsgset=external_potmsgset,
1598- suggestion=False, is_current_upstream=True)
1599+ is_current_upstream=True)
1600 imported_translation.makeCurrentUbuntu(False)
1601
1602 transaction.commit()
1603@@ -436,7 +432,7 @@
1604 # considered an external suggestion.
1605 current_translation = self.factory.makeSharedTranslationMessage(
1606 pofile=external_pofile, potmsgset=external_potmsgset,
1607- suggestion=False, is_current_upstream=False)
1608+ is_current_upstream=False)
1609
1610 transaction.commit()
1611
1612@@ -769,13 +765,12 @@
1613 removeSecurityProxy(self.pofile), self.potmsgset,
1614 translations=[u'trans1'], reviewer=self.factory.makePerson(),
1615 is_current_upstream=True, date_updated=self.now())
1616- self.suggestion1 = self.factory.makeTranslationMessage(
1617- self.pofile, self.potmsgset, suggestion=True,
1618- translations=[u'sugg1'], reviewer=self.factory.makePerson(),
1619- date_updated=self.now())
1620- self.suggestion2 = self.factory.makeTranslationMessage(
1621- self.pofile, self.potmsgset, suggestion=True,
1622- translations=[u'sugg2'], date_updated=self.now())
1623+ self.suggestion1 = self.factory.makeSuggestion(
1624+ self.pofile, self.potmsgset, translations=[u'sugg1'],
1625+ date_created=self.now())
1626+ self.suggestion2 = self.factory.makeSuggestion(
1627+ self.pofile, self.potmsgset, translations=[u'sugg2'],
1628+ date_created=self.now())
1629 self._setDateCreated(self.suggestion2)
1630
1631 def test_dismiss_all(self):
1632
1633=== modified file 'lib/lp/translations/tests/test_translatablemessage.py'
1634--- lib/lp/translations/tests/test_translatablemessage.py 2010-03-24 13:56:15 +0000
1635+++ lib/lp/translations/tests/test_translatablemessage.py 2010-08-17 09:48:55 +0000
1636@@ -44,13 +44,17 @@
1637 is_current_ubuntu or is_current_upstream or is_diverged)
1638 if translation is not None:
1639 translation = [translation]
1640- return self.factory.makeTranslationMessage(
1641- pofile=self.pofile, potmsgset=self.potmsgset,
1642- translations=translation,
1643- suggestion=is_suggestion,
1644- is_current_upstream=is_current_upstream,
1645- force_diverged=is_diverged,
1646- date_updated=date_updated)
1647+ if is_suggestion:
1648+ return self.factory.makeSuggestion(
1649+ pofile=self.pofile, potmsgset=self.potmsgset,
1650+ translations=translation, date_created=date_updated)
1651+ else:
1652+ return self.factory.makeTranslationMessage(
1653+ pofile=self.pofile, potmsgset=self.potmsgset,
1654+ translations=translation,
1655+ is_current_upstream=is_current_upstream,
1656+ force_diverged=is_diverged,
1657+ date_updated=date_updated)
1658
1659
1660 class TestTranslatableMessage(TestTranslatableMessageBase):
1661@@ -172,24 +176,24 @@
1662 super(TestTranslatableMessageSuggestions, self).setUp()
1663 self.now = self.gen_now().next
1664 self.suggestion1 = self._createTranslation(date_updated=self.now())
1665- self.current = self._createTranslation(is_current_ubuntu=True,
1666- date_updated=self.now())
1667+ self.current = self._createTranslation(
1668+ is_current_ubuntu=True, date_updated=self.now())
1669 self.suggestion2 = self._createTranslation(date_updated=self.now())
1670 self.message = TranslatableMessage(self.potmsgset, self.pofile)
1671
1672 def test_getAllSuggestions(self):
1673- # There are three different methods to return
1674+ # There are three different methods to return.
1675 suggestions = self.message.getAllSuggestions()
1676 self.assertContentEqual([self.suggestion1, self.suggestion2],
1677 suggestions)
1678
1679 def test_getDismissedSuggestions(self):
1680- # There are three different methods to return
1681+ # There are three different methods to return.
1682 suggestions = self.message.getDismissedSuggestions()
1683 self.assertContentEqual([self.suggestion1], suggestions)
1684
1685 def test_getUnreviewedSuggestions(self):
1686- # There are three different methods to return
1687+ # There are three different methods to return.
1688 suggestions = self.message.getUnreviewedSuggestions()
1689 self.assertContentEqual([self.suggestion2], suggestions)
1690
1691
1692=== modified file 'lib/lp/translations/tests/test_translations_to_review.py'
1693--- lib/lp/translations/tests/test_translations_to_review.py 2010-05-07 12:29:23 +0000
1694+++ lib/lp/translations/tests/test_translations_to_review.py 2010-08-17 09:48:55 +0000
1695@@ -26,6 +26,7 @@
1696
1697 class ReviewTestMixin:
1698 """Base for testing which translations a reviewer can review."""
1699+
1700 def setUpMixin(self, for_product=True):
1701 """Set up test environment.
1702
1703@@ -82,10 +83,10 @@
1704
1705 later_time = self.base_time + timedelta(0, 3600)
1706 self.suggestion = removeSecurityProxy(
1707- self.factory.makeTranslationMessage(
1708+ self.factory.makeSuggestion(
1709 potmsgset=self.potmsgset, pofile=self.pofile,
1710 translator=self.factory.makePerson(), translations=['wi'],
1711- date_updated=later_time, suggestion=True))
1712+ date_created=later_time))
1713
1714 self.assertTrue(self.translation.is_current_ubuntu)
1715 self.pofile.updateStatistics()
1716@@ -109,6 +110,7 @@
1717
1718 Can be applied to product or distribution setups.
1719 """
1720+
1721 def test_OneFileToReview(self):
1722 # In the base case, the method finds one POFile for self.person
1723 # to review.
1724
1725=== modified file 'lib/lp/translations/utilities/sanitize.py'
1726--- lib/lp/translations/utilities/sanitize.py 2010-03-26 20:14:32 +0000
1727+++ lib/lp/translations/utilities/sanitize.py 2010-08-17 09:48:55 +0000
1728@@ -51,8 +51,7 @@
1729 """Find out which newline style is used in text."""
1730 error_message = (
1731 "%s text (%r) mixes different newline markers." % (
1732- text_name, text)
1733- )
1734+ text_name, text))
1735 style = None
1736 # To avoid confusing the single-character newline styles for mac and
1737 # unix with the two-character windows one, remove the windows-style
1738@@ -169,6 +168,9 @@
1739 :param pluralforms: The number of expected pluralforms
1740 """
1741 # Sanitize all given translations.
1742+ # Make sure the translations are stored in a dict.
1743+ if isinstance(translations, (list, tuple)):
1744+ translations = dict(enumerate(translations))
1745 # Unneeded plural forms are stored as well (needed since we may
1746 # have incorrect plural form data, so we can just reactivate them
1747 # once we fix the plural information for the language)
1748@@ -188,4 +190,3 @@
1749 # There will be a different function for translation coming from imports but
1750 # for now it is identical to the one used in browser code.
1751 sanitize_translations_from_import = sanitize_translations_from_webui
1752-
1753
1754=== modified file 'lib/lp/translations/utilities/tests/test_sanitize.py'
1755--- lib/lp/translations/utilities/tests/test_sanitize.py 2010-03-26 19:37:58 +0000
1756+++ lib/lp/translations/utilities/tests/test_sanitize.py 2010-08-17 09:48:55 +0000
1757@@ -203,8 +203,23 @@
1758 }
1759 self.assertEqual(
1760 expected_sanitized,
1761- sanitize_translations_from_webui(self.english, translations, 3)
1762- )
1763+ sanitize_translations_from_webui(self.english, translations, 3))
1764+
1765+ def test_sanitize_translations_not_in_dict(self):
1766+ # A list is converted to a dictionary.
1767+ translations = [
1768+ u'Pluralform 0',
1769+ u'Pluralform 1',
1770+ u'Pluralform 2',
1771+ ]
1772+ expected_sanitized = {
1773+ 0: u'Pluralform 0',
1774+ 1: u'Pluralform 1',
1775+ 2: u'Pluralform 2',
1776+ }
1777+ self.assertEqual(
1778+ expected_sanitized,
1779+ sanitize_translations_from_webui(self.english, translations, 3))
1780
1781 def test_sanitize_translations_missing_pluralform(self):
1782 # Missing plural forms are normalized to None.
1783@@ -219,8 +234,7 @@
1784 }
1785 self.assertEqual(
1786 expected_sanitized,
1787- sanitize_translations_from_webui(self.english, translations, 3)
1788- )
1789+ sanitize_translations_from_webui(self.english, translations, 3))
1790
1791 def test_sanitize_translations_excess_pluralform(self):
1792 # Excess plural forms are sanitized, too.
1793@@ -238,8 +252,7 @@
1794 }
1795 self.assertEqual(
1796 expected_sanitized,
1797- sanitize_translations_from_webui(self.english, translations, 3)
1798- )
1799+ sanitize_translations_from_webui(self.english, translations, 3))
1800
1801
1802 def test_suite():
1803
1804=== modified file 'lib/lp/translations/utilities/tests/test_superfastimports.py'
1805--- lib/lp/translations/utilities/tests/test_superfastimports.py 2010-03-23 21:07:11 +0000
1806+++ lib/lp/translations/utilities/tests/test_superfastimports.py 2010-08-17 09:48:55 +0000
1807@@ -13,6 +13,7 @@
1808 from lp.translations.utilities.translation_common_format import (
1809 TranslationMessageData)
1810
1811+
1812 class TestSuperFastImports(TestCaseWithFactory):
1813 """Test how ExistingPOFileInDatabase cache works."""
1814
1815@@ -66,8 +67,7 @@
1816 def test_inactive_messages(self):
1817 # Make sure non-current messages (i.e. suggestions) are
1818 # not cached in ExistingPOFileInDatabase.
1819- inactive_message = self.factory.makeTranslationMessage(
1820- pofile=self.pofile, suggestion=True)
1821+ inactive_message = self.factory.makeSuggestion(pofile=self.pofile)
1822 cached_file = ExistingPOFileInDatabase(self.pofile)
1823 message_data = self.getTranslationMessageData(inactive_message)
1824 self.assertFalse(
1825
1826=== modified file 'lib/lp/translations/windmill/tests/test_pofile_translate.py'
1827--- lib/lp/translations/windmill/tests/test_pofile_translate.py 2010-05-24 16:20:27 +0000
1828+++ lib/lp/translations/windmill/tests/test_pofile_translate.py 2010-08-17 09:48:55 +0000
1829@@ -7,6 +7,7 @@
1830 __all__ = []
1831
1832 import transaction
1833+from zope.security.proxy import removeSecurityProxy
1834
1835 from canonical.launchpad.windmill.testing import constants, lpuser
1836 from lp.translations.windmill.testing import TranslationsWindmillLayer
1837@@ -151,9 +152,11 @@
1838 current_translation = self.factory.makeTranslationMessage(
1839 pofile=pofile, potmsgset=potmsgset, translations=['current'])
1840 transaction.commit()
1841- suggestion = self.factory.makeTranslationMessage(
1842- pofile=pofile, potmsgset=potmsgset,
1843- translations=['suggestion'], suggestion=True)
1844+ suggestion = self.factory.makeSuggestion(
1845+ pofile=pofile, potmsgset=potmsgset, translations=['suggestion'])
1846+ # XXX henninge 2010-08-13 bug=597539: The view code depends on the
1847+ # pofile attribute being set.
1848+ removeSecurityProxy(suggestion).pofile = pofile
1849 transaction.commit()
1850 logout()
1851
1852@@ -484,4 +487,3 @@
1853 reviewer and current_is_reviewer or
1854 translator and not current_is_reviewer)
1855 assert switch_done is True, "Could not switch working mode."
1856-

Subscribers

People subscribed via source and target branches