~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/tests/test_translationpolicy.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-02-15 23:54:54 UTC
  • mfrom: (12289.12.22 devel-710591-importer)
  • Revision ID: launchpad@pqm.canonical.com-20110215235454-spq1uya72313gslf
[r=jtv][bug=710591] Fix translation import script to use old-style
 imports on source packages if no upstream project is configured.

Show diffs side-by-side

added added

removed removed

Lines of Context:
379
379
        self.user = self.factory.makePerson()
380
380
        self.language = self.factory.makeLanguage()
381
381
 
382
 
    def _doesPackageShare(self, sourcepackage, from_upstream=False):
 
382
    def _doesPackageShare(self, sourcepackage, by_maintainer=False):
383
383
        """Does this `SourcePackage` share with upstream?"""
384
384
        distro = sourcepackage.distroseries.distribution
385
385
        return distro.sharesTranslationsWithOtherSide(
386
386
            self.user, self.language, sourcepackage=sourcepackage,
387
 
            purportedly_upstream=from_upstream)
 
387
            purportedly_upstream=by_maintainer)
388
388
 
389
389
    def test_product_always_shares(self):
390
390
        product = self.factory.makeProduct()
391
391
        self.assertTrue(
392
392
            product.sharesTranslationsWithOtherSide(self.user, self.language))
393
393
 
394
 
    def test_distribution_shares_only_if_invited(self):
 
394
    def _makePackageAndProductSeries(self):
395
395
        package = self.factory.makeSourcePackage()
396
396
        self.factory.makePackagingLink(
397
397
            sourcepackagename=package.sourcepackagename,
398
398
            distroseries=package.distroseries)
399
 
        product = package.productseries.product
 
399
        return (package, package.productseries)
 
400
 
 
401
    def test_distribution_shares_only_if_invited_with_template(self):
 
402
        # With an upstream template, translations will be shared if the
 
403
        # product invites edits.
 
404
        package, productseries = self._makePackageAndProductSeries()
 
405
        product = productseries.product
 
406
        self.factory.makePOTemplate(productseries=productseries)
400
407
 
401
408
        product.translationpermission = TranslationPermission.OPEN
402
409
        self.assertTrue(self._doesPackageShare(package))
403
410
        product.translationpermission = TranslationPermission.CLOSED
404
411
        self.assertFalse(self._doesPackageShare(package))
405
412
 
406
 
    def test_unlinked_package_shares_only_upstream_translations(self):
 
413
    def test_distribution_shares_not_without_template(self):
 
414
        # Without an upstream template, translations will not be shared
 
415
        # if they do not originate from uploads done by the maintainer.
 
416
        package, productseries = self._makePackageAndProductSeries()
 
417
        product = productseries.product
 
418
 
 
419
        product.translationpermission = TranslationPermission.OPEN
 
420
        self.assertFalse(self._doesPackageShare(package))
 
421
        product.translationpermission = TranslationPermission.CLOSED
 
422
        self.assertFalse(self._doesPackageShare(package))
 
423
 
 
424
    def test_distribution_shares_only_by_maintainer_without_template(self):
 
425
        # Without an upstream template, translations will be shared
 
426
        # if they do originate from uploads done by the maintainer.
 
427
        package, productseries = self._makePackageAndProductSeries()
 
428
        product = productseries.product
 
429
 
 
430
        product.translationpermission = TranslationPermission.OPEN
 
431
        self.assertTrue(self._doesPackageShare(package, by_maintainer=True))
 
432
        product.translationpermission = TranslationPermission.CLOSED
 
433
        self.assertTrue(self._doesPackageShare(package, by_maintainer=True))
 
434
 
 
435
    def test_distribution_shares_only_by_maintainer_without_upstream(self):
 
436
        # Without an upstream product series, translations will only be
 
437
        # shared if they do originate from uploads done by the maintainer.
407
438
        package = self.factory.makeSourcePackage()
408
 
        distro = package.distroseries.distribution
409
 
        for from_upstream in [False, True]:
 
439
        for by_maintainer in [False, True]:
410
440
            self.assertEqual(
411
 
                from_upstream, self._doesPackageShare(package, from_upstream))
 
441
                by_maintainer, self._doesPackageShare(package, by_maintainer))