def test_make_name_from_path_falls_back_on_default(self):
     # make_name_from_path falls back on the default you pass if the
     # path contains no helpful identifiers.
     default_name = 'default-name'
     self.assertEqual(
         default_name,
         make_name_from_path('messages.pot', default=default_name))
 def test_make_name_from_path_sanitizes_default(self):
     # If make_name_from_path has to fall back on the default you
     # pass, it sanitizes the domain it gets for use as a template
     # name, just as it would a domain that was extracted from the
     # path.
     self.assertEqual(
         "foo-bar",
         make_name_from_path('messages.pot', default="foo_bar"))
Example #3
0
    def __init__(self, files, productseries=None,
                 distroseries=None, sourcepackagename=None):
        """Create the approver and build the approval list by comparing
        the given files as found in the source tree to the database entries.

        Either productseries or distroseries/sourcepackagename must be given
        but not all.

        :param files: A list of paths to the translation files.
        :param productseries: The productseries that this upload is for.
        :param distroseries: The distroseries that this upload is for.
        :param sourcepackagename: The sourcepackagename that this upload
            is for.
        """

        assert (distroseries is None or sourcepackagename is not None), (
                "Please specify distroseries and sourcepackagename together.")

        self._potemplates = {}
        self._n_matched = 0
        self.is_approval_possible = True

        potemplate_names = set()
        product_name = get_product_name(productseries)

        importer = TranslationImporter()
        self._potemplateset = getUtility(IPOTemplateSet).getSubset(
            iscurrent=True, productseries=productseries,
            distroseries=distroseries, sourcepackagename=sourcepackagename)
        for path in files:
            if importer.isTemplateName(path):
                potemplate = self._potemplateset.getPOTemplateByPath(path)
                if potemplate is None:
                    name = make_name_from_path(path, default=product_name)
                    potemplate = self._potemplateset.getPOTemplateByName(name)
                else:
                    name = potemplate.name
                # Template names must occur only once.
                if name in potemplate_names:
                    self.is_approval_possible = False
                else:
                    potemplate_names.add(name)
                if potemplate is not None:
                    self._n_matched += 1
                self._potemplates[path] = potemplate
        # The simplest case of exactly one file and one POTemplate object is
        # always approved.
        if len(self._potemplateset) == len(self._potemplates) == 1:
            self._potemplates[self._potemplates.keys()[0]] = (
                list(self._potemplateset)[0])
            self.is_approval_possible = True
 def test_make_name_from_path(self):
     # Chain both methods for convenience.
     self.assertEqual(
         'my-domain', make_name_from_path("po/My_Do@main/messages.pot"))