379
379
self.user = self.factory.makePerson()
380
380
self.language = self.factory.makeLanguage()
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)
389
389
def test_product_always_shares(self):
390
390
product = self.factory.makeProduct()
392
392
product.sharesTranslationsWithOtherSide(self.user, self.language))
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)
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)
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))
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
419
product.translationpermission = TranslationPermission.OPEN
420
self.assertFalse(self._doesPackageShare(package))
421
product.translationpermission = TranslationPermission.CLOSED
422
self.assertFalse(self._doesPackageShare(package))
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
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))
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))