def test_translation_group(self):
     group = self.factory.makeTranslationGroup(
         self.distroseries.distribution.owner, url=None)
     self.distroseries.distribution.translationgroup = group
     self.view = DistroSeriesLanguageView(self.dsl, LaunchpadTestRequest())
     self.view.initialize()
     self.assertEquals(self.view.translation_group, group)
 def setUp(self):
     # Create a distroseries that uses translations.
     TestCaseWithFactory.setUp(self)
     self.distroseries = self.factory.makeDistroSeries()
     self.language = getUtility(ILanguageSet).getLanguageByCode('sr')
     sourcepackagename = self.factory.makeSourcePackageName()
     potemplate = self.factory.makePOTemplate(
         distroseries=self.distroseries,
         sourcepackagename=sourcepackagename)
     self.factory.makePOFile('sr', potemplate)
     self.distroseries.updateStatistics(transaction)
     self.dsl = self.distroseries.distroserieslanguages[0]
     self.view = DistroSeriesLanguageView(self.dsl, LaunchpadTestRequest())
    def test_translation_team(self):
        # Just having a group doesn't mean there's a translation
        # team as well.
        group = self.factory.makeTranslationGroup(
            self.distroseries.distribution.owner, url=None)
        self.distroseries.distribution.translationgroup = group
        self.assertEquals(self.view.translation_team, None)

        # Setting a translator for this languages makes it
        # appear as the translation_team.
        team = self.factory.makeTeam()
        translator = getUtility(ITranslatorSet).new(group, self.language, team)
        # Recreate the view because we are using a cached property.
        self.view = DistroSeriesLanguageView(self.dsl, LaunchpadTestRequest())
        self.view.initialize()
        self.assertEquals(self.view.translation_team, translator)
 def test_translation_group(self):
     group = self.factory.makeTranslationGroup(
         self.distroseries.distribution.owner, url=None)
     self.distroseries.distribution.translationgroup = group
     self.view = DistroSeriesLanguageView(
         self.dsl, LaunchpadTestRequest())
     self.view.initialize()
     self.assertEquals(self.view.translation_group, group)
class TestDistroSeriesLanguage(TestCaseWithFactory):
    """Test DistroSeriesLanguage view."""

    layer = LaunchpadZopelessLayer

    def setUp(self):
        # Create a distroseries that uses translations.
        TestCaseWithFactory.setUp(self)
        self.distroseries = self.factory.makeDistroSeries()
        self.language = getUtility(ILanguageSet).getLanguageByCode('sr')
        sourcepackagename = self.factory.makeSourcePackageName()
        potemplate = self.factory.makePOTemplate(
            distroseries=self.distroseries,
            sourcepackagename=sourcepackagename)
        self.factory.makePOFile('sr', potemplate)
        self.distroseries.updateStatistics(transaction)
        self.dsl = self.distroseries.distroserieslanguages[0]
        self.view = DistroSeriesLanguageView(self.dsl, LaunchpadTestRequest())

    def test_empty_view(self):
        self.assertEquals(self.view.translation_group, None)
        self.assertEquals(self.view.translation_team, None)
        self.assertEquals(self.view.context, self.dsl)

    def test_translation_group(self):
        group = self.factory.makeTranslationGroup(
            self.distroseries.distribution.owner, url=None)
        self.distroseries.distribution.translationgroup = group
        self.view = DistroSeriesLanguageView(self.dsl, LaunchpadTestRequest())
        self.view.initialize()
        self.assertEquals(self.view.translation_group, group)

    def test_translation_team(self):
        # Just having a group doesn't mean there's a translation
        # team as well.
        group = self.factory.makeTranslationGroup(
            self.distroseries.distribution.owner, url=None)
        self.distroseries.distribution.translationgroup = group
        self.assertEquals(self.view.translation_team, None)

        # Setting a translator for this languages makes it
        # appear as the translation_team.
        team = self.factory.makeTeam()
        translator = getUtility(ITranslatorSet).new(group, self.language, team)
        # Recreate the view because we are using a cached property.
        self.view = DistroSeriesLanguageView(self.dsl, LaunchpadTestRequest())
        self.view.initialize()
        self.assertEquals(self.view.translation_team, translator)

    def test_sourcepackagenames_bulk_loaded(self):
        # SourcePackageName records referenced by POTemplates
        # are bulk loaded. Accessing the sourcepackagename attribute
        # of a potemplate does not require an additional SQL query.
        self.view.initialize()
        template = self.view.batchnav.currentBatch()[0]
        with StormStatementRecorder() as recorder:
            template.sourcepackagename
        self.assertThat(recorder, HasQueryCount(Equals(0)))
 def setUp(self):
     # Create a distroseries that uses translations.
     TestCaseWithFactory.setUp(self)
     self.distroseries = self.factory.makeDistroSeries()
     self.language = getUtility(ILanguageSet).getLanguageByCode('sr')
     sourcepackagename = self.factory.makeSourcePackageName()
     potemplate = self.factory.makePOTemplate(
         distroseries=self.distroseries,
         sourcepackagename=sourcepackagename)
     self.factory.makePOFile('sr', potemplate)
     self.distroseries.updateStatistics(transaction)
     self.dsl = self.distroseries.distroserieslanguages[0]
     self.view = DistroSeriesLanguageView(
         self.dsl, LaunchpadTestRequest())
    def test_translation_team(self):
        # Just having a group doesn't mean there's a translation
        # team as well.
        group = self.factory.makeTranslationGroup(
            self.distroseries.distribution.owner, url=None)
        self.distroseries.distribution.translationgroup = group
        self.assertEquals(self.view.translation_team, None)

        # Setting a translator for this languages makes it
        # appear as the translation_team.
        team = self.factory.makeTeam()
        translator = getUtility(ITranslatorSet).new(
            group, self.language, team)
        # Recreate the view because we are using a cached property.
        self.view = DistroSeriesLanguageView(
            self.dsl, LaunchpadTestRequest())
        self.view.initialize()
        self.assertEquals(self.view.translation_team, translator)
