← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/launchpad/bug-662552-get-tm-or-dummy into lp:launchpad/devel

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/launchpad/bug-662552-get-tm-or-dummy into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers): code
Related bugs:
  #662552 Timeout error trying to access the translation interface
  https://bugs.launchpad.net/bugs/662552


= Bug 662552: Streamline getCurrentDummyTranslationMessage =

We're getting timeouts on the POFile:+translate page, so I'm fixing up a bunch of relatively non-invasive things that it wastes time on.

In this case, it's IPOTMsgSet.getCurrentDummyTranslationMessage.  This method returns a DummyTranslationMessage.  With a few easily fixed exceptions in one doctest, every use of this method follows the same basic pattern:

    message = potmsgset.getCurrentTranslationMessage(
        pofile.potemplate, pofile.language)
    if message is None:
        message = potmsgset.getCurrentDummyTranslationMessage(
            pofile.potemplate, pofile.language)
    else:
        message.setPOFile(pofile)

(The message.setPOFile() part is a hack to get around the fact that some code still relies on TranslationMessage.pofile even though it's been removed from the schema; we now use an alternate which is meant to be valid only within the request).

In this branch I replace the entire usage pattern with a single new method:

    message = potmsgset.getCurrentTranslationMessageOrDummy(
        pofile)

I also eliminated a few assertions that guarded the integrity of this pattern along the way, doing several redundant database lookups to ensure that there is no real current translation message before creating a dummy.  That pattern is now explicit, and enshrined in a single place in the code.

About half of the branch is actually lint cleanup.  There's a bit of lint left, but that's all related to blank lines around free-standing comment blocks.  I'm not yet convinced that "make lint" has a creditable complaint.


Jeroen
-- 
https://code.launchpad.net/~jtv/launchpad/bug-662552-get-tm-or-dummy/+merge/39467
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/launchpad/bug-662552-get-tm-or-dummy into lp:launchpad/devel.
=== modified file 'lib/lp/translations/browser/pofile.py'
--- lib/lp/translations/browser/pofile.py	2010-08-31 11:11:09 +0000
+++ lib/lp/translations/browser/pofile.py	2010-10-27 18:48:52 +0000
@@ -87,20 +87,7 @@
             raise NotFoundError(
                 "%r is not a valid sequence number." % name)
 
-        # Need to check in our database whether we have already the requested
-        # TranslationMessage.
-        translationmessage = potmsgset.getCurrentTranslationMessage(
-            self.context.potemplate, self.context.language)
-
-        if translationmessage is not None:
-            # Already have a valid POMsgSet entry, just return it.
-            translationmessage.setPOFile(self.context)
-            return translationmessage
-        else:
-            # Get a fake one so we don't create new TranslationMessage just
-            # because someone is browsing the web.
-            return potmsgset.getCurrentDummyTranslationMessage(
-                self.context.potemplate, self.context.language)
+        return potmsgset.getCurrentTranslationMessageOrDummy(self.context)
 
 
 class POFileFacets(POTemplateFacets):
@@ -846,14 +833,8 @@
                 "POTMsgSets on page not in ascending sequence order")
             last = potmsgset
 
-            translationmessage = potmsgset.getCurrentTranslationMessage(
-                self.context.potemplate, self.context.language)
-            if translationmessage is None:
-                translationmessage = (
-                    potmsgset.getCurrentDummyTranslationMessage(
-                        self.context.potemplate, self.context.language))
-            else:
-                translationmessage.setPOFile(self.context)
+            translationmessage = (
+                potmsgset.getCurrentTranslationMessageOrDummy(self.context))
             view = self._prepareView(
                 CurrentTranslationMessageView, translationmessage,
                 self.errors.get(potmsgset))

=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
--- lib/lp/translations/browser/tests/translationmessage-views.txt	2010-10-18 22:24:59 +0000
+++ lib/lp/translations/browser/tests/translationmessage-views.txt	2010-10-27 18:48:52 +0000
@@ -1,4 +1,5 @@
-= TranslationMessage View =
+TranslationMessage View
+=======================
 
 On this section, we are going to test the view class for an
 ITranslationMessage object.
