def test_does_not_replace_domain_if_path_contains_no_useful_name(self): # For an upload to a package (where there's no fallback to a # product name), if the path contains no meaningful domain name # but matches that of an existing template, even though the # entry gets approved for import into that template, the # existing template's domain name stays as it was. generic_path = u'po/messages.pot' package = self.factory.makeSourcePackage() package_kwargs = { 'distroseries': package.distroseries, 'sourcepackagename': package.sourcepackagename, } template = self.factory.makePOTemplate(**package_kwargs) original_domain = template.translation_domain entry = self.queue.addOrUpdateEntry(generic_path, self.factory.getUniqueString(), True, template.owner, potemplate=template, **package_kwargs) approver = TranslationBranchApprover(generic_path, **package_kwargs) approver.approve(entry) self.assertEqual(original_domain, template.translation_domain)
def run(self): """See `IRosettaUploadJob`.""" with server(get_ro_server(), no_replace=True): # This is not called upon job creation because the branch would # neither have been mirrored nor scanned then. self._init_translation_file_lists() # Get the product series that are connected to this branch and # that want to upload translations. productseriesset = getUtility(IProductSeriesSet) productseries = productseriesset.findByTranslationsImportBranch( self.branch, self.force_translations_upload) translation_import_queue = getUtility(ITranslationImportQueue) for series in productseries: approver = TranslationBranchApprover(self.file_names, productseries=series) for iter_info in self._iter_lists_and_uploaders(series): file_names, changed_files, uploader = iter_info for upload_file_name, upload_file_content in changed_files: if len(upload_file_content) == 0: continue # Skip empty files entry = translation_import_queue.addOrUpdateEntry( upload_file_name, upload_file_content, True, uploader, productseries=series) approver.approve(entry)
def test_approve_new_package_template(self): # The approver has sufficient privileges to create a new # template on a source package. package = self.factory.makeSourcePackage() package_kwargs = {"distroseries": package.distroseries, "sourcepackagename": package.sourcepackagename} template = self.factory.makePOTemplate(**package_kwargs) entry = self.factory.makeTranslationImportQueueEntry(path="messages.pot", potemplate=template, **package_kwargs) self.becomeTheApprover() approver = TranslationBranchApprover([template.path], **package_kwargs) approver.approve(entry)
def test_approve_new_product_template(self): # The approver has sufficient privileges to create a new # template on a product. template = self.factory.makePOTemplate() entry = self.factory.makeTranslationImportQueueEntry( "messages.pot", potemplate=template, productseries=template.productseries ) self.becomeTheApprover() approver = TranslationBranchApprover([template.path], productseries=template.productseries) approver.approve(entry)
def test_approve_new_product_template(self): # The approver has sufficient privileges to create a new # template on a product. template = self.factory.makePOTemplate() entry = self.factory.makeTranslationImportQueueEntry( 'messages.pot', potemplate=template, productseries=template.productseries) self.becomeTheApprover() approver = TranslationBranchApprover( [template.path], productseries=template.productseries) approver.approve(entry)
def test_approve_new_package_template(self): # The approver has sufficient privileges to create a new # template on a source package. package = self.factory.makeSourcePackage() package_kwargs = { 'distroseries': package.distroseries, 'sourcepackagename': package.sourcepackagename, } template = self.factory.makePOTemplate(**package_kwargs) entry = self.factory.makeTranslationImportQueueEntry( path='messages.pot', potemplate=template, **package_kwargs) self.becomeTheApprover() approver = TranslationBranchApprover([template.path], **package_kwargs) approver.approve(entry)
def test_approve_sharing_template(self): # The approver has sufficient privileges to approve templates # that will have POFiles copied over from sharing templates. productseries = self.factory.makeProductSeries() package = self.factory.makeSourcePackage() package_kwargs = { 'distroseries': package.distroseries, 'sourcepackagename': package.sourcepackagename, } self.factory.makePackagingLink(productseries=productseries, **package_kwargs) template_name = self.factory.getUniqueString() template_path = "%s.pot" % template_name self.factory.makePOFile(potemplate=self.factory.makePOTemplate( name=template_name, productseries=productseries)) self.factory.makePOFile(potemplate=self.factory.makePOTemplate( name=template_name, **package_kwargs)) new_series = self.factory.makeProductSeries( product=productseries.product) entry = self.factory.makeTranslationImportQueueEntry( path=template_path, productseries=new_series) self.becomeTheApprover() TranslationBranchApprover([template_path], new_series).approve(entry)
def test_does_not_replace_domain_if_path_contains_no_useful_name(self): # For an upload to a package (where there's no fallback to a # product name), if the path contains no meaningful domain name # but matches that of an existing template, even though the # entry gets approved for import into that template, the # existing template's domain name stays as it was. generic_path = u"po/messages.pot" package = self.factory.makeSourcePackage() package_kwargs = {"distroseries": package.distroseries, "sourcepackagename": package.sourcepackagename} template = self.factory.makePOTemplate(**package_kwargs) original_domain = template.translation_domain entry = self.queue.addOrUpdateEntry( generic_path, self.factory.getUniqueString(), True, template.owner, potemplate=template, **package_kwargs ) approver = TranslationBranchApprover(generic_path, **package_kwargs) approver.approve(entry) self.assertEqual(original_domain, template.translation_domain)
def run(self): """See `IRosettaUploadJob`.""" with server(get_ro_server(), no_replace=True): # This is not called upon job creation because the branch would # neither have been mirrored nor scanned then. self._init_translation_file_lists() # Get the product series that are connected to this branch and # that want to upload translations. productseriesset = getUtility(IProductSeriesSet) productseries = productseriesset.findByTranslationsImportBranch( self.branch, self.force_translations_upload) translation_import_queue = getUtility(ITranslationImportQueue) for series in productseries: approver = TranslationBranchApprover(self.file_names, productseries=series) for iter_info in self._iter_lists_and_uploaders(series): file_names, changed_files, uploader = iter_info for upload_file_name, upload_file_content in changed_files: if len(upload_file_content) == 0: continue # Skip empty files entry = translation_import_queue.addOrUpdateEntry( upload_file_name, upload_file_content, True, uploader, productseries=series) approver.approve(entry)
def test_new_package_template_without_domain_is_not_approved(self): # If an upload for a package has no information that a template # name or domain could be based on, it is not approved. # Template domains for packages must generally be unique for the # entire distribution, but in practice it's too variable to # figure out here. package = self.factory.makeSourcePackage() package_kwargs = { 'distroseries': package.distroseries, 'sourcepackagename': package.sourcepackagename, } entry = self.queue.addOrUpdateEntry('messages.pot', self.factory.getUniqueString(), True, self.factory.makePerson(), **package_kwargs) TranslationBranchApprover(entry.path, **package_kwargs).approve(entry) self.assertEqual(RosettaImportStatus.NEEDS_REVIEW, entry.status)
def _createApprover(self, file_or_files): if not isinstance(file_or_files, (tuple, list)): paths = (file_or_files, ) else: paths = file_or_files return TranslationBranchApprover(paths, productseries=self.series)