launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #02390
[Merge] lp:~adeuring/launchpad/translation-fixing2 into lp:launchpad
Abel Deuring has proposed merging lp:~adeuring/launchpad/translation-fixing2 into lp:launchpad with lp:~abentley/launchpad/translation-fixing as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~adeuring/launchpad/translation-fixing2/+merge/46976
This branch removes tests of the deprecated method POTMsgSet.updateTranslations() and it replaces calls of this method in some tests by calls of makeCurrentTranslation()
tests:
bin/test -t potmsgset.txt -t test_pofile -t test_potmsgset -t import-flags.txt
no lint
--
https://code.launchpad.net/~adeuring/launchpad/translation-fixing2/+merge/46976
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~adeuring/launchpad/translation-fixing2 into lp:launchpad.
=== modified file 'lib/lp/translations/doc/potmsgset.txt'
--- lib/lp/translations/doc/potmsgset.txt 2010-12-14 16:57:36 +0000
+++ lib/lp/translations/doc/potmsgset.txt 2011-01-20 21:20:32 +0000
@@ -211,248 +211,6 @@
u'\nTranslation\nto test\n'
-POTMsgSet.updateTranslation
----------------------------
-
-This method is the core piece of Translations infrastructure: it
-updates a single language translation for a POTMsgSet, and modifies a
-lot of metadata depending on many different conditions. It is used
-from both web UI and from import code.
-
-We are going to work with Evolution.
-
- >>> evolution = getUtility(IProductSet).getByName('evolution')
- >>> evolution_trunk = evolution.getSeries('trunk')
- >>> evolution_potemplate = evolution_trunk.getPOTemplate('evolution-2.2')
-
-Carlos is a privileged translator that will do the updates.
-
- >>> carlos = getUtility(IPersonSet).getByName('carlos')
- >>> login('carlos@xxxxxxxxxxxxx')
-
-We will be working with Catalan (ca) translations, with the new PO file.
-
- >>> upstream_pofile = evolution_potemplate.newPOFile('ca')
- >>> catalan = upstream_pofile.language
-
-And, any changes we'd do will be in 'evolution addressbook' message.
-
- >>> upstream_potmsgset = evolution_potemplate.getPOTMsgSetByMsgIDText(
- ... u'evolution addressbook')
-
-At this time, there is no current or imported translation and no suggestions.
-
- >>> print upstream_potmsgset.getCurrentTranslationMessage(
- ... evolution_potemplate, catalan)
- None
- >>> print upstream_potmsgset.getOtherTranslation(
- ... catalan, evolution_potemplate.translation_side)
- None
- >>> list(upstream_potmsgset.getLocalTranslationMessages(
- ... evolution_potemplate, catalan))
- []
-
-To add a suggestion, we set the force_suggestion parameter.
-
- >>> new_translation = upstream_potmsgset.updateTranslation(
- ... upstream_pofile, carlos, {0: u'foo'}, is_current_upstream=False,
- ... force_suggestion=True, lock_timestamp=datetime.now(pytz.UTC))
-
-Since this message is just a suggestion, it doesn't have a reviewer, but
-it does note a person which last changed it.
-
- >>> print new_translation.reviewer
- None
- >>> print new_translation.date_reviewed
- None
- >>> new_translation.submitter.displayname
- u'Carlos Perell\xf3 Mar\xedn'
- >>> new_translation.date_created is None
- False
-
-Since this is a suggestion, it is not counted as a translation.
-The updateStatistics method returns four values:
- - The number of translations 'imported' that are being used.
- - The number of translations 'imported' that were updated in Launchpad.
- - The number of new translations added in Launchpad.
- - The number of messages that have suggestions to be reviewed.
-
- >>> upstream_pofile.updateStatistics()
- (0, 0, 0, 1)
-
-We are adding a translation from the import.
-
- >>> upstream_potmsgset = evolution_potemplate.getPOTMsgSetByMsgIDText(
- ... u'%d contact', u'%d contacts')
-
-At this time, there is no current or imported translation and no suggestions.
-
- >>> print upstream_potmsgset.getCurrentTranslationMessage(
- ... evolution_potemplate, catalan)
- None
- >>> print upstream_potmsgset.getOtherTranslation(
- ... catalan, evolution_potemplate.translation_side)
- None
- >>> list(upstream_potmsgset.getLocalTranslationMessages(
- ... evolution_potemplate, catalan))
- []
-
-To add an imported translation, we need to set is_current_upstream parameter.
-
- >>> new_translation = upstream_potmsgset.updateTranslation(
- ... upstream_pofile, carlos, {0: u'foo %d', 1: u'foos %d'},
- ... is_current_upstream=True, lock_timestamp=datetime.now(pytz.UTC))
-
-The new translation is reflected in the POFile statistics.
-
- >>> upstream_pofile.updateStatistics()
- (1, 0, 0, 1)
-
-Since this message came from the import, it doesn't have a reviewer, but
-it does note a person which last changed it.
-
- >>> current = upstream_potmsgset.getCurrentTranslationMessage(
- ... evolution_potemplate, catalan)
- >>> print current.reviewer
- None
- >>> print current.date_reviewed
- None
- >>> current.submitter.displayname
- u'Carlos Perell\xf3 Mar\xedn'
- >>> current.date_created is None
- False
-
-Unsetting a translation from the import
-.......................................
-
-A translation can be removed from the import by being set to an empty string.
-
- >>> upstream_potmsgset = evolution_potemplate.getPOTMsgSetByMsgIDText(
- ... u'have ')
- >>> new_translation = upstream_potmsgset.updateTranslation(
- ... upstream_pofile, carlos, {0: u''},
- ... is_current_upstream=True, lock_timestamp=datetime.now(pytz.UTC))
-
-Current translation is now unset, as is imported.
-
- >>> current = upstream_potmsgset.getCurrentTranslationMessage(
- ... evolution_potemplate, catalan)
- >>> print current
- None
- >>> imported = upstream_potmsgset.getOtherTranslation(
- ... catalan, evolution_potemplate.translation_side)
- >>> print imported
- None
-
-Given that we unset an imported translation, statistics remain unchanged.
-
- >>> upstream_pofile.updateStatistics()
- (1, 0, 0, 1)
-
-To unset an imported plural translation, we can add an empty translation.
-
- >>> upstream_potmsgset = evolution_potemplate.getPOTMsgSetByMsgIDText(
- ... u'%d contact', u'%d contacts')
- >>> new_translation = upstream_potmsgset.updateTranslation(
- ... upstream_pofile, carlos, {0: u'', 1: u''},
- ... is_current_upstream=True, lock_timestamp=datetime.now(pytz.UTC))
-
-The statistics change to reflect that the message is not available
-in upstream anymore, so it's now noted as newly translated in Launchpad.
-
- >>> upstream_pofile.updateStatistics()
- (0, 0, 0, 2)
-
-Activating an existing suggestion
-.................................
-
-Foo Bar is a privileged translator who can do reviews and submit translations
-directly, while No Privileges user can only submit suggestions.
-
- >>> foobar = getUtility(IPersonSet).getByName('name16')
- >>> no_priv = getUtility(IPersonSet).getByName('no-priv')
-
-We'll be working with Spanish PO file for Evolution, again handling
-'evolution addressbook' message.
-
- >>> pofile_es = evolution_potemplate.getPOFileByLang('es')
- >>> spanish = pofile_es.language
- >>> potmsgset = evolution_potemplate.getPOTMsgSetByMsgIDText(
- ... u'evolution addressbook')
-
-At the moment, there are no suggestions for this message.
-
- >>> suggested = potmsgset.getLocalTranslationMessages(
- ... evolution_potemplate, spanish)
- >>> len(list(suggested))
- 0
-
-A No Privileges user updates a translation.
-
- >>> new_message = potmsgset.updateTranslation(
- ... pofile_es, no_priv, {0: u'test string'},
- ... is_current_upstream=False, lock_timestamp=datetime.now(pytz.UTC))
-
-This message is not made current or marked as imported.
-
- >>> new_message.is_current_ubuntu
- False
- >>> new_message.is_current_upstream
- False
-
-Now, we should have one extra suggestion.
-
- >>> suggested = potmsgset.getLocalTranslationMessages(
- ... evolution_potemplate, spanish)
- >>> len(list(suggested))
- 1
-
-That is the one that no_priv submitted.
-
- >>> suggested[0].translations
- [u'test string']
-
-And the active translation is not the one we suggested.
-
- >>> current = potmsgset.getCurrentTranslationMessage(
- ... evolution_potemplate, spanish)
- >>> current.translations
- [u'libreta de direcciones de Evolution']
-
-And the reviewer for that message was Carlos:
-
- >>> current.reviewer.name
- u'carlos'
-
-Now, Foo Bar, a translator with permissions, is going to approve that
-new suggestion.
-
- >>> new_message = potmsgset.updateTranslation(
- ... pofile_es, foobar, {0: u'test string'},
- ... is_current_upstream=False, lock_timestamp=datetime.now(pytz.UTC))
-
-We don't have any suggestion newer than the new active translation
-
- >>> suggested = potmsgset.getLocalTranslationMessages(
- ... evolution_potemplate, spanish)
- >>> len(list(suggested))
- 0
-
-And the active translation is now the one from no-priv user.
-
- >>> current = potmsgset.getCurrentTranslationMessage(
- ... evolution_potemplate, spanish)
- >>> current.submitter.name
- u'no-priv'
- >>> current.translations
- [u'test string']
-
-Also, we should have Foo Bar as the reviewer of that translation.
-
- >>> current.reviewer.displayname
- u'Foo Bar'
-
-
Plural forms
------------
@@ -461,6 +219,9 @@
An empty translation does not need to exist in the database. If not,
a DummyPOFile is used instead.
+ >>> evolution = getUtility(IProductSet).getByName('evolution')
+ >>> evolution_trunk = evolution.getSeries('trunk')
+ >>> evolution_potemplate = evolution_trunk.getPOTemplate('evolution-2.2')
>>> language_pt_BR = getUtility(
... ILanguageSet).getLanguageByCode('pt_BR')
>>> pt_BR_dummypofile = evolution_potemplate.getDummyPOFile(
@@ -538,10 +299,12 @@
We call such a message incomplete, and undesirable as it is, it is still
gracefully accepted.
+ >>> pofile_es = evolution_potemplate.getPOFileByLang('es')
>>> plural_potmsgset = pofile_es.potemplate.getPOTMsgSetByMsgIDText(
... u'%d contact', u'%d contacts')
>>> pofile_es.plural_forms
2
+ >>> foobar = getUtility(IPersonSet).getByName('name16')
>>> message = factory.makeCurrentTranslationMessage(
... pofile_es, plural_potmsgset, foobar,
... translations={0: u'foo %d', 1: None})
@@ -598,6 +361,10 @@
plural forms. This time, uploading a three-form translation produces a
new translation message.
+Carlos is a privileged translator that will do the updates.
+
+ >>> carlos = getUtility(IPersonSet).getByName('carlos')
+ >>> login('carlos@xxxxxxxxxxxxx')
>>> zap.pluralforms = 3
>>> zap.pluralexpression = 'n % 3'
@@ -732,6 +499,7 @@
We have the same message in both templates but with different
translations in Spanish:
+ >>> spanish = pofile_es.language
>>> evo_product_message = evo_product_template.getPOTMsgSetByMsgIDText(
... ' cards')
>>> evo_product_translation = (
=== removed file 'lib/lp/translations/tests/potmsgset-update-translation.txt'
--- lib/lp/translations/tests/potmsgset-update-translation.txt 2010-12-16 13:25:54 +0000
+++ lib/lp/translations/tests/potmsgset-update-translation.txt 1970-01-01 00:00:00 +0000
@@ -1,162 +0,0 @@
- >>> import datetime
- >>> import pytz
- >>> from zope.component import getUtility
- >>> from canonical.database.sqlbase import flush_database_updates
- >>> from lp.registry.interfaces.person import IPersonSet
- >>> from lp.translations.model.pomsgid import POMsgID
- >>> from lp.translations.model.potemplate import POTemplate
- >>> UTC = pytz.timezone('UTC')
-
-Get the PO msgid we will be working with.
-
- >>> pomsgid = POMsgID.byMsgid('evolution addressbook')
-
-Carlos is the one that will do the uploads.
-
- >>> carlos = getUtility(IPersonSet).getByName('carlos')
-
-Now find the po template.
-
- >>> upstream_evo = POTemplate.get(1)
- >>> upstream_evo.productseries is not None
- True
-
- >>> upstream_evo.productseries.product.name
- u'evolution'
-
-And the Spanish translation.
-
- >>> pofile_es = upstream_evo.getPOFileByLang('es')
-
-This method will only overwrite translations in Launchpad with upstream
-ones if the previous upstream translation matches the translation used
-in Launchpad or there is no complete translation.
-
- >>> potmsgset = pofile_es.potemplate.getPOTMsgSetByMsgIDText(
- ... u'EncFS Password: ')
-
-We can see that this is actually the case:
-
- >>> from lp.services.worlddata.model.language import LanguageSet
- >>> spanish = LanguageSet().getLanguageByCode('es')
- >>> message = potmsgset.getCurrentTranslationMessage(
- ... upstream_evo, spanish)
- >>> message.msgstr0.translation
- u'Contrase\xf1a de EncFS: '
-
- >>> message.is_complete
- True
-
- >>> message.is_current_upstream
- True
-
-We change the upstream one, and thus, the one in Launchpad will be changed
-too at the same time.
-
- >>> message = potmsgset.updateTranslation(
- ... pofile_es, carlos, {0: u'foo '}, is_current_upstream=True,
- ... lock_timestamp=datetime.datetime.now(UTC))
-
- >>> message.msgstr0.translation
- u'foo '
- >>> message.is_complete
- True
- >>> message.is_current_upstream
- True
-
-Even more, if there is no translation at all in Launchpad, we still get
-the update from upstream.
-
- >>> message = potmsgset.updateTranslation(
- ... pofile_es, carlos, {}, is_current_upstream=False,
- ... lock_timestamp=datetime.datetime.now(UTC))
- >>> message.msgstr0 is None
- True
-
- >>> message.is_complete
- False
-
- >>> flush_database_updates()
- >>> message = potmsgset.updateTranslation(
- ... pofile_es, carlos, {0: u'foobar '},
- ... is_current_upstream=True,
- ... lock_timestamp=datetime.datetime.now(UTC))
- >>> flush_database_updates()
- >>> message.msgstr0.translation
- u'foobar '
-
- >>> message.is_complete
- True
-
- >>> message.is_current_upstream
- True
-
-So far, the current translation has been the imported one. If Carlos
-now submits another translation for the same message through the web
-form, it is marked as current, but the last-imported translation remains
-unaffected.
-
- >>> dummy = potmsgset.updateTranslation(
- ... pofile_es, carlos, {0: 'boing '}, is_current_upstream=False,
- ... lock_timestamp=datetime.datetime.now(UTC))
- >>> flush_database_updates()
- >>> message = potmsgset.getCurrentTranslationMessage(
- ... upstream_evo, spanish)
- >>> message == dummy
- True
- >>> message.msgstr0.translation
- u'boing '
-
- >>> message.is_complete
- True
-
- >>> message.is_current_upstream
- False
-
-Since upstream and active translations diverged, if we get a new
-upstream translation, the one in Launchpad will be kept untouched.
-
- >>> dummy = potmsgset.updateTranslation(
- ... pofile_es, carlos, {0: u'bars '}, is_current_upstream=True,
- ... lock_timestamp=datetime.datetime.now(UTC))
- >>> flush_database_updates()
- >>> message = potmsgset.getCurrentTranslationMessage(
- ... upstream_evo, spanish)
- >>> message != dummy
- True
-
- >>> message.translations
- [u'boing ']
-
- >>> message.is_complete
- True
-
- >>> message = potmsgset.getImportedTranslationMessage(
- ... upstream_evo, spanish)
- >>> message.translations
- [u'bars ']
-
- >>> message.is_complete
- True
-
-To force adding a new suggestion even if there are enough
-privileges to set it as current, we can use the force_suggestion
-parameter.
-
- >>> dummy = potmsgset.updateTranslation(
- ... pofile_es, carlos, {0: u'suggestion! '},
- ... is_current_upstream=False,
- ... lock_timestamp=datetime.datetime.now(UTC), force_suggestion=True)
- >>> flush_database_updates()
- >>> message = potmsgset.getCurrentTranslationMessage(
- ... upstream_evo, spanish)
- >>> message != dummy
- True
- >>> message.translations
- [u'boing ']
- >>> message.is_complete
- True
- >>> dummy.translations
- [u'suggestion! ']
- >>> dummy.is_complete
- True
=== removed file 'lib/lp/translations/tests/test_empty_messages.py'
--- lib/lp/translations/tests/test_empty_messages.py 2010-12-16 13:16:58 +0000
+++ lib/lp/translations/tests/test_empty_messages.py 1970-01-01 00:00:00 +0000
@@ -1,113 +0,0 @@
-# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-__metaclass__ = type
-
-from datetime import datetime
-
-from pytz import timezone
-from zope.component import getUtility
-
-from canonical.testing.layers import LaunchpadZopelessLayer
-from lp.app.enums import ServiceUsage
-from lp.services.worlddata.interfaces.language import ILanguageSet
-from lp.testing import TestCaseWithFactory
-
-
-class TestTranslationEmptyMessages(TestCaseWithFactory):
- """Test behaviour of empty translation messages."""
-
- layer = LaunchpadZopelessLayer
-
- def setUp(self):
- """Set up context to test in."""
- # Pretend we have a product being translated to Serbian.
- # This is where we are going to be importing translations to.
- super(TestTranslationEmptyMessages, self).setUp()
- product = self.factory.makeProduct(
- translations_usage=ServiceUsage.LAUNCHPAD)
- self.productseries = self.factory.makeProductSeries(product=product)
- self.potemplate = self.factory.makePOTemplate(self.productseries)
- self.serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
- self.pofile_sr = self.factory.makePOFile(
- 'sr',
- potemplate=self.potemplate)
- self.now = datetime.now(timezone('UTC'))
-
- def test_NoEmptyImporedTranslation(self):
- # When an empty translation comes from import, it is
- # ignored when there's NO previous is_current_upstream translation.
- potmsgset = self.factory.makePOTMsgSet(self.potemplate)
- translation = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, [""],
- is_current_upstream=True, lock_timestamp=None)
-
- # Importing an empty translation should not create a new record
- # in the database.
- self.assertEquals(translation, None)
-
- def test_DeactivatingCurrentTranslation(self):
- # Deactivating replace existing is_current_ubuntu translation,
- # stores an empty translation in the database.
- potmsgset = self.factory.makePOTMsgSet(self.potemplate)
- translation = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, ["active translation"],
- is_current_upstream=False, lock_timestamp=None)
- deactivation = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, [u""],
- is_current_upstream=False, lock_timestamp=self.now)
- ubuntu_message = potmsgset.getCurrentTranslationMessage(
- self.potemplate, self.serbian)
-
- # Storing an empty translation should deactivate the current
- # translation message.
- self.assertEquals(deactivation, ubuntu_message)
-
- def test_DeactivatingImportedTranslation(self):
- # When an empty translation comes from import, it is
- # ignored when there IS a previous is_current_upstream translation,
- # and previous translation is marked as not being
- # is_current_upstream anymore.
- potmsgset = self.factory.makePOTMsgSet(self.potemplate)
- translation = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, ["upstream translation"],
- is_current_upstream=True, lock_timestamp=None)
- deactivation = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, [""],
- is_current_upstream=True, lock_timestamp=self.now)
- upstream_message = potmsgset.getImportedTranslationMessage(
- self.potemplate, self.serbian)
- ubuntu_message = potmsgset.getCurrentTranslationMessage(
- self.potemplate, self.serbian)
-
- # Empty is_current_upstream message should not be imported.
- self.assertEquals(deactivation, None)
- # Existing is_current_upstream message should be unset.
- self.assertEquals(upstream_message, None)
- # Old is_current_upstream message is not is_current_ubuntu either.
- self.assertEquals(ubuntu_message, None)
-
- def test_DeactivatingImportedNotCurrentTranslation(self):
- # When an empty translation comes from import, and there is a
- # previous is_current_upstream translation and another
- # is_current_ubuntu translation, only is_current_upstream
- # translation is unset.
- potmsgset = self.factory.makePOTMsgSet(self.potemplate)
- upstream_message = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, ["upstream translation"],
- is_current_upstream=True, lock_timestamp=None)
- launchpad_message = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, ["launchpad translation"],
- is_current_upstream=False, lock_timestamp=self.now)
- deactivation = potmsgset.updateTranslation(
- self.pofile_sr, self.pofile_sr.owner, [""],
- is_current_upstream=True, lock_timestamp=self.now)
- new_upstream_message = potmsgset.getImportedTranslationMessage(
- self.potemplate, self.serbian)
- ubuntu_message = potmsgset.getCurrentTranslationMessage(
- self.potemplate, self.serbian)
-
- # Current message should not be changed.
- self.assertEquals(launchpad_message, ubuntu_message)
- # Existing is_current_upstream message should be unset.
- self.assertEquals(new_upstream_message, None)
=== modified file 'lib/lp/translations/tests/test_pofile.py'
--- lib/lp/translations/tests/test_pofile.py 2011-01-11 16:15:52 +0000
+++ lib/lp/translations/tests/test_pofile.py 2011-01-20 21:20:32 +0000
@@ -1855,12 +1855,11 @@
def _createMessageSet(self, testmsg):
# Create a message set from the test data.
- pomsgset = self.factory.makePOTMsgSet(
+ potmsgset = self.factory.makePOTMsgSet(
self.potemplate, testmsg['msgid'], sequence=testmsg['sequence'])
- pomsgset.updateTranslation(
- self.pofile, self.pofile.owner,
- {0: testmsg['string'], },
- True, None, force_edition_rights=True)
+ translation = self.factory.makeCurrentTranslationMessage(
+ self.pofile, potmsgset=potmsgset, translator=self.pofile.owner,
+ translations={0: testmsg['string'], }, current_other=True)
def test_getTranslationRows_sequence(self):
# Test for correct sorting of obsolete messages (where sequence=0).
=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
--- lib/lp/translations/tests/test_potmsgset.py 2011-01-19 21:02:46 +0000
+++ lib/lp/translations/tests/test_potmsgset.py 2011-01-20 21:20:32 +0000
@@ -21,7 +21,6 @@
ZopelessDatabaseLayer,
)
from lp.app.enums import ServiceUsage
-from lp.registry.interfaces.person import IPersonSet
from lp.services.propertycache import get_property_cache
from lp.testing import TestCaseWithFactory
from lp.translations.interfaces.potemplate import IPOTemplateSet
@@ -69,8 +68,8 @@
# Create a single POTMsgSet that is used across all tests,
# and add it to only one of the POTemplates.
- self.potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate)
- self.potmsgset.setSequence(self.devel_potemplate, 1)
+ self.potmsgset = self.factory.makePOTMsgSet(
+ self.devel_potemplate, sequence=1)
def _refreshSuggestiveTemplatesCache(self):
"""Refresh the `SuggestivePOTemplate` cache."""
@@ -183,9 +182,7 @@
self.assertTrue(dummy.is_current_ubuntu)
self.assertFalse(dummy.is_current_upstream)
- # XXX henninge 2010-12-10 bug=688519: getCurrentTranslationMessage is not
- # side-aware yet.
- def test_getCurrentTranslationMessage(self):
+ def test_getCurrentTranslation(self):
"""Test how shared and diverged current translation messages
interact."""
# Share a POTMsgSet in two templates, and get a Serbian POFile.
@@ -194,21 +191,29 @@
serbian = sr_pofile.language
# A shared translation is current in both templates.
- shared_translation = self.factory.makeSharedTranslationMessage(
+ shared_translation = self.factory.makeCurrentTranslationMessage(
pofile=sr_pofile, potmsgset=self.potmsgset)
- self.assertEquals(self.potmsgset.getCurrentTranslationMessage(
- self.devel_potemplate, serbian), shared_translation)
- self.assertEquals(self.potmsgset.getCurrentTranslationMessage(
- self.stable_potemplate, serbian), shared_translation)
+ devel_translation = self.potmsgset.getCurrentTranslation(
+ self.devel_potemplate, serbian,
+ self.devel_potemplate.translation_side)
+ self.assertEquals(devel_translation, shared_translation)
+ stable_translation = self.potmsgset.getCurrentTranslation(
+ self.stable_potemplate, serbian,
+ self.stable_potemplate.translation_side)
+ self.assertEquals(stable_translation, shared_translation)
# Adding a diverged translation in one template makes that one
# current in it.
- diverged_translation = self.factory.makeTranslationMessage(
- pofile=sr_pofile, potmsgset=self.potmsgset, force_diverged=True)
- self.assertEquals(self.potmsgset.getCurrentTranslationMessage(
- self.devel_potemplate, serbian), diverged_translation)
- self.assertEquals(self.potmsgset.getCurrentTranslationMessage(
- self.stable_potemplate, serbian), shared_translation)
+ diverged_translation = self.factory.makeDivergedTranslationMessage(
+ pofile=sr_pofile, potmsgset=self.potmsgset)
+ devel_translation = self.potmsgset.getCurrentTranslation(
+ self.devel_potemplate, serbian,
+ self.devel_potemplate.translation_side)
+ self.assertEquals(devel_translation, diverged_translation)
+ stable_translation = self.potmsgset.getCurrentTranslation(
+ self.stable_potemplate, serbian,
+ self.stable_potemplate.translation_side)
+ self.assertEquals(stable_translation, shared_translation)
def test_getOtherTranslation(self):
# Get the translation on the other side.
@@ -494,182 +499,6 @@
self.devel_potemplate, serbian),
True)
- def test_updateTranslation_divergence(self):
- """Test that diverging translations works as expected."""
- sr_pofile = self.factory.makePOFile('sr', self.devel_potemplate)
- serbian = sr_pofile.language
-
- # We can't use factory methods here because they depend on
- # updateTranslation itself. So, a bit more boiler-plate than
- # usual.
-
- # Let's create a shared, current translation.
- shared_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile, submitter=sr_pofile.owner,
- new_translations=[u'Shared'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
- self.assertEquals(shared_translation.potemplate, None)
- self.assertTrue(shared_translation.is_current_ubuntu)
-
- # And let's create a diverged translation by passing `force_diverged`
- # parameter to updateTranslation call.
- diverged_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile, submitter=sr_pofile.owner,
- new_translations=[u'Diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC), force_diverged=True)
- self.assertEquals(diverged_translation.potemplate,
- self.devel_potemplate)
- # Both shared and diverged translations are marked as current,
- # since shared might be used in other templates which have no
- # divergences.
- self.assertTrue(shared_translation.is_current_ubuntu)
- self.assertTrue(diverged_translation.is_current_ubuntu)
-
- # But only diverged one is returned as current.
- current_translation = self.potmsgset.getCurrentTranslationMessage(
- self.devel_potemplate, serbian)
- self.assertEquals(current_translation, diverged_translation)
-
- # Trying to set a new, completely different translation when
- # there is a diverged translation keeps the divergence.
- new_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile, submitter=sr_pofile.owner,
- new_translations=[u'New diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
- self.assertEquals(new_translation.potemplate,
- self.devel_potemplate)
- self.assertTrue(shared_translation.is_current_ubuntu)
- self.assertTrue(new_translation.is_current_ubuntu)
-
- def test_updateTranslation_divergence_identical_translation(self):
- """Test that identical diverging translations works as expected."""
- # Create the POFile in *all* sharing potemplates.
- sr_pofile_devel = self.factory.makePOFile('sr',
- self.devel_potemplate,
- create_sharing=True)
- serbian = sr_pofile_devel.language
- sr_pofile_stable = (
- self.stable_potemplate.getPOFileByLang(serbian.code))
-
- # We can't use factory methods here because they depend on
- # updateTranslation itself. So, a bit more boiler-plate than
- # usual.
-
- # Let's create a shared, current translation.
- shared_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile_devel, submitter=sr_pofile_devel.owner,
- new_translations=[u'Shared'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
-
- # And let's create a diverged translation on the devel series by
- # passing `force_diverged` parameter to updateTranslation call.
- diverged_translation_devel = self.potmsgset.updateTranslation(
- pofile=sr_pofile_devel, submitter=sr_pofile_devel.owner,
- new_translations=[u'Diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC), force_diverged=True)
-
- # Now we create a diverged translation in the stable series that
- # is identical to the diverged message in the devel series.
- diverged_translation_stable = self.potmsgset.updateTranslation(
- pofile=sr_pofile_stable, submitter=sr_pofile_stable.owner,
- new_translations=[u'Diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC), force_diverged=True)
-
- # This will create a new, diverged message with the same translation
- # but linked to the other potemplate.
- devel_translation = self.potmsgset.getCurrentTranslationMessage(
- self.devel_potemplate, serbian)
- self.assertEquals(diverged_translation_devel, devel_translation)
- self.assertEquals(self.devel_potemplate,
- devel_translation.potemplate)
-
- stable_translation = self.potmsgset.getCurrentTranslationMessage(
- self.stable_potemplate, serbian)
- self.assertEquals(diverged_translation_stable, stable_translation)
- self.assertEquals(self.stable_potemplate,
- stable_translation.potemplate)
-
- def test_updateTranslation_divergence_shared_identical_translation(self):
- """Test that identical diverging translations works as expected."""
- # Create the POFile in *all* sharing potemplates.
- sr_pofile_devel = self.factory.makePOFile('sr',
- self.devel_potemplate,
- create_sharing=True)
- serbian = sr_pofile_devel.language
- sr_pofile_stable = (
- self.stable_potemplate.getPOFileByLang(serbian.code))
-
- # We can't use factory methods here because they depend on
- # updateTranslation itself. So, a bit more boiler-plate than
- # usual.
-
- # Let's create a shared, current translation.
- shared_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile_devel, submitter=sr_pofile_devel.owner,
- new_translations=[u'Shared'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
-
- # And let's create a diverged translation on the devel series by
- # passing `force_diverged` parameter to updateTranslation call.
- diverged_translation_devel = self.potmsgset.updateTranslation(
- pofile=sr_pofile_devel, submitter=sr_pofile_devel.owner,
- new_translations=[u'Diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC), force_diverged=True)
-
- # Now we create a new shared translation in the stable series that
- # is identical to the diverged message in the devel series.
- new_translation_stable = self.potmsgset.updateTranslation(
- pofile=sr_pofile_stable, submitter=sr_pofile_stable.owner,
- new_translations=[u'Diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
-
- # This will create a new shared message with the same translation as
- # the diverged one.
- devel_translation = self.potmsgset.getCurrentTranslationMessage(
- self.devel_potemplate, serbian)
- self.assertEquals(diverged_translation_devel, devel_translation)
- self.assertEquals(self.devel_potemplate,
- devel_translation.potemplate)
-
- stable_translation = self.potmsgset.getCurrentTranslationMessage(
- self.stable_potemplate, serbian)
- self.assertEquals(new_translation_stable, stable_translation)
- self.assertEquals(None, stable_translation.potemplate)
-
- # The old shared translation is not current anymore.
- self.assertFalse(shared_translation.is_current_ubuntu)
-
- def test_updateTranslation_convergence(self):
- """Test that converging translations works as expected."""
- sr_pofile = self.factory.makePOFile('sr', self.devel_potemplate)
- serbian = sr_pofile.language
-
- # Let's create a shared, current translation, and diverge from it
- # in this POTemplate.
- shared_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile, submitter=sr_pofile.owner,
- new_translations=[u'Shared'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
- diverged_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile, submitter=sr_pofile.owner,
- new_translations=[u'Diverged'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC), force_diverged=True)
-
- # Setting a diverged translation to exactly match shared one
- # will "converge" it back to the shared one.
- new_translation = self.potmsgset.updateTranslation(
- pofile=sr_pofile, submitter=sr_pofile.owner,
- new_translations=[u'Shared'], is_current_upstream=False,
- lock_timestamp=datetime.now(pytz.UTC))
- self.assertEquals(new_translation, shared_translation)
- self.assertFalse(diverged_translation.is_current_ubuntu)
- self.assertTrue(new_translation.is_current_ubuntu)
-
- # Current translation is the shared one.
- current_translation = self.potmsgset.getCurrentTranslationMessage(
- self.devel_potemplate, serbian)
- self.assertEquals(current_translation, shared_translation)
-
def test_setTranslationCreditsToTranslated(self):
"""Test that translation credits are correctly set as translated."""
sr_pofile = self.factory.makePOFile('sr', self.devel_potemplate)
@@ -1242,257 +1071,6 @@
self.assertEquals(ubuntu_msgid, self.potmsgset.singular_text)
-class TestPOTMsgSetCornerCases(TestCaseWithFactory):
- """Test corner cases and constraints."""
-
- layer = DatabaseFunctionalLayer
-
- def gen_now(self):
- now = datetime.now(pytz.UTC)
- while True:
- yield now
- now += timedelta(milliseconds=1)
-
- def setUp(self):
- """Set up context to test in."""
- # Create a product with two series and a shared POTemplate
- # in different series ('devel' and 'stable').
- super(TestPOTMsgSetCornerCases, self).setUp('carlos@xxxxxxxxxxxxx')
-
- self.pofile = self.factory.makePOFile('sr')
- self.potemplate = self.pofile.potemplate
- self.uploader = getUtility(IPersonSet).getByName('carlos')
- self.now = self.gen_now().next
-
- # Create a single POTMsgSet that is used across all tests,
- # and add it to only one of the POTemplates.
- self.potmsgset = self.factory.makePOTMsgSet(self.potemplate,
- sequence=1)
-
- def test_updateTranslation_SharedCurrentConstraint(self):
- # Corner case for bug #373139:
- # Adding a diverged, non-imported translation "tm1",
- # then a shared imported translation "tm2",
- # and finally, a shared imported translation "tm1" (matching original
- # diverged, non-imported translation) marks "tm2" as not current,
- # and makes "tm1" shared.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=False, force_diverged=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True, force_shared=True)
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True)
-
- self.assertTrue(tm1.is_current_ubuntu)
- self.assertFalse(tm2.is_current_ubuntu)
- self.assertTrue(tm1.potemplate is None)
- self.assertTrue(tm2.potemplate is None)
-
- def test_updateTranslation_SharedImportedConstraint(self):
- # Corner case for bug #373139:
- # Adding a diverged imported translation "tm1",
- # then a shared imported translation "tm2",
- # and re-uploading "tm1" as just imported
- # makes "tm2" not is_current_upstream, and both are shared.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True, force_diverged=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True, force_shared=True)
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True)
-
- self.assertTrue(tm1.is_current_upstream)
- self.assertFalse(tm2.is_current_upstream)
- self.assertTrue(tm1.potemplate is None)
- self.assertTrue(tm2.potemplate is None)
-
- def test_updateTranslation_DivergedImportedConstraint(self):
- # Corner case for bug #373139:
- # Adding a shared imported translation "tm1",
- # then a diverged imported translation "tm2",
- # and re-uploading "tm1" as imported translation
- # makes "tm2" not is_current_upstream, and both are shared.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True, force_shared=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True, force_diverged=True)
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True)
-
- self.assertTrue(tm1.is_current_upstream)
- self.assertFalse(tm2.is_current_upstream)
- self.assertTrue(tm1.potemplate is None)
- self.assertTrue(tm2.potemplate is None)
-
- def test_updateTranslation_DivergedCurrentConstraint(self):
- # Corner case for bug #373139:
- # Adding a shared non-imported translation "tm0",
- # then a diverged non-imported translation "tm1"
- # (both are still current), then a diverged imported
- # translation (common pre-message-sharing-migration),
- # and we try to activate "tm0" as a forced diverged translation.
- # This makes "tm0" current and diverged, "tm1" non-current
- # and shared (basically, just a regular suggestion), and
- # "tm2" a diverged, non-current but imported translation.
- tm0 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm0"], lock_timestamp=self.now(),
- is_current_upstream=False, force_shared=True)
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=False, force_diverged=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True, force_diverged=True)
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm0"], lock_timestamp=self.now(),
- is_current_upstream=False, force_diverged=True)
-
- self.assertTrue(tm0.is_current_ubuntu)
- self.assertFalse(tm1.is_current_ubuntu)
- self.assertFalse(tm2.is_current_ubuntu)
- self.assertTrue(tm2.is_current_upstream)
- self.assertEquals(tm0.potemplate, self.potemplate)
- self.assertTrue(tm1.potemplate is None)
- self.assertEquals(tm2.potemplate, self.potemplate)
-
- def test_updateTranslation_DivergedImportedToSharedImported(self):
- # Corner case for bug #381645:
- # Adding a shared imported translation "tm1",
- # then a diverged imported translation "tm2",
- # making a shared one current.
- # On importing "tm1" again, we need to remove
- # is_current_upstream flag from diverged message.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True, force_shared=True)
- self.assertTrue(tm1.is_current_ubuntu)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True, force_diverged=True)
- tm2.makeCurrentUbuntu(False)
-
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True)
-
- self.assertTrue(tm1.is_current_ubuntu)
- self.assertTrue(tm1.is_current_upstream)
- self.assertFalse(tm2.is_current_ubuntu)
- self.assertFalse(tm2.is_current_upstream)
- self.assertTrue(tm1.potemplate is None)
-
- def test_updateTranslation_DivergedCurrentToSharedImported(self):
- # Corner case for bug #381645:
- # Adding a shared imported translation "tm1",
- # then a diverged, non-imported current translation "tm2".
- # On importing "tm2" again, we need to make it
- # shared, and unmark existing imported message as
- # being current.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True, force_shared=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=False, force_diverged=True)
- self.assertTrue(tm1.is_current_ubuntu)
- self.assertTrue(tm2.is_current_ubuntu)
- self.assertTrue(tm1.is_current_upstream)
- self.assertFalse(tm2.is_current_upstream)
-
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True)
-
- self.assertTrue(tm2.is_current_ubuntu)
- self.assertTrue(tm2.is_current_upstream)
- self.assertTrue(tm2.potemplate is None)
- self.assertFalse(tm1.is_current_ubuntu)
- self.assertFalse(tm1.is_current_upstream)
-
- def test_updateTranslation_SharedImportedToSharedImported(self):
- # Corner case for bug #394224:
- # Adding two imported messages, a shared "tm1" and a diverged "tm2".
- # "tm1" is the current message.
- # On importing "tm2" again, we need to make it shared while marking
- # "tm1" to be not imported because two imported shared translations
- # at the same time would trigger a database constraint.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True, force_shared=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=True, force_diverged=True)
- tm2.makeCurrentUbuntu(False)
-
- self.assertEquals(None, tm1.potemplate)
- self.assertEquals(self.pofile.potemplate, tm2.potemplate)
-
- self.assertTrue(tm1.is_current_ubuntu)
- self.assertFalse(tm2.is_current_ubuntu)
-
- self.assertTrue(tm1.is_current_upstream)
- self.assertTrue(tm2.is_current_upstream)
-
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=False)
-
- self.assertEquals(None, tm1.potemplate)
- self.assertEquals(None, tm2.potemplate)
-
- self.assertFalse(tm1.is_current_ubuntu)
- self.assertTrue(tm2.is_current_ubuntu)
-
- self.assertFalse(tm1.is_current_upstream)
- self.assertTrue(tm2.is_current_upstream)
-
- def test_updateTranslation_DivergedCurrentToDivergedImported(self):
- # Corner case that came up when fixing bug #394224:
- # Two diverged messages, one current-upstream "tm1", the other "tm2"
- # (current-Ubuntu) is not.
- # Updating the first one through the web ui
- # (is_current_upstream=False) allows the current-upstream one to
- # replace the one that's not current-upstream. The former diverged
- # ubuntu message is converged.
- tm1 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=True, force_diverged=True)
- tm2 = self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm2"], lock_timestamp=self.now(),
- is_current_upstream=False, force_diverged=True)
-
- self.assertEquals(self.pofile.potemplate, tm1.potemplate)
- self.assertEquals(self.pofile.potemplate, tm2.potemplate)
-
- self.assertFalse(tm1.is_current_ubuntu)
- self.assertTrue(tm2.is_current_ubuntu)
-
- self.assertTrue(tm1.is_current_upstream)
- self.assertFalse(tm2.is_current_upstream)
-
- self.potmsgset.updateTranslation(
- self.pofile, self.uploader, [u"tm1"], lock_timestamp=self.now(),
- is_current_upstream=False)
-
- self.assertEquals(self.pofile.potemplate, tm1.potemplate)
- self.assertEquals(None, tm2.potemplate)
-
- self.assertTrue(tm1.is_current_ubuntu)
- self.assertFalse(tm2.is_current_ubuntu)
-
- self.assertTrue(tm1.is_current_upstream)
- self.assertFalse(tm2.is_current_upstream)
-
-
class TestPOTMsgSetTranslationCredits(TestCaseWithFactory):
"""Test methods related to TranslationCredits."""