@@ -11,13 +12,14 @@
     >>> from lp.services.worlddata.interfaces.language import ILanguageSet
     >>> from lp.translations.publisher import TranslationsLayer
 
-All the tests will be submitted as comming from Kurem, an editor for the POFile
-that we are going to edit.
+All the tests will be submitted as comming from Kurem, an editor for the
+POFile that we are going to edit.
 
     >>> login('kurem@xxxxxxxxx')
 
 
-== No plural forms ==
+No plural forms
+---------------
 
 We are going to see what happens if we get an entry for a language
 without the plural form information.
@@ -29,8 +31,7 @@
     >>> potmsgset = pofile_tlh.potemplate.getPOTMsgSetByMsgIDText(
     ...     u'evolution addressbook')
     >>> current_translationmessage = (
-    ...     potmsgset.getCurrentDummyTranslationMessage(
-    ...         pofile_tlh.potemplate, pofile_tlh.language))
+    ...     potmsgset.getCurrentTranslationMessageOrDummy(pofile_tlh))
     >>> translationmessage_page_view = create_view(
     ...     current_translationmessage, "+translate", layer=TranslationsLayer)
     >>> translationmessage_page_view.initialize()
@@ -46,7 +47,8 @@
     False
 
 
-== Basic checks ==
+Basic checks
+------------
 
 Now, we will use objects that we have in our database, instead of
 dummy ones.
@@ -79,7 +81,8 @@
     False
 
 
-== The subview: TranslationMessageView ==
+The subview: TranslationMessageView
+-----------------------------------
 
 For the next tests, we grab the subview which is what holds information
 that pertains to the POMsgSet rendering itself:
@@ -145,7 +148,8 @@
     AssertionError: There is no plural form #1 for Spanish (es) language
 
 
-== Web presentation ==
+Web presentation
+----------------
 
 Some characters are presented specially in the Web interface, and there are
 functions to determine whether to advise translators about their presence.
@@ -226,7 +230,8 @@
     >>> transaction.commit()
 
 
-== Submitting translations ==
+Submitting translations
+-----------------------
 
 A new translation is submitted through the view.
 
@@ -330,7 +335,8 @@
     [u'Foo']
 
 
-== Bogus translation submission ==
+Bogus translation submission
+----------------------------
 
 What would happen if we get a submit for another msgset that isn't being
 considered?
@@ -362,7 +368,8 @@
     True
 
 
-== TranslationMessageSuggestions ==
+TranslationMessageSuggestions
+-----------------------------
 
 This class keeps all suggestions available for a concrete
 ITranslationMessage.
@@ -529,7 +536,8 @@
     0
 
 
-== Sequence number of new shared POTMsgSets ==
+Sequence number of new shared POTMsgSets
+----------------------------------------
 
 Newly added shared POTMsgSets don't have their sequence field set, but
 they do have sequence number when being displayed with translation
@@ -556,7 +564,9 @@
     >>> subview.sequence
     1
 
-== Ordering with unset potemplate values ==
+
+Ordering with unset potemplate values
+-------------------------------------
 
 Fix for bug #371560: can be removed after message sharing cleanup is done.
 Code still uses potmsgset.potemplate when getting a sequence number, and
@@ -596,7 +606,9 @@
     ...     server_url=server_url)
     >>> pofile_view.initialize()
 
-== Sharing and diverging messages ==
+
+Sharing and diverging messages
+------------------------------
 
 When there is an existing shared translation, one gets an option
 to diverge it when on a zoomed-in view (when looking that particular

=== modified file 'lib/lp/translations/browser/translationmessage.py'
--- lib/lp/translations/browser/translationmessage.py	2010-09-03 16:01:01 +0000
+++ lib/lp/translations/browser/translationmessage.py	2010-10-27 18:48:52 +0000
@@ -67,10 +67,6 @@
     )
 from lp.translations.interfaces.translationsperson import ITranslationsPerson
 
