← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~danilo/launchpad/kill-updatetranslation-doctests into lp:launchpad/db-devel

 

Данило Шеган has proposed merging lp:~danilo/launchpad/kill-updatetranslation-doctests into lp:launchpad/db-devel with lp:~danilo/launchpad/kill-updatetranslation as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~danilo/launchpad/kill-updatetranslation-doctests/+merge/44962

= Kill updateTranslation calls =

This kills updateTranslation calls in a few more doctests.  Also migrate TM.isHidden.

== Tests ==

Run the tests themselves:

 bin/test -cvvm lp.translations -t doc.pofile.txt -t doc.rosetta-karma.txt -t doc.translationmessage.txt

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/doc/pofile.txt
  lib/lp/translations/doc/rosetta-karma.txt
  lib/lp/translations/doc/translationmessage.txt
  lib/lp/translations/model/potmsgset.py
  lib/lp/translations/model/translationmessage.py

-- 
https://code.launchpad.net/~danilo/launchpad/kill-updatetranslation-doctests/+merge/44962
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~danilo/launchpad/kill-updatetranslation-doctests into lp:launchpad/db-devel.
=== modified file 'lib/lp/translations/doc/pofile.txt'
--- lib/lp/translations/doc/pofile.txt	2010-12-09 19:49:36 +0000
+++ lib/lp/translations/doc/pofile.txt	2010-12-31 17:15:02 +0000
@@ -86,8 +86,9 @@
     ...             if len(plural) > 20:
     ...                plural = plural[:17] + "..."
     ...         if pofile is not None:
