← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~danilo/launchpad/psl-tests-cleanup into lp:launchpad/devel

 

Данило Шеган has proposed merging lp:~danilo/launchpad/psl-tests-cleanup into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #612505 Clean-up productserieslanguage tests
  https://bugs.launchpad.net/bugs/612505


= Bug: #612505: tests cleanup =

A follow-up branch for https://code.edge.launchpad.net/~danilo/launchpad/translatedlanguage/+merge/30788

A simple test cleanup that removes tests that exist in the "shared" mixin tests now, and splits remaining tests further so it's mostly "test for one thing only".

= Tests =

bin/test -cvvt test_productserieslanguage -t test_translatedlanguage

= Demo & QA =

Make the test suite pass.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/tests/test_productserieslanguage.py

-- 
https://code.launchpad.net/~danilo/launchpad/psl-tests-cleanup/+merge/31531
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~danilo/launchpad/psl-tests-cleanup into lp:launchpad/devel.
=== modified file 'lib/lp/translations/tests/test_productserieslanguage.py'
--- lib/lp/translations/tests/test_productserieslanguage.py	2010-07-24 11:31:11 +0000
+++ lib/lp/translations/tests/test_productserieslanguage.py	2010-08-02 12:06:03 +0000
@@ -27,25 +27,26 @@
         self.productseries = self.factory.makeProductSeries()
         self.productseries.product.official_rosetta = True
 
-    def test_NoTemplatesNoTranslation(self):
+    def test_no_templates_no_translation(self):
         # There are no templates and no translations.
         self.assertEquals(self.productseries.productserieslanguages,
                           [])
 
-    def test_OneTemplateNoTranslation(self):
+    def test_one_template_no_translation(self):
         # There is a template and no translations.
         self.factory.makePOTemplate(productseries=self.productseries)
         self.assertEquals(self.productseries.productserieslanguages,
                           [])
 
-    def test_OneTemplateWithTranslations(self):
+    def test_one_template_with_pofile(self):
         # There is a template and one translation.
+        # With a single PO file, PSL optimizes this and
+        # provides a POFile directly through "pofile" attribute.
         potemplate = self.factory.makePOTemplate(
             productseries=self.productseries)
 
         # Add a Serbian translation.
-        serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
-        sr_pofile = self.factory.makePOFile(serbian.code, potemplate)
+        sr_pofile = self.factory.makePOFile('sr', potemplate)
 
         psls = list(self.productseries.productserieslanguages)
         self.assertEquals(len(psls), 1)
@@ -53,23 +54,30 @@
         # ProductSeriesLanguage object correctly keeps values
         # for a language, productseries itself and POFile.
         sr_psl = psls[0]
-        self.assertEquals(sr_psl.productseries, self.productseries)
-        self.assertEquals(sr_psl.language, serbian)
-        self.assertEquals(sr_psl.pofile, sr_pofile)
-
+        self.assertEquals(self.productseries, sr_psl.productseries)
+        self.assertEquals(sr_pofile.language, sr_psl.language)
+        self.assertEquals(sr_pofile, sr_psl.pofile)
+        self.assertEquals([sr_pofile], list(sr_psl.pofiles))
+
+    def test_productserieslanguages_languages_sorting(self):
+        # ProductSeriesLanguages are sorted alphabetically by language.
+        potemplate = self.factory.makePOTemplate(
+            productseries=self.productseries)
+
+        # Add a Serbian translation.
+        serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
+        sr_pofile = self.factory.makePOFile(serbian.code, potemplate)
         # Add another translation (eg. "Albanian", so it sorts
         # it before Serbian).
         albanian = getUtility(ILanguageSet).getLanguageByCode('sq')
         sq_pofile = self.factory.makePOFile(albanian.code, potemplate)
+
         psls = list(self.productseries.productserieslanguages)
-        self.assertEquals(len(psls), 2)
-
-        # Ordering is alphabetic by English name of the language.
         self.assertEquals(psls[0].language, albanian)
         self.assertEquals(psls[1].language, serbian)
 
-    def test_TwoTemplatesWithTranslations(self):
-        # There is a template and one translation.
+    def test_two_templates_pofile_not_set(self):
+        # With two templates, pofile attribute doesn't get set.
         potemplate1 = self.factory.makePOTemplate(
             productseries=self.productseries)
         potemplate2 = self.factory.makePOTemplate(
@@ -81,26 +89,11 @@
         serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
         pofile1 = self.factory.makePOFile(serbian.code, potemplate1)
         psls = list(self.productseries.productserieslanguages)
-        self.assertEquals(len(psls), 1)
 
         # `pofile` is not set when there's more than one template.
-        sr_psl = self.productseries.productserieslanguages[0]
-        self.assertEquals(sr_psl.productseries, self.productseries)
-        self.assertEquals(sr_psl.language, serbian)
+        sr_psl = psls[0]
         self.assertEquals(sr_psl.pofile, None)
 
-        # A POFile is returned where it exists, and a DummyPOFile where
-        # it doesn't.
-        self.assertEquals(2, len(sr_psl.pofiles))
-        self.assertEquals(potemplate2, sr_psl.pofiles[0].potemplate)
-        self.assertEquals(pofile1, sr_psl.pofiles[1])
-
-        # If we provide a POFile for the other template, `pofiles`
-        # returns both (ordered by decreasing priority).
-        pofile2 = self.factory.makePOFile(serbian.code, potemplate2)
-        sr_psl = self.productseries.productserieslanguages[0]
-        self.assertEquals(list(sr_psl.pofiles), [pofile2, pofile1])
-
 
 class TestProductSeriesLanguageStatsCalculation(TestCaseWithFactory):
     """Test ProductSeriesLanguage statistics calculation."""