-#
-# Exceptions and helper classes
-#
-
 
 class POTMsgSetBatchNavigator(BatchNavigator):
 
@@ -143,9 +139,6 @@
         return contents
 
 
-#
-# Standard UI classes
-#
 class CurrentTranslationMessageFacets(POTemplateFacets):
     usedfor = ITranslationMessage
 
@@ -176,9 +169,6 @@
         return Link('../+export', text, icon='download')
 
 
-#
-# Views
-#
 class CurrentTranslationMessageIndexView:
     """A view to forward to the translation form."""
 
@@ -298,16 +288,16 @@
 
         if self.request.method == 'POST':
             if self.user is None:
-                raise UnexpectedFormData, (
-                    'Anonymous users or users who are not accepting our '
-                    'licensing terms cannot do POST submissions.')
+                raise UnexpectedFormData(
+                    "Anonymous users or users who are not accepting our "
+                    "licensing terms cannot do POST submissions.")
             translations_person = ITranslationsPerson(self.user)
             if (translations_person.translations_relicensing_agreement
                     is not None and
                 not translations_person.translations_relicensing_agreement):
-                raise UnexpectedFormData, (
-                    'Users who do not agree to licensing terms '
-                    'cannot do POST submissions.')
+                raise UnexpectedFormData(
+                    "Users who do not agree to licensing terms "
+                    "cannot do POST submissions.")
             try:
                 # Try to get the timestamp when the submitted form was
                 # created. We use it to detect whether someone else updated
@@ -318,9 +308,9 @@
             except zope_datetime.DateTimeError:
                 # invalid format. Either we don't have the timestamp in the
                 # submitted form or it has the wrong format.
-                raise UnexpectedFormData, (
-                    'We didn\'t find the timestamp that tells us when was'
-                    ' generated the submitted form.')
+                raise UnexpectedFormData(
+                    "We didn't find the timestamp that tells us when was"
+                    " generated the submitted form.")
 
             # Check if this is really the form we are listening for..
             if self.request.form.get("submit_translations"):
@@ -543,7 +533,7 @@
         elif fallback_language is not None:
             # If there's a standard alternative language and no
             # user-specified language was provided, preselect it.
-            alternative_language =  fallback_language
+            alternative_language = fallback_language
             second_lang_code = fallback_language.code
         else:
             # The second_lang_code is None and there is no fallback_language.
@@ -685,12 +675,8 @@
                 # current translation, suggestion or the new translation
                 # field.
                 current_translation_message = (
-                    potmsgset.getCurrentTranslationMessage(
-                        self.pofile.potemplate, self.pofile.language))
-                if current_translation_message is None:
-                    current_translation_message = (
-                        potmsgset.getCurrentDummyTranslationMessage(
-                            self.pofile.potemplate, self.pofile.language))
+                    potmsgset.getCurrentTranslationMessageOrDummy(
+                        self.pofile))
                 if (selected_translation_key !=
                     msgset_ID_LANGCODE_translation_PLURALFORM_new):
                     # It's either current translation or an existing
@@ -890,14 +876,6 @@
     template = ViewPageTemplateFile(
         '../templates/currenttranslationmessage-translate-one.pt')
 
-    # Relevant instance variables:
-    #   self.translations
-    #   self.error
-    #   self.sec_lang
-    #   self.second_lang_potmsgset
-    #   self.suggestion_blocks
-    #   self.pluralform_indices
-
     def __init__(self, current_translation_message, request,
                  plural_indices_to_store, translations, force_suggestion,
                  force_diverge, error, second_lang_code, form_is_writeable):
@@ -1053,7 +1031,7 @@
 
             diverged_and_have_shared = (
                 self.context.potemplate is not None and
-                self.shared_translationmessage is not None) 
+                self.shared_translationmessage is not None)
             if diverged_and_have_shared:
                 pofile = self.shared_translationmessage.ensureBrowserPOFile()
                 if pofile is None:
@@ -1152,10 +1130,10 @@
 
     def _setOnePOFile(self, messages):
         """Return a list of messages that all have a browser_pofile set.
-        
+
         If a pofile cannot be found for a message, it is not included in
         the resulting list.
-        """ 
+        """
         result = []
         for message in messages:
             if message.browser_pofile is None:
@@ -1167,7 +1145,7 @@
                     message.setPOFile(pofile)
             result.append(message)
         return result
-    
+
     def _buildAllSuggestions(self):
         """Builds all suggestions and puts them into suggestions_block.
 
@@ -1503,7 +1481,6 @@
         return "%s_dismissable_button" % self.html_id
 
 
-
 class CurrentTranslationMessageZoomedView(CurrentTranslationMessageView):
     """A view that displays a `TranslationMessage`, but zoomed in.
 
@@ -1533,11 +1510,6 @@
         return None
 
 
-#
-# Pseudo-content class
-#
-
-
 class TranslationMessageSuggestions:
     """See `ITranslationMessageSuggestions`."""
 
@@ -1591,6 +1563,7 @@
 class Submission:
     """A submission generated from a TranslationMessage"""
 
+
 def convert_translationmessage_to_submission(
     message, current_message, plural_form, pofile, legal_warning_needed,
     is_empty=False, packaged=False, local_to_pofile=False):

=== modified file 'lib/lp/translations/doc/canonical_url_examples.txt'
--- lib/lp/translations/doc/canonical_url_examples.txt	2010-07-30 12:56:27 +0000
+++ lib/lp/translations/doc/canonical_url_examples.txt	2010-10-27 18:48:52 +0000
@@ -71,8 +71,8 @@
 Even for a dummy one.
 
     >>> potmsgset = potemplate.getPOTMsgSetBySequence(20)
-    >>> translationmessage = potmsgset.getCurrentDummyTranslationMessage(
-    ...     pofile.potemplate, pofile.language)
+    >>> translationmessage = potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     pofile)
     >>> print canonical_url(translationmessage)
     http://transl.../hoary/+source/evolution/+pots/evolution-2.2/es/20
 
@@ -109,8 +109,8 @@
 Even for a dummy PO msgset
 
     >>> potmsgset = potemplate.getPOTMsgSetBySequence(20)
-    >>> translationmessage = potmsgset.getCurrentDummyTranslationMessage(
-    ...     pofile.potemplate, pofile.language)
+    >>> translationmessage = potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     pofile)
     >>> print canonical_url(translationmessage)
     http://translations.../evolution/trunk/+pots/evolution-2.2/es/20
 

=== modified file 'lib/lp/translations/doc/potmsgset.txt'
--- lib/lp/translations/doc/potmsgset.txt	2010-10-26 10:31:37 +0000
+++ lib/lp/translations/doc/potmsgset.txt	2010-10-27 18:48:52 +0000
@@ -478,8 +478,8 @@
     ...     evolution_potemplate, pt_BR_dummypofile.language)
     >>> print current
     None
-    >>> pt_BR_dummy_current = potmsgset.getCurrentDummyTranslationMessage(
-    ...     evolution_potemplate, pt_BR_dummypofile.language)
+    >>> pt_BR_dummy_current = potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     pt_BR_dummypofile)
     >>> pt_BR_dummy_current.plural_forms
     1
     >>> pt_BR_dummy_current.translations
@@ -508,8 +508,8 @@
     >>> print apa_dummypofile.language.pluralforms
     None
     >>> apa_dummy_current = (
-    ...     plural_potmsgset.getCurrentDummyTranslationMessage(
-    ...         evolution_potemplate, apa_dummypofile.language))
+    ...     plural_potmsgset.getCurrentTranslationMessageOrDummy(
+    ...         apa_dummypofile))
     >>> apa_dummy_current.plural_forms
     2
     >>> apa_dummy_current.translations
@@ -519,8 +519,9 @@
 
     >>> language_ru = getUtility(ILanguageSet).getLanguageByCode('ru')
     >>> ru_dummypofile = evolution_potemplate.getDummyPOFile(language_ru)
-    >>> ru_dummy_current = plural_potmsgset.getCurrentDummyTranslationMessage(
-    ...     evolution_potemplate, ru_dummypofile.language)
+    >>> ru_dummy_current = (
+    ...     plural_potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     	ru_dummypofile))
 
     >>> print ru_dummypofile.language.pluralforms
     3
@@ -925,29 +926,6 @@
     0
 
 
-POTMsgSet.getCurrentDummyTranslationMessage
--------------------------------------------
-
-Sometimes, there are POTMsgSet objects with no translations to a language,
-and we need to get dummy objects which emulate them to do read operations.
-This method give us such dummy objects.
-
-    >>> spanish_in_mexico = getUtility(ILanguageSet).getLanguageByCode(
-    ...     'es_MX')
-    >>> potmsgset.getCurrentDummyTranslationMessage(
-    ...     evolution_potemplate, spanish_in_mexico) is None
-    False
-
-But, if we already have a TranslationMessage for a POTMsgSet in our database,
-and we request a dummy one, that's broken and we detect it.
-
-    >>> potmsgset.getCurrentDummyTranslationMessage(
-    ...     evolution_potemplate, spanish)
-    Traceback (most recent call last):
-    ...
-    AssertionError: There is already a translation message ...
-
-
 Suggestions for translator credits
 ----------------------------------
 

=== modified file 'lib/lp/translations/doc/translationmessage.txt'
--- lib/lp/translations/doc/translationmessage.txt	2010-10-18 22:24:59 +0000
+++ lib/lp/translations/doc/translationmessage.txt	2010-10-27 18:48:52 +0000
@@ -10,6 +10,7 @@
     >>> from lp.translations.interfaces.translationmessage import (
     ...     ITranslationMessage)
     >>> from lp.translations.interfaces.translator import ITranslatorSet
+    >>> from lp.translations.model.pofile import DummyPOFile
 
     >>> login('carlos@xxxxxxxxxxxxx')
     >>> pofile_es = factory.makePOFile(language_code='es')
@@ -18,16 +19,15 @@
 
 This class links the translations submitted by a translator with the
 associated POFile and POTMsgSet.  TranslationMessage and
-DummyTranslationMessage both implement ITranslationMessage interface:
+DummyTranslationMessage both implement ITranslationMessage:
 
     >>> translationmessage = factory.makeTranslationMessage(
     ...     potmsgset=potmsgset, pofile=pofile_es)
     >>> verifyObject(ITranslationMessage, translationmessage)
     True
 
-    >>> serbian = getUtility(ILanguageSet)['sr']
-    >>> dummy_message = potmsgset.getCurrentDummyTranslationMessage(
-    ...     potemplate, serbian)
+    >>> dummy_message = potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     factory.makePOFile())
     >>> verifyObject(ITranslationMessage, dummy_message)
     True
 
@@ -48,18 +48,19 @@
 the translation, no matter the number of plural forms defined for the
 language:
 
+    >>> serbian = getUtility(ILanguageSet)['sr']
     >>> serbian.pluralforms
     3
-    >>> current_sr = potmsgset.getCurrentDummyTranslationMessage(
-    ...     potemplate, serbian)
+    >>> current_sr = potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     DummyPOFile(potemplate, serbian))
     >>> current_sr.plural_forms
     1
 
     >>> divehi = getUtility(ILanguageSet)['dv']
     >>> print divehi.pluralforms
     None
-    >>> current_dv = potmsgset.getCurrentDummyTranslationMessage(
-    ...     potemplate, divehi)
+    >>> current_dv = potmsgset.getCurrentTranslationMessageOrDummy(
+    ...     DummyPOFile(potemplate, divehi))
     >>> current_dv.plural_forms
     1
 
@@ -73,8 +74,8 @@
     u'plural'
     >>> serbian.pluralforms
     3
-    >>> current_sr = potmsgset_plural.getCurrentDummyTranslationMessage(
-    ...     potemplate, serbian)
+    >>> current_sr = potmsgset_plural.getCurrentTranslationMessageOrDummy(
+    ...     DummyPOFile(potemplate, serbian))
     >>> current_sr.plural_forms
     3
 
@@ -83,8 +84,8 @@
 
     >>> print divehi.pluralforms
     None
-    >>> current_dv = potmsgset_plural.getCurrentDummyTranslationMessage(
-    ...     potemplate, divehi)
+    >>> current_dv = potmsgset_plural.getCurrentTranslationMessageOrDummy(
+    ...     DummyPOFile(potemplate, divehi))
     >>> current_dv.plural_forms
     2
 

=== modified file 'lib/lp/translations/interfaces/potmsgset.py'
--- lib/lp/translations/interfaces/potmsgset.py	2010-08-20 20:31:18 +0000
+++ lib/lp/translations/interfaces/potmsgset.py	2010-10-27 18:48:52 +0000
@@ -65,6 +65,7 @@
 class BrokenTextError(ValueError):
     """Exception raised when we detect values on a text that aren't valid."""
 