-    ...             translation = potmsgset.getCurrentTranslationMessage(
-    ...                 pofile.potemplate, pofile.language).translations[0]
+    ...             translation = potmsgset.getCurrentTranslation(
+    ...                 pofile.potemplate, pofile.language,
+    ...                 pofile.potemplate.translation_side).translations[0]
     ...             if len(translation) > 20:
     ...                 translation = translation[:17] + "..."
     ...         print "%2d. %-20s   %-20s   %-20s" % (
@@ -545,8 +546,9 @@
 
     >>> potmsgset = pofile_sr.potemplate.getOrCreateSharedPOTMsgSet(
     ...     singular_text=msgid, plural_text=msgid_plural)
-    >>> print potmsgset.getCurrentTranslationMessage(
-    ...     pofile_sr.potemplate, pofile_sr.language)
+    >>> print potmsgset.getCurrentTranslation(
+    ...     pofile_sr.potemplate, pofile_sr.language,
+    ...     pofile_sr.potemplate.translation_side)
     None
 
 Is time to create it.  We need some extra privileges here.
@@ -558,9 +560,9 @@
     >>> translations = {0: u''}
     >>> is_current_upstream = False
     >>> lock_timestamp = datetime.datetime.now(UTC)
-    >>> translation_message = potmsgset.updateTranslation(
-    ...     pofile_sr, rosetta_experts, translations, is_current_upstream,
-    ...     lock_timestamp)
+    >>> translation_message = factory.makeCurrentTranslationMessage(
+    ...     pofile_sr, potmsgset, rosetta_experts, translations=translations,
+    ...     current_other=is_current_upstream)
 
 As we can see, is the msgid we were looking for.
 
@@ -659,8 +661,9 @@
     ...     print "%-10s %-5s %-10s %-11s" % (
     ...         "msgid", "form", "translat.", "Has plurals")
     ...     for potmsgset in potmsgsets:
-    ...         translationmessage = potmsgset.getCurrentTranslationMessage(
-    ...             pofile.potemplate, pofile.language)
+    ...         translationmessage = potmsgset.getCurrentTranslation(
+    ...             pofile.potemplate, pofile.language,
+    ...             pofile.potemplate.translation_side)
     ...         msgid = potmsgset.msgid_singular.msgid
     ...         if len(msgid) > 10:
     ...             msgid = msgid[:7] + '...'
@@ -743,8 +746,9 @@
 
     >>> potmsgset = alsa_template.getPOTMsgSetByMsgIDText(
     ...     u'translation-credits')
-    >>> current = potmsgset.getCurrentTranslationMessage(
-    ...     alsa_template, alsa_translation.language)
+    >>> current = potmsgset.getCurrentTranslation(
+    ...     alsa_template, alsa_translation.language,
+    ...     alsa_template.translation_side)
     >>> print current.translations
     [u'This is a dummy translation so that
     the credits are counted as translated.']
@@ -752,28 +756,28 @@
 If we submit an upstream translation, the translation for this message
 is updated.
 
-    >>> new_credits = potmsgset.updateTranslation(
-    ...     alsa_translation, alsa_translation.owner,
-    ...     {0: u'Happy translator'}, is_current_upstream=True,
-    ...     lock_timestamp=datetime.datetime.now(UTC))
+    >>> new_credits = factory.makeCurrentTranslationMessage(
+    ...     alsa_translation, potmsgset, alsa_translation.owner,
+    ...     translations={0: u'Happy translator'}, current_other=True)
     >>> flush_database_updates()
-    >>> current = potmsgset.getCurrentTranslationMessage(
-    ...     alsa_template, alsa_translation.language)
+    >>> current = potmsgset.getCurrentTranslation(
+    ...     alsa_template, alsa_translation.language,
+    ...     alsa_template.translation_side)
     >>> print current.translations
     [u'Happy translator']
 
 If we submit non-upstream translation, it's rejected.
 
-    >>> no_credits = potmsgset.updateTranslation(
+    >>> no_credits = potmsgset.submitSuggestion(
     ...     alsa_translation, alsa_translation.owner,
-    ...     {0: u'Unhappy translator'}, is_current_upstream=False,
-    ...     lock_timestamp=datetime.datetime.now(UTC))
+    ...     {0: u'Unhappy translator'})
     >>> print no_credits
     None
 
     >>> flush_database_updates()
-    >>> current = potmsgset.getCurrentTranslationMessage(
-    ...     alsa_template, alsa_translation.language)
+    >>> current = potmsgset.getCurrentTranslation(
+    ...     alsa_template, alsa_translation.language,
+    ...     alsa_template.translation_side)
     >>> print current.translations
     [u'Happy translator']
 

=== modified file 'lib/lp/translations/doc/rosetta-karma.txt'
--- lib/lp/translations/doc/rosetta-karma.txt	2010-12-02 16:13:51 +0000
+++ lib/lp/translations/doc/rosetta-karma.txt	2010-12-31 17:15:02 +0000
@@ -297,11 +297,11 @@
     >>> by_maintainer = False
 
 And we can see as he won't get any karma activity from that, otherwise it'd be
-printed after the call to updateTranslationSet().
+printed after the call to set current translation.
 
-    >>> translationmessage = potmsgset.updateTranslation(
-    ...     pofile, no_priv, new_translations, by_maintainer,
-    ...     lock_timestamp=datetime.datetime.now(UTC))
+    >>> translationmessage = factory.makeCurrentTranslationMessage(
+    ...     pofile, potmsgset, no_priv, translations=new_translations,
+    ...     current_other=by_maintainer)
     >>> flush_database_caches()
 
 But now, he will provide a new suggestion.
@@ -314,9 +314,8 @@
     >>> potemplate = POTemplate.get(1)
     >>> pofile = potemplate.getPOFileByLang('es')
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'foo')
-    >>> translationmessage = potmsgset.updateTranslation(
-    ...     pofile, no_priv, new_translations, by_maintainer,
-    ...     lock_timestamp=datetime.datetime.now(UTC))
+    >>> translationmessage = potmsgset.submitSuggestion(
+    ...     pofile, no_priv, new_translations)
     Karma added: action=translationsuggestionadded, product=evolution
     >>> transaction.commit()
 
@@ -333,25 +332,25 @@
     >>> pofile = potemplate.getPOFileByLang('es')
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'foo')
     >>> new_translations = {0: u'somethingelse'}
