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
1=== modified file 'lib/lp/testing/factory.py'
2--- lib/lp/testing/factory.py 2010-08-19 09:37:13 +0000
3+++ lib/lp/testing/factory.py 2010-08-24 06:45:55 +0000
4@@ -165,6 +165,7 @@
5 time_counter,
6 )
7 from lp.translations.interfaces.potemplate import IPOTemplateSet
8+from lp.translations.interfaces.side import ITranslationSideTraitsSet
9 from lp.translations.interfaces.translationimportqueue import (
10 RosettaImportStatus)
11 from lp.translations.interfaces.translationfileformat import (
12@@ -2107,7 +2108,7 @@
13 if isinstance(translations, dict):
14 return translations
15 assert isinstance(translations, (list, tuple)), (
16- "Expecting either a dict or a sequence." )
17+ "Expecting either a dict or a sequence.")
18 return dict(enumerate(translations))
19
20 def makeSuggestion(self, pofile=None, potmsgset=None, translator=None,
21@@ -2196,6 +2197,26 @@
22 if diverged:
23 removeSecurityProxy(message).potemplate = pofile.potemplate
24
25+ message.markReviewed(reviewer)
26+ return message
27+
28+ def makeDivergedTranslationMessage(self, pofile=None, potmsgset=None,
29+ translator=None, reviewer=None,
30+ translations=None):
31+ """Create a diverged, current `TranslationMessage`."""
32+ if pofile is None:
33+ pofile = self.makePOFile('lt')
34+
35+ # This creates a suggestion, then diverges it, then activates it.
36+ # Once we have a method for diverging messages, do this in a more
37+ # proper way.
38+ message = self.makeSharedTranslationMessage(
39+ pofile=pofile, potmsgset=potmsgset, translator=translator,
40+ reviewer=reviewer, translations=translations, suggestion=True)
41+ traits = getUtility(ITranslationSideTraitsSet).getTraits(
42+ pofile.potemplate.translation_side)
43+ removeSecurityProxy(message).potemplate = pofile.potemplate
44+ traits.setFlag(message, True)
45 return message
46
47 def makeTranslation(self, pofile, sequence,
48
49=== modified file 'lib/lp/testing/tests/test_factory.py'
50--- lib/lp/testing/tests/test_factory.py 2010-08-19 09:37:13 +0000
51+++ lib/lp/testing/tests/test_factory.py 2010-08-24 06:45:55 +0000
52@@ -517,6 +517,41 @@
53 translations, [tm.msgstr0.translation, tm.msgstr1.translation])
54 self.assertIs(None, tm.msgstr2)
55
56+ def test_makeCurrentTranslationMessage_sets_reviewer(self):
57+ reviewer = self.factory.makePerson()
58+
59+ tm = self.factory.makeCurrentTranslationMessage(reviewer=reviewer)
60+
61+ self.assertEqual(reviewer, tm.reviewer)
62+
63+ def test_makeCurrentTranslationMessage_creates_reviewer(self):
64+ tm = self.factory.makeCurrentTranslationMessage(reviewer=None)
65+
66+ self.assertNotEqual(None, tm.reviewer)
67+
68+ def test_makeDivergedTranslationMessage_upstream(self):
69+ pofile = self.factory.makePOFile('ca')
70+
71+ tm = self.factory.makeDivergedTranslationMessage(pofile=pofile)
72+
73+ self.assertTrue(tm.is_current_upstream)
74+ self.assertFalse(tm.is_current_ubuntu)
75+ self.assertTrue(tm.is_diverged)
76+ self.assertEqual(pofile.potemplate, tm.potemplate)
77+
78+ def test_makeDivergedTranslationMessage_ubuntu(self):
79+ potemplate = self.factory.makePOTemplate(
80+ distroseries=self.factory.makeDistroSeries(),
81+ sourcepackagename=self.factory.makeSourcePackageName())
82+ pofile = self.factory.makePOFile('eu', potemplate=potemplate)
83+
84+ tm = self.factory.makeDivergedTranslationMessage(pofile=pofile)
85+
86+ self.assertTrue(tm.is_current_ubuntu)
87+ self.assertFalse(tm.is_current_upstream)
88+ self.assertTrue(tm.is_diverged)
89+ self.assertEqual(pofile.potemplate, tm.potemplate)
90+
91
92 class TestFactoryWithLibrarian(TestCaseWithFactory):
93
94
95=== modified file 'lib/lp/translations/interfaces/pofile.py'
96--- lib/lp/translations/interfaces/pofile.py 2010-08-10 14:39:46 +0000
97+++ lib/lp/translations/interfaces/pofile.py 2010-08-24 06:45:55 +0000
98@@ -281,6 +281,14 @@
99 :return: a list of `VPOExport` objects.
100 """
101
102+ def markChanged(translator=None, timestamp=None):
103+ """Note a change to this `POFile` or its contents.
104+
105+ :param translator: The person making this change. If given,
106+ `lasttranslator` will be updated to refer to this person.
107+ :param timestamp: Time of the change. Defaults to "now."
108+ """
109+
110
111 class AlternativeLanguageVocabularyFactory:
112 """Gets vocab for user's preferred languages, or all languages if not set.
113
114=== modified file 'lib/lp/translations/model/pofile.py'
115--- lib/lp/translations/model/pofile.py 2010-08-17 09:55:30 +0000
116+++ lib/lp/translations/model/pofile.py 2010-08-24 06:45:55 +0000
117@@ -417,6 +417,14 @@
118 """See `IPOFile`."""
119 return TranslatableMessage(potmsgset, self)
120
121+ def markChanged(self, translator=None, timestamp=None):
122+ """See `IPOFile`."""
123+ if timestamp is None:
124+ timestamp = UTC_NOW
125+ self.date_changed = timestamp
126+ if translator is not None:
127+ self.lasttranslator = translator
128+
129
130 class POFile(SQLBase, POFileMixIn):
131 implements(IPOFile)
132
133=== modified file 'lib/lp/translations/tests/test_pofile.py'
134--- lib/lp/translations/tests/test_pofile.py 2010-08-17 09:55:30 +0000
135+++ lib/lp/translations/tests/test_pofile.py 2010-08-24 06:45:55 +0000
136@@ -11,6 +11,8 @@
137 from zope.interface.verify import verifyObject
138 from zope.security.proxy import removeSecurityProxy
139
140+from canonical.database.constants import UTC_NOW
141+
142 from lp.translations.interfaces.pofile import IPOFileSet
143 from lp.translations.interfaces.translatablemessage import (
144 ITranslatableMessage)
145@@ -1776,6 +1778,26 @@
146 "getTranslationRows does not sort obsolete messages "
147 "(sequence=0) to the end of the file.")
148
149+ def test_markChanged_sets_date(self):
150+ timestamp = datetime.now(pytz.UTC) - timedelta(days=14)
151+ self.pofile.markChanged(timestamp=timestamp)
152+ self.assertEqual(timestamp, self.pofile.date_changed)
153+
154+ def test_markChanged_defaults_to_now(self):
155+ self.pofile.date_changed = datetime.now(pytz.UTC) - timedelta(days=99)
156+ self.pofile.markChanged()
157+ self.assertEqual(UTC_NOW, self.pofile.date_changed)
158+
159+ def test_markChanged_leaves_lasttranslator_unchanged(self):
160+ old_lasttranslator = self.pofile.lasttranslator
161+ self.pofile.markChanged()
162+ self.assertEqual(old_lasttranslator, self.pofile.lasttranslator)
163+
164+ def test_markChanged_sets_lasttranslator(self):
165+ translator = self.factory.makePerson()
166+ self.pofile.markChanged(translator=translator)
167+ self.assertEqual(translator, self.pofile.lasttranslator)
168+
169
170 class TestPOFileToTranslationFileDataAdapter(TestCaseWithFactory):
171 """Test POFile being adapted to IPOFileToTranslationFileData."""

Subscribers

People subscribed via source and target branches