+
 class POTMsgSetInIncompatibleTemplatesError(Exception):
     """Raised when a POTMsgSet appears in multiple incompatible templates.
 
@@ -134,14 +135,13 @@
             queries that search for credits messages.
             """))
 
-    def getCurrentDummyTranslationMessage(potemplate, language):
-        """Return a DummyTranslationMessage for this message language.
-
-        :param potemplate: PO template you want a translation message for.
-        :param language: language we want a dummy translations for.
-
-        If a TranslationMessage for this language already exists,
-        an exception is raised.
+    def getCurrentTranslationMessageOrDummy(pofile):
+        """Return the current `TranslationMessage`, or a dummy.
+
+        :param pofile: PO template you want a translation message for.
+        :return: The current translation for `self` in `pofile`, if
+            there is one.  Otherwise, a `DummyTranslationMessage` for
+            `self` in `pofile`.
         """
 
     def getCurrentTranslationMessage(potemplate, language):

=== modified file 'lib/lp/translations/model/potmsgset.py'
--- lib/lp/translations/model/potmsgset.py	2010-10-27 07:56:41 +0000
+++ lib/lp/translations/model/potmsgset.py	2010-10-27 18:48:52 +0000
@@ -42,7 +42,6 @@
 from canonical.launchpad.interfaces.lpstorm import ISlaveStore
 from canonical.launchpad.readonly import is_read_only
 from lp.app.errors import UnexpectedFormData
-from lp.translations.interfaces.pofile import IPOFileSet
 from lp.translations.interfaces.potmsgset import (
     BrokenTextError,
     IPOTMsgSet,
@@ -237,18 +236,15 @@
         else:
             return self.msgid_plural.msgid
 
-    def getCurrentDummyTranslationMessage(self, potemplate, language):
+    def getCurrentTranslationMessageOrDummy(self, pofile):
         """See `IPOTMsgSet`."""
-
-        pofile = potemplate.getPOFileByLang(language.code)
-        if pofile is None:
-            pofileset = getUtility(IPOFileSet)
-            pofile = pofileset.getDummy(potemplate, language)
+        current = self.getCurrentTranslationMessage(
+            pofile.potemplate, pofile.language)
+        if current is None:
+            return DummyTranslationMessage(pofile, self)
         else:
-            assert self.getCurrentTranslationMessage(potemplate,
-                                                     language) is None, (
-                'There is already a translation message in our database.')
-        return DummyTranslationMessage(pofile, self)
+            current.setPOFile(pofile)
+            return current
 
     def _getUsedTranslationMessage(self, potemplate, language, current=True):
         """Get a translation message which is either used in

=== modified file 'lib/lp/translations/model/translationmessage.py'
--- lib/lp/translations/model/translationmessage.py	2010-10-04 22:56:09 +0000
+++ lib/lp/translations/model/translationmessage.py	2010-10-27 18:48:52 +0000
@@ -115,13 +115,6 @@
     implements(ITranslationMessage)
 
     def __init__(self, pofile, potmsgset):
-        # Check whether we already have a suitable TranslationMessage, in
-        # which case, the dummy one must not be used.
-        assert potmsgset.getCurrentTranslationMessage(
-            pofile.potemplate,
-            pofile.language) is None, (
-                'This translation message already exists in the database.')
-
         self.id = None
         self.browser_pofile = pofile
         self.potemplate = pofile.potemplate

=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
--- lib/lp/translations/tests/test_potmsgset.py	2010-10-26 10:31:37 +0000
+++ lib/lp/translations/tests/test_potmsgset.py	2010-10-27 18:48:52 +0000
@@ -13,17 +13,13 @@
 import pytz
 import transaction
 from zope.component import getUtility
-from zope.security.proxy import (
-    isinstance as zope_isinstance,
-    removeSecurityProxy,
-    )
+from zope.security.proxy import removeSecurityProxy
 
 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
 from canonical.testing.layers import ZopelessDatabaseLayer
 from lp.app.enums import ServiceUsage
 from lp.registry.interfaces.person import IPersonSet
 from lp.registry.interfaces.product import IProductSet
