~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/scripts/tests/test_translations_approval.py

  • Committer: Stuart Bishop
  • Date: 2011-10-20 06:24:21 UTC
  • mfrom: (9893.10.6 trivial)
  • mto: This revision was merged to the branch mainline in revision 14178.
  • Revision ID: stuart.bishop@canonical.com-20111020062421-8irsskytxf2i0srg
Merged trivial into distinct-db-users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
import logging
 
5
import transaction
 
6
 
 
7
from canonical.testing.layers import LaunchpadScriptLayer
 
8
from lp.testing import TestCaseWithFactory
 
9
from lp.translations.enums import RosettaImportStatus
 
10
from lp.translations.model.translationimportqueue import (
 
11
    TranslationImportQueue,
 
12
    )
 
13
from lp.translations.scripts.import_queue_gardener import ImportQueueGardener
 
14
 
 
15
 
 
16
class TestTranslationsImportApproval(TestCaseWithFactory):
 
17
 
 
18
    layer = LaunchpadScriptLayer
 
19
 
 
20
    def setUp(self):
 
21
        super(TestTranslationsImportApproval, self).setUp()
 
22
        self.queue = TranslationImportQueue()
 
23
        self.script = ImportQueueGardener(
 
24
            'translations-import-queue-gardener',
 
25
            dbuser='translations_import_queue_gardener',
 
26
            test_args=[])
 
27
        self.script.logger.setLevel(logging.FATAL)
 
28
        self.owner = self.factory.makePerson()
 
29
        self.productseries = self.factory.makeProductSeries()
 
30
 
 
31
    def test_templates_with_unique_directories_are_approved(self):
 
32
        # If there are multiple templates with unique directories then the
 
33
        # approval is ok.
 
34
 
 
35
        # Make two valid templates with different directories.
 
36
        self.factory.makePOTemplate(
 
37
            path='po/evolution-3.2.pot',
 
38
            productseries=self.productseries)
 
39
        self.factory.makePOTemplate(
 
40
            path='other-po/evolution-3.0.pot',
 
41
            productseries=self.productseries)
 
42
        tiqe = self.factory.makeTranslationImportQueueEntry(
 
43
            path='po/fr.po', productseries=self.productseries)
 
44
        transaction.commit()
 
45
        self.assertIsNone(tiqe.import_into)
 
46
        self.assertEqual(RosettaImportStatus.NEEDS_REVIEW, tiqe.status)
 
47
        self.script.main()
 
48
        self.assertIsNotNone(tiqe.import_into)
 
49
        self.assertEqual(RosettaImportStatus.APPROVED, tiqe.status)
 
50
 
 
51
    def test_inactive_templates_do_not_block_approval(self):
 
52
        # If all but one of the templates with the same path directory are
 
53
        # marked as obsolete, the approval proceeds.
 
54
        # See bug 867411 for more details.
 
55
 
 
56
        # Make a valid template.
 
57
        self.factory.makePOTemplate(
 
58
            path='po/evolution-3.2.pot',
 
59
            productseries=self.productseries)
 
60
        # Make a obsolete template with the same directory.
 
61
        self.factory.makePOTemplate(
 
62
            path='po/evolution-3.0.pot',
 
63
            productseries=self.productseries,
 
64
            iscurrent=False)
 
65
        tiqe = self.factory.makeTranslationImportQueueEntry(
 
66
            path='po/fr.po', productseries=self.productseries)
 
67
        transaction.commit()
 
68
        self.assertIsNone(tiqe.import_into)
 
69
        self.assertEqual(RosettaImportStatus.NEEDS_REVIEW, tiqe.status)
 
70
        self.script.main()
 
71
        self.assertIsNotNone(tiqe.import_into)
 
72
        self.assertEqual(RosettaImportStatus.APPROVED, tiqe.status)