-    >>> translationmessage = potmsgset.updateTranslation(
-    ...     pofile, kurem, new_translations, by_maintainer,
-    ...     lock_timestamp=datetime.datetime.now(UTC))
+    >>> translationmessage = potmsgset.findTranslationMessage(
+    ...     pofile, new_translations)
+    >>> translationmessage.approve(pofile, kurem)
     Karma added: action=translationsuggestionapproved, product=evolution
     Karma added: action=translationreview, product=evolution
     >>> transaction.commit()
 
 Finally, this reviewer, is going to add a new translation directly. He should
-get karma for his autoapproved translation.
+get karma for his translation, but not for a review.
 
     >>> kurem = personset.getByEmail('kurem@xxxxxxxxx')
     >>> potemplate = POTemplate.get(1)
     >>> pofile = potemplate.getPOFileByLang('es')
     >>> potmsgset = potemplate.getPOTMsgSetByMsgIDText(u'foo')
     >>> new_translations = {0: u'changed again'}
-    >>> translationmessage = potmsgset.updateTranslation(
-    ...     pofile, kurem, new_translations, by_maintainer,
-    ...     lock_timestamp=datetime.datetime.now(UTC))
-    Karma added: action=translationsuggestionapproved, product=evolution
+    >>> translationmessage = potmsgset.submitSuggestion(
+    ...     pofile, kurem, new_translations)
+    Karma added: action=translationsuggestionadded, product=evolution
+    >>> translationmessage.approve(pofile, kurem)
     >>> transaction.commit()
 
 

=== modified file 'lib/lp/translations/doc/translationmessage.txt'
--- lib/lp/translations/doc/translationmessage.txt	2010-12-10 10:53:44 +0000
+++ lib/lp/translations/doc/translationmessage.txt	2010-12-31 17:15:02 +0000
@@ -101,10 +101,6 @@
 
     >>> import transaction
 
-    >>> from datetime import datetime
-    >>> import pytz
-    >>> UTC = pytz.timezone('UTC')
-
 We are working with a product with translations being restricted to
 a single translation group.
 
@@ -134,9 +130,8 @@
     >>> nopriv = getUtility(IPersonSet).getByName('no-priv')
     >>> login('no-priv@xxxxxxxxxxxxx')
 
-    >>> new_suggestion = potmsgset.updateTranslation(
-    ...     pofile_sr, nopriv, {0: u'suggestion'},
-    ...     is_current_upstream=False, lock_timestamp=datetime.now(UTC))
+    >>> new_suggestion = potmsgset.submitSuggestion(
+    ...     pofile_sr, nopriv, {0: u'suggestion'})
     >>> transaction.commit()
     >>> new_suggestion.isHidden(pofile_sr)
     False
@@ -147,9 +142,9 @@
 
 An imported translation is not hidden when submitted.
 
-    >>> imported_translation = potmsgset.updateTranslation(
-    ...     pofile_sr, foobar, {0: u'foo'},
-    ...     is_current_upstream=True, lock_timestamp=datetime.now(UTC))
+    >>> imported_translation = factory.makeCurrentTranslationMessage(
+    ...     pofile_sr, potmsgset, foobar, current_other=True,
+    ...     translations={ 0: 'imported' })
     >>> transaction.commit()
     >>> imported_translation.isHidden(pofile_sr)
     False
@@ -161,9 +156,9 @@
 
 A newly submitted non-imported translation is not hidden either.
 
-    >>> current_translation = potmsgset.updateTranslation(
-    ...     pofile_sr, foobar, {0: u'bar'},
-    ...     is_current_upstream=False, lock_timestamp=datetime.now(UTC))
+    >>> current_translation = factory.makeCurrentTranslationMessage(
+    ...     pofile_sr, potmsgset, foobar, current_other=False,
+    ...     translations={ 0: 'current' })
     >>> transaction.commit()
     >>> current_translation.isHidden(pofile_sr)
     False
