Merge lp:~jtv/launchpad/recife-pre-resetCurrentTranslation into lp:~launchpad/launchpad/recife

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Stuart Bishop
Approved revision: no longer in the source branch.
Merged at revision: 9160
Proposed branch: lp:~jtv/launchpad/recife-pre-resetCurrentTranslation
Merge into: lp:~launchpad/launchpad/recife
Diff against target: 171 lines (+95/-1)
5 files modified
lib/lp/testing/factory.py (+22/-1)
lib/lp/testing/tests/test_factory.py (+35/-0)
lib/lp/translations/interfaces/pofile.py (+8/-0)
lib/lp/translations/model/pofile.py (+8/-0)
lib/lp/translations/tests/test_pofile.py (+22/-0)
To merge this branch: bzr merge lp:~jtv/launchpad/recife-pre-resetCurrentTranslation
Reviewer Review Type Date Requested Status
Stuart Bishop (community) code Approve
Launchpad code reviewers code Pending
Review via email: mp+33490@code.launchpad.net

Commit message

factory.makeDivergedTranslationMessage, POFile.markChanged.

Description of the change

= Helpers for resetCurrentTranslation work =

This goes into the Recife feature branch. It adds two helpers that became necessary for a later branch:

1. LaunchpadObjectFactory.makeDivergedTranslationMessage. Creates a TranslationMessage that's current and diverged. In the Recife work's current transient state, we have no proper way of doing this. At least this way we get to sweep all the dirt under a single rug until we can clean it up properly.

2. POFile.markChanged updates a POFile's last-change date and, optionally, the last translator. This is cleaner than messing with the POFile's attributes directly elsewhere.

Finally (but all the way at the top) it fixes an omission that causes trouble in later branches:

3. LaunchpadObjectFactory.makeCurrentTranslation neglected to set the new message's reviewer as expected.

To test,
{{{
./bin/test -vvc -m lp.testing.tests.test_factory
}}}

No lint.

Jeroen

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

(13:32:29) Jeroen Vermeulen: stub: care to review a branch for me? It's a blocking risk, but not large. https://code.edge.launchpad.net/~jtv/launchpad/recife-pre-resetCurrentTranslation/+merge/33490
(13:35:22) stub: jtv: Not a blocking risk yet - nothing is using it apart from tests
(13:35:52) Jeroen Vermeulen: stub: nothing I can _land_ now, no. Hence: blocking.
(13:36:07) stub: You have an XXX that doesn't cite a bug.
(13:36:32) stub: There are two ways of fixing that.
(13:36:41) Jeroen Vermeulen: stub: our policy is currently not to file bugs too far in advance. It's listed in various places though.
(13:37:23) stub: Our policy is also no XXX's without cited bugs IIRC. So remove three letters or create a bug I think are the options.
(13:37:50) Jeroen Vermeulen: Okay, okay, I'm removing the XXX.
(13:38:43) Jeroen Vermeulen: Pushing.
(13:40:04) stub: jtv: IPOFile doesn't describe the parameters, which is minor but doesn't hurt to mention translator remains unchanged and timestamp is now by default.
(13:40:06) Jeroen Vermeulen: Pushed.
(13:40:56) stub: Otherwise all fine.