class TestDistroSeriesLanguage(TestCaseWithFactory):
    """Test DistroSeriesLanguage view."""

    layer = LaunchpadZopelessLayer

    def setUp(self):
        # Create a distroseries that uses translations.
        TestCaseWithFactory.setUp(self)
        self.distroseries = self.factory.makeDistroSeries()
        self.language = getUtility(ILanguageSet).getLanguageByCode('sr')
        sourcepackagename = self.factory.makeSourcePackageName()
        potemplate = self.factory.makePOTemplate(
            distroseries=self.distroseries,
            sourcepackagename=sourcepackagename)
        self.factory.makePOFile('sr', potemplate)
        self.distroseries.updateStatistics(transaction)
        self.dsl = self.distroseries.distroserieslanguages[0]
        self.view = DistroSeriesLanguageView(
            self.dsl, LaunchpadTestRequest())

    def test_empty_view(self):
        self.assertEquals(self.view.translation_group, None)
        self.assertEquals(self.view.translation_team, None)
        self.assertEquals(self.view.context, self.dsl)

    def test_translation_group(self):
        group = self.factory.makeTranslationGroup(
            self.distroseries.distribution.owner, url=None)
        self.distroseries.distribution.translationgroup = group
        self.view = DistroSeriesLanguageView(
            self.dsl, LaunchpadTestRequest())
        self.view.initialize()
        self.assertEquals(self.view.translation_group, group)

    def test_translation_team(self):
        # Just having a group doesn't mean there's a translation
        # team as well.
        group = self.factory.makeTranslationGroup(
            self.distroseries.distribution.owner, url=None)
        self.distroseries.distribution.translationgroup = group
        self.assertEquals(self.view.translation_team, None)

        # Setting a translator for this languages makes it
        # appear as the translation_team.
        team = self.factory.makeTeam()
        translator = getUtility(ITranslatorSet).new(
            group, self.language, team)
        # Recreate the view because we are using a cached property.
        self.view = DistroSeriesLanguageView(
            self.dsl, LaunchpadTestRequest())
        self.view.initialize()
        self.assertEquals(self.view.translation_team, translator)

    def test_sourcepackagenames_bulk_loaded(self):
        # SourcePackageName records referenced by POTemplates
        # are bulk loaded. Accessing the sourcepackagename attribute
        # of a potemplate does not require an additional SQL query.
        self.view.initialize()
        template = self.view.batchnav.currentBatch()[0]
        with StormStatementRecorder() as recorder:
            template.sourcepackagename
        self.assertThat(recorder, HasQueryCount(Equals(0)))