Merge lp://staging/~jtv/launchpad/recife-add-suggestion into lp://staging/~launchpad/launchpad/recife

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Данило Шеган
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp://staging/~jtv/launchpad/recife-add-suggestion
Merge into: lp://staging/~launchpad/launchpad/recife
Diff against target: 814 lines (+437/-80)
19 files modified
lib/canonical/launchpad/ftests/__init__.py (+0/-41)
lib/lp/answers/doc/karma.txt (+1/-1)
lib/lp/archiveuploader/tests/upload-karma.txt (+1/-3)
lib/lp/bugs/doc/externalbugtracker-comment-imports.txt (+1/-1)
lib/lp/bugs/doc/malone-karma.txt (+1/-1)
lib/lp/code/doc/branch-karma.txt (+1/-1)
lib/lp/registry/doc/person-karma.txt (+1/-1)
lib/lp/registry/stories/object/xx-object-branding.txt (+2/-5)
lib/lp/registry/stories/person/xx-person-edit-profile-picture.txt (+1/-1)
lib/lp/registry/stories/person/xx-person-rdf.txt (+1/-1)
lib/lp/registry/stories/teammembership/xx-private-membership.txt (+1/-1)
lib/lp/testing/__init__.py (+12/-0)
lib/lp/testing/branding.py (+48/-0)
lib/lp/testing/factory.py (+17/-0)
lib/lp/testing/karma.py (+88/-19)
lib/lp/translations/doc/rosetta-karma.txt (+1/-1)
lib/lp/translations/interfaces/potmsgset.py (+11/-1)
lib/lp/translations/model/potmsgset.py (+31/-1)
lib/lp/translations/tests/test_potmsgset.py (+218/-1)
To merge this branch: bzr merge lp://staging/~jtv/launchpad/recife-add-suggestion
Reviewer Review Type Date Requested Status
Данило Шеган (community) code Approve
Review via email: mp+22091@code.staging.launchpad.net

Commit message

POTMsgSet.submitSuggestion

Description of the change

= Bug 546521 =

This introduces a new method POTMsgSet.submitSuggestion, which can take over the work of updateTranslation for just one, limited scenario: suggesting a translation. Unlike updateTranslation, the method assumes that sanitization and validation of the translations has happened at the call site (which is something Henning is working on).

At the head of the diff you may notice an unrelated added line in the interface that was missing for some reason. Henning noticed this earlier today.

I tried giving submitSuggestion language/variant parameters instead of a pofile, but it turned out we also needed the context of the pofile's template in order to assign karma.

Speaking of karma, the test introduces a helper class called KarmaListener that we can turn into a reusable helper and incorporate into our TestCase class as needed. It records selected karma events. There's nothing translations-specific to this.

No lint.

To test,
{{{
./bin/test -vv -t TestPOTMsgSet_submitSuggestion
}}}

No lint.

Jeroen

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :
Download full text (5.1 KiB)

> === modified file 'lib/lp/translations/model/potmsgset.py'
> --- lib/lp/translations/model/potmsgset.py 2010-03-23 15:39:12
+0000
> +++ lib/lp/translations/model/potmsgset.py 2010-03-25 00:11:17
+0000
> @@ -888,6 +888,36 @@
> matching_message.sync()
> return matching_message
>
> + def submitSuggestion(self, pofile, submitter, new_translations):
> + """See `IPOTMsgSet`."""
> + if self.is_translation_credit:
> + # We don't support suggestions on credits messages.
> + return None
> +
> + potranslations = self._findPOTranslations(new_translations)
> +
> + existing_message = self._findTranslationMessage(
> + pofile, potranslations, pofile.plural_forms)
> + if existing_message is not None:
> + return existing_message

In the end you still included this logic as part of submitSuggestion? I
guess we can move it out later if it turns out that's what we want.

> === modified file 'lib/lp/translations/tests/test_potmsgset.py'
> @@ -1267,5 +1271,274 @@
> self.assertEqual(credits_type,
credits.translation_credits_type)
>
>
> +class KarmaListener:

Any reason not to put this inside lib/lp/registry/tests/karma.py?

> +class TestPOTMsgSet_submitSuggestion(TestCaseWithFactory):
> + """Test `POTMsgSet.submitSuggestion`."""
> +
> + layer = ZopelessDatabaseLayer
> +
> + def _makePOFileAndPOTMsgSet(self, msgid=None, with_plural=False):

In general, if you find that you need such a method, we might probably
need it in other cases as well. So, why not put it into the factory?

> + """Set up a `POFile` with `POTMsgSet`."""
> + pofile = self.factory.makePOFile('nl')
> + if msgid is None:
> + singular_text = self.factory.getUniqueString()
> + else:
> + singular_text = msgid
> + if with_plural:
> + plural_text = self.factory.getUniqueString()
> + else:
> + plural_text = None
> + potmsgset = self.factory.makePOTMsgSet(
> + pofile.potemplate, singular=singular_text,
plural=plural_text)
> +

Some extra whitespace here.

> + return pofile, potmsgset
> +
> + def _suggest(self, pofile, potmsgset, translations):
> + """Convenience shorthand for submitSuggestion."""
> + return potmsgset.submitSuggestion(
> + pofile, pofile.potemplate.owner, translations)

I believe this reduced the usefulness of these tests as a documentation
for submitSuggestion() method. And yet, you have added no documentation
whatsoever.

> + def test_plural_forms(self):
> + pofile, potmsgset =
self._makePOFileAndPOTMsgSet(with_plural=True)
> + translations = {
> + 0: self.factory.getUniqueString(),
> + 1: self.factory.getUniqueString(),
> + }
> +
> + suggestion = self._suggest(pofile, potmsgset, translations)
> + for form, translation in translations.iteritems():
> + self.assertEqual(
> + translation,
> + getattr(suggestion, 'msgstr%d' % form).translation)
> + for form in xrange(2, TranslationConstants.MAX_PLUR...

Read more...

review: Needs Fixing (code)
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

See revision 9132 above:
 * Renamed lp.registry.tests.karma to lp.testing.karma to deal with import problems.
 * Renamed KarmaListener to KarmaRecorder, moved into lp.testing.karma.
 * Made KarmaRecorder a bit more flexible, turned existing KarmaAssignedEventListener into a subclass.
 * Moved set_branding from canonical.launchpad.ftests to a new module lp.testing.branding to deal with import problems.
 * Moved makePOFileAndPOTMsgSet into the factory.
 * Removed test helper _suggest, calling submitSuggestion directly instead.
 * Used the factory to create TranslationMessages in the test, instead of updateTranslation.
 * Unrolled the poorly legible test loop. Don't really need to test _all_ possible plural forms.

Jeroen

Revision history for this message
Данило Шеган (danilo) wrote :

All good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches