Merge lp:~henninge/launchpad/bug-408899 into lp:launchpad

Proposed by Henning Eggers
Status: Merged
Merged at revision: not available
Proposed branch: lp:~henninge/launchpad/bug-408899
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~henninge/launchpad/bug-408899
Reviewer Review Type Date Requested Status
Paul Hummer (community) Approve
Review via email: mp+9775@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

= Probelem and fix =

The TranslationBranchApprover creates potemplate names from file names. These names must be a "valid_name" as defined by the database constraint of that name. Unfortunately the conversion method only took underscores into account, converting them to dashes.

This fix makes sure that the names produced conform to the valid_name constraint, most notably making all letters lower case. It also uses sanitize_name to remove all other invalid characters from the name.

= Test =

bin/test -vv -ttemplate_name

= Demo and QA =

Configure a product series to import translation templates from a branch. Push a pot file with capital letters and other invalid characters in it to that branch. Wait for that file to be uploaded to the translation import queue and you can see that it creates a potemplate entry with a valid name. In fact, without this fix it would not have been uploaded at all.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/lp/translations/model/translationbranchapprover.py
  lib/lp/translations/tests/test_translationbranchapprover.py

Revision history for this message
Paul Hummer (rockstar) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/model/translationbranchapprover.py'
2--- lib/lp/translations/model/translationbranchapprover.py 2009-07-17 00:26:05 +0000
3+++ lib/lp/translations/model/translationbranchapprover.py 2009-08-06 15:14:02 +0000
4@@ -11,6 +11,7 @@
5
6 from zope.component import getUtility
7
8+from canonical.launchpad.validators.name import sanitize_name
9 from lp.translations.interfaces.potemplate import IPOTemplateSet
10 from lp.translations.interfaces.translationimportqueue import (
11 RosettaImportStatus)
12@@ -119,7 +120,7 @@
13 @staticmethod
14 def makeName(domain):
15 """Make a template name from a translation domain."""
16- return domain.replace('_', '-')
17+ return sanitize_name(domain.replace('_', '-').lower())
18
19 @staticmethod
20 def makeNameFromPath(path):
21
22=== modified file 'lib/lp/translations/tests/test_translationbranchapprover.py'
23--- lib/lp/translations/tests/test_translationbranchapprover.py 2009-07-17 00:26:05 +0000
24+++ lib/lp/translations/tests/test_translationbranchapprover.py 2009-08-06 15:14:02 +0000
25@@ -8,12 +8,13 @@
26 from unittest import TestLoader
27 from zope.component import getUtility
28
29+from canonical.launchpad.validators.name import valid_name
30+from canonical.testing import LaunchpadZopelessLayer
31 from lp.translations.interfaces.translationimportqueue import (
32 ITranslationImportQueue, RosettaImportStatus)
33 from lp.testing import TestCaseWithFactory
34 from lp.translations.model.translationbranchapprover import (
35 TranslationBranchApprover)
36-from canonical.testing import LaunchpadZopelessLayer
37
38 class TestTranslationBranchApprover(TestCaseWithFactory):
39
40@@ -93,14 +94,15 @@
41 translation_domain, entry.potemplate.translation_domain)
42
43 def test_template_name(self):
44- # The name should not contain underscores any more.
45- translation_domain = ('translation_domain_with_underscores')
46- template_name = translation_domain.replace('_', '-')
47+ # The name is derived from the file name and must be a valid name.
48+ translation_domain = (u'Invalid-Name_with illegal#Characters')
49 template_path = translation_domain + u'.pot'
50 entry = self._upload_file(template_path)
51 approver = self._create_approver(template_path)
52 approver.approve(entry)
53- self.assertEqual(template_name, entry.potemplate.name)
54+ self.assertTrue(valid_name(entry.potemplate.name))
55+ self.assertEqual(u'invalid-name-withillegalcharacters',
56+ entry.potemplate.name)
57
58 def test_replace_existing_approved(self):
59 # Template files that replace existing entries are approved.