-from lp.services.worlddata.interfaces.language import ILanguageSet
 from lp.testing import TestCaseWithFactory
 from lp.translations.interfaces.potemplate import IPOTemplateSet
 from lp.translations.interfaces.potmsgset import (
@@ -165,31 +161,21 @@
         translation.potemplate = self.devel_potemplate
         self.assertEquals(potmsgset.singular_text, ENGLISH_STRING)
 
-    def test_getCurrentDummyTranslationMessage(self):
-        """Test that a DummyTranslationMessage is correctly returned."""
-
-        # When there is no POFile, we get a DummyTranslationMessage inside
-        # a DummyPOFile.
-        serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
-        dummy = self.potmsgset.getCurrentDummyTranslationMessage(
-            self.devel_potemplate, serbian)
-        self.assertTrue(zope_isinstance(dummy, DummyTranslationMessage))
-
-        # If a POFile exists, but there is no current translation message,
-        # a dummy translation message is returned.
-        sr_pofile = self.factory.makePOFile('sr', self.devel_potemplate)
-        dummy = self.potmsgset.getCurrentDummyTranslationMessage(
-            self.devel_potemplate, serbian)
-        self.assertTrue(zope_isinstance(dummy, DummyTranslationMessage))
-
-        # When there is a current translation message, an exception
-        # is raised.
-        translation = self.factory.makeTranslationMessage(
-            pofile=sr_pofile, potmsgset=self.potmsgset)
-        self.assertTrue(translation.is_current)
-        self.assertRaises(AssertionError,
-                          self.potmsgset.getCurrentDummyTranslationMessage,
-                          self.devel_potemplate, serbian)
+    def test_getCurrentTranslationMessageOrDummy_returns_real_tm(self):
+        pofile = self.factory.makePOFile('nl')
+        message = self.factory.makeTranslationMessage(
+            pofile=pofile, suggestion=False, is_imported=True)
+
+        self.assertEqual(
+            message,
+            message.potmsgset.getCurrentTranslationMessageOrDummy(pofile))
+
+    def test_getCurrentTranslationMessageOrDummy_returns_dummy_tm(self):
+        pofile = self.factory.makePOFile('nl')
+        potmsgset = self.factory.makePOTMsgSet(pofile.potemplate)
+
+        message = potmsgset.getCurrentTranslationMessageOrDummy(pofile)
+        self.assertIsInstance(message, DummyTranslationMessage)
 
     def test_getCurrentTranslationMessage(self):
         """Test how shared and diverged current translation messages