review: Approve
Revision history for this message
Stuart Bishop (stub) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py 2010-08-19 09:37:13 +0000
+++ lib/lp/testing/factory.py 2010-08-24 06:45:55 +0000
@@ -165,6 +165,7 @@
165 time_counter,165 time_counter,
166 )166 )
167from lp.translations.interfaces.potemplate import IPOTemplateSet167from lp.translations.interfaces.potemplate import IPOTemplateSet
168from lp.translations.interfaces.side import ITranslationSideTraitsSet
168from lp.translations.interfaces.translationimportqueue import (169from lp.translations.interfaces.translationimportqueue import (
169 RosettaImportStatus)170 RosettaImportStatus)
170from lp.translations.interfaces.translationfileformat import (171from lp.translations.interfaces.translationfileformat import (
@@ -2107,7 +2108,7 @@
2107 if isinstance(translations, dict):2108 if isinstance(translations, dict):
2108 return translations2109 return translations
2109 assert isinstance(translations, (list, tuple)), (2110 assert isinstance(translations, (list, tuple)), (
2110 "Expecting either a dict or a sequence." )2111 "Expecting either a dict or a sequence.")
2111 return dict(enumerate(translations))2112 return dict(enumerate(translations))
21122113
2113 def makeSuggestion(self, pofile=None, potmsgset=None, translator=None,2114 def makeSuggestion(self, pofile=None, potmsgset=None, translator=None,
@@ -2196,6 +2197,26 @@
2196 if diverged:2197 if diverged:
2197 removeSecurityProxy(message).potemplate = pofile.potemplate2198 removeSecurityProxy(message).potemplate = pofile.potemplate
21982199
2200 message.markReviewed(reviewer)
2201 return message
2202
2203 def makeDivergedTranslationMessage(self, pofile=None, potmsgset=None,
2204 translator=None, reviewer=None,
2205 translations=None):
2206 """Create a diverged, current `TranslationMessage`."""
2207 if pofile is None:
2208 pofile = self.makePOFile('lt')
2209
2210 # This creates a suggestion, then diverges it, then activates it.
2211 # Once we have a method for diverging messages, do this in a more
2212 # proper way.
2213 message = self.makeSharedTranslationMessage(
2214 pofile=pofile, potmsgset=potmsgset, translator=translator,
2215 reviewer=reviewer, translations=translations, suggestion=True)
2216 traits = getUtility(ITranslationSideTraitsSet).getTraits(
2217 pofile.potemplate.translation_side)
2218 removeSecurityProxy(message).potemplate = pofile.potemplate
2219 traits.setFlag(message, True)
2199 return message2220 return message
22002221
2201 def makeTranslation(self, pofile, sequence,2222 def makeTranslation(self, pofile, sequence,
22022223
=== modified file 'lib/lp/testing/tests/test_factory.py'
--- lib/lp/testing/tests/test_factory.py 2010-08-19 09:37:13 +0000
+++ lib/lp/testing/tests/test_factory.py 2010-08-24 06:45:55 +0000
@@ -517,6 +517,41 @@
517 translations, [tm.msgstr0.translation, tm.msgstr1.translation])517 translations, [tm.msgstr0.translation, tm.msgstr1.translation])
518 self.assertIs(None, tm.msgstr2)518 self.assertIs(None, tm.msgstr2)
519519
520 def test_makeCurrentTranslationMessage_sets_reviewer(self):
521 reviewer = self.factory.makePerson()
522
523 tm = self.factory.makeCurrentTranslationMessage(reviewer=reviewer)
524
525 self.assertEqual(reviewer, tm.reviewer)
526
527 def test_makeCurrentTranslationMessage_creates_reviewer(self):
528 tm = self.factory.makeCurrentTranslationMessage(reviewer=None)
529
530 self.assertNotEqual(None, tm.reviewer)
531
532 def test_makeDivergedTranslationMessage_upstream(self):
533 pofile = self.factory.makePOFile('ca')
534
535 tm = self.factory.makeDivergedTranslationMessage(pofile=pofile)
536
537 self.assertTrue(tm.is_current_upstream)
538 self.assertFalse(tm.is_current_ubuntu)
539 self.assertTrue(tm.is_diverged)
540 self.assertEqual(pofile.potemplate, tm.potemplate)
541
542 def test_makeDivergedTranslationMessage_ubuntu(self):
543 potemplate = self.factory.makePOTemplate(
544 distroseries=self.factory.makeDistroSeries(),
545 sourcepackagename=self.factory.makeSourcePackageName())
546 pofile = self.factory.makePOFile('eu', potemplate=potemplate)
547
548 tm = self.factory.makeDivergedTranslationMessage(pofile=pofile)
549
550 self.assertTrue(tm.is_current_ubuntu)
551 self.assertFalse(tm.is_current_upstream)
552 self.assertTrue(tm.is_diverged)
553 self.assertEqual(pofile.potemplate, tm.potemplate)
554
520555
521class TestFactoryWithLibrarian(TestCaseWithFactory):556class TestFactoryWithLibrarian(TestCaseWithFactory):
522557
523558
=== modified file 'lib/lp/translations/interfaces/pofile.py'
--- lib/lp/translations/interfaces/pofile.py 2010-08-10 14:39:46 +0000
+++ lib/lp/translations/interfaces/pofile.py 2010-08-24 06:45:55 +0000
@@ -281,6 +281,14 @@
281 :return: a list of `VPOExport` objects.281 :return: a list of `VPOExport` objects.
282 """282 """
283283
284 def markChanged(translator=None, timestamp=None):
285 """Note a change to this `POFile` or its contents.
286
287 :param translator: The person making this change. If given,
288 `lasttranslator` will be updated to refer to this person.
289 :param timestamp: Time of the change. Defaults to "now."
290 """
291
284292
285class AlternativeLanguageVocabularyFactory:293class AlternativeLanguageVocabularyFactory:
286 """Gets vocab for user's preferred languages, or all languages if not set.294 """Gets vocab for user's preferred languages, or all languages if not set.
287295
=== modified file 'lib/lp/translations/model/pofile.py'
--- lib/lp/translations/model/pofile.py 2010-08-17 09:55:30 +0000
+++ lib/lp/translations/model/pofile.py 2010-08-24 06:45:55 +0000
@@ -417,6 +417,14 @@
417 """See `IPOFile`."""417 """See `IPOFile`."""
418 return TranslatableMessage(potmsgset, self)418 return TranslatableMessage(potmsgset, self)
419419
420 def markChanged(self, translator=None, timestamp=None):
421 """See `IPOFile`."""
422 if timestamp is None:
423 timestamp = UTC_NOW
424 self.date_changed = timestamp
425 if translator is not None:
426 self.lasttranslator = translator
427
420428
421class POFile(SQLBase, POFileMixIn):429class POFile(SQLBase, POFileMixIn):
422 implements(IPOFile)430 implements(IPOFile)
423431
=== modified file 'lib/lp/translations/tests/test_pofile.py'
--- lib/lp/translations/tests/test_pofile.py 2010-08-17 09:55:30 +0000
+++ lib/lp/translations/tests/test_pofile.py 2010-08-24 06:45:55 +0000
@@ -11,6 +11,8 @@
11from zope.interface.verify import verifyObject11from zope.interface.verify import verifyObject
12from zope.security.proxy import removeSecurityProxy12from zope.security.proxy import removeSecurityProxy
1313
14from canonical.database.constants import UTC_NOW
15
14from lp.translations.interfaces.pofile import IPOFileSet16from lp.translations.interfaces.pofile import IPOFileSet
15from lp.translations.interfaces.translatablemessage import (17from lp.translations.interfaces.translatablemessage import (
16 ITranslatableMessage)18 ITranslatableMessage)
@@ -1776,6 +1778,26 @@
1776 "getTranslationRows does not sort obsolete messages "1778 "getTranslationRows does not sort obsolete messages "
1777 "(sequence=0) to the end of the file.")1779 "(sequence=0) to the end of the file.")
17781780
1781 def test_markChanged_sets_date(self):
1782 timestamp = datetime.now(pytz.UTC) - timedelta(days=14)
1783 self.pofile.markChanged(timestamp=timestamp)
1784 self.assertEqual(timestamp, self.pofile.date_changed)
1785
1786 def test_markChanged_defaults_to_now(self):
1787 self.pofile.date_changed = datetime.now(pytz.UTC) - timedelta(days=99)
1788 self.pofile.markChanged()
1789 self.assertEqual(UTC_NOW, self.pofile.date_changed)
1790
1791 def test_markChanged_leaves_lasttranslator_unchanged(self):
1792 old_lasttranslator = self.pofile.lasttranslator
1793 self.pofile.markChanged()
1794 self.assertEqual(old_lasttranslator, self.pofile.lasttranslator)
1795
1796 def test_markChanged_sets_lasttranslator(self):
1797 translator = self.factory.makePerson()
1798 self.pofile.markChanged(translator=translator)
1799 self.assertEqual(translator, self.pofile.lasttranslator)
1800
17791801
1780class TestPOFileToTranslationFileDataAdapter(TestCaseWithFactory):1802class TestPOFileToTranslationFileDataAdapter(TestCaseWithFactory):
1781 """Test POFile being adapted to IPOFileToTranslationFileData."""1803 """Test POFile being adapted to IPOFileToTranslationFileData."""

Subscribers

People subscribed via source and target branches