@@ -175,9 +170,9 @@
 
 If a new current translation is submitted, the old one is hidden.
 
-    >>> new_current_translation = potmsgset.updateTranslation(
-    ...     pofile_sr, foobar, {0: u'new'},
-    ...     is_current_upstream=False, lock_timestamp=datetime.now(UTC))
+    >>> new_current_translation = factory.makeCurrentTranslationMessage(
+    ...     pofile_sr, potmsgset, foobar, current_other=False,
+    ...     translations={ 0 : 'new' })
     >>> transaction.commit()
     >>> new_current_translation.isHidden(pofile_sr)
     False
@@ -195,9 +190,8 @@
     >>> nopriv = getUtility(IPersonSet).getByName('no-priv')
     >>> login('no-priv@xxxxxxxxxxxxx')
 
-    >>> another_suggestion = potmsgset.updateTranslation(
-    ...     pofile_sr, nopriv, {0: u'another suggestion'},
-    ...     is_current_upstream=False, lock_timestamp=datetime.now(UTC))
+    >>> another_suggestion = potmsgset.submitSuggestion(
+    ...     pofile_sr, nopriv, {0: u'another suggestion'})
     >>> transaction.commit()
     >>> another_suggestion.isHidden(pofile_sr)
     False
@@ -214,16 +208,16 @@
 For a regular single-form message, that's always one.
 
     >>> login('foo.bar@xxxxxxxxxxxxx')
-    >>> message = potmsgset.getCurrentTranslationMessage(potemplate, serbian)
+    >>> message = potmsgset.getCurrentTranslation(
+    ...     potemplate, serbian, potemplate.translation_side)
     >>> message.translations
     [u'new']
 
 If the message has no actual translation, the translations attribute
 contains just a None.
 
-    >>> empty_message = potmsgset.updateTranslation(
-    ...     pofile_sr, foobar, {}, is_current_upstream=False,
-    ...     lock_timestamp=datetime.now(UTC))
+    >>> empty_message = potmsgset.submitSuggestion(
+    ...     pofile_sr, foobar, {})
     >>> empty_message.translations
     [None]
 
@@ -242,9 +236,8 @@
 If the message does not translate all those forms, we get None entries
 in the list.
 
-    >>> empty_message = plural_potmsgset.updateTranslation(
-    ...     pofile_sr, foobar, {}, is_current_upstream=False,
-    ...     lock_timestamp=datetime.now(UTC))
+    >>> empty_message = plural_potmsgset.submitSuggestion(
+    ...     pofile_sr, foobar, {})
     >>> empty_message.translations
     [None, None, None]
 

=== modified file 'lib/lp/translations/model/potmsgset.py'
--- lib/lp/translations/model/potmsgset.py	2010-12-17 10:30:55 +0000
+++ lib/lp/translations/model/potmsgset.py	2010-12-31 17:15:02 +0000
@@ -990,7 +990,6 @@
         if self.is_translation_credit:
             # We don't support suggestions on credits messages.
             return None
-
         potranslations = self._findPOTranslations(new_translations)
 
         existing_message = self._findMatchingTranslationMessage(

=== modified file 'lib/lp/translations/model/translationmessage.py'
--- lib/lp/translations/model/translationmessage.py	2010-12-17 10:30:55 +0000
+++ lib/lp/translations/model/translationmessage.py	2010-12-31 17:15:02 +0000
@@ -324,8 +324,9 @@
         # more recent than the date of suggestion's date_created),
         # it is hidden.
         # If it has not been reviewed yet, it's not hidden.
-        current = self.potmsgset.getCurrentTranslationMessage(
-            pofile.potemplate, self.language)
+        current = self.potmsgset.getCurrentTranslation(
+            pofile.potemplate, self.language,
+            pofile.potemplate.translation_side)
         # If there is no current translation, none of the
         # suggestions have been reviewed, so they are all shown.
         if current is None: