~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/scripts/tests/test_queue.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-15 02:41:34 UTC
  • mfrom: (13211.2.5 bug-791204)
  • Revision ID: launchpad@pqm.canonical.com-20110615024134-qp73i2q6lo58be2u
[r=gmb][bug=791204] Prepare PackageUpload for handling copy-job
 uploads in queue script and on +queue page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from canonical.database.sqlbase import ISOLATION_LEVEL_READ_COMMITTED
21
21
from canonical.launchpad.database.librarian import LibraryFileAlias
22
22
from canonical.launchpad.interfaces.librarian import ILibraryFileAliasSet
 
23
from canonical.launchpad.interfaces.lpstorm import IStore
23
24
from canonical.librarian.testing.server import fillLibrarianFile
24
25
from canonical.librarian.utils import filechunks
25
26
from canonical.testing.layers import (
59
60
    CommandRunner,
60
61
    CommandRunnerError,
61
62
    name_queue_map,
 
63
    QueueAction,
62
64
    )
63
65
from lp.testing import (
64
66
    celebrity_logged_in,
65
67
    person_logged_in,
66
68
    TestCaseWithFactory,
67
69
    )
68
 
 
69
 
 
70
 
class TestQueueBase(TestCase):
 
70
from lp.testing.fakemethod import FakeMethod
 
71
 
 
72
 
 
73
class TestQueueBase:
71
74
    """Base methods for queue tool test classes."""
72
75
 
73
76
    def setUp(self):
107
110
        self.assertEqual(to_addrs, expected_to_addrs)
108
111
 
109
112
 
110
 
class TestQueueTool(TestQueueBase):
 
113
class TestQueueTool(TestQueueBase, TestCase):
111
114
    layer = LaunchpadZopelessLayer
112
115
    dbuser = config.uploadqueue.dbuser
113
116
 
924
927
            'override binary pmount', component_name='partner')
925
928
 
926
929
 
 
930
class TestQueueActionLite(TestCaseWithFactory):
 
931
    """A lightweight unit test case for `QueueAction`.
 
932
 
 
933
    Meant for detailed tests that would be too expensive for full end-to-end
 
934
    tests.
 
935
    """
 
936
 
 
937
    layer = LaunchpadZopelessLayer
 
938
 
 
939
    def makeQueueAction(self, package_upload, distroseries=None):
 
940
        """Create a `QueueAction` for use with a `PackageUpload`.
 
941
 
 
942
        The action's `display` method is set to a `FakeMethod`.
 
943
        """
 
944
        if distroseries is None:
 
945
            distroseries = self.factory.makeDistroSeries(
 
946
                status=SeriesStatus.CURRENT)
 
947
        distro = distroseries.distribution
 
948
        if package_upload is None:
 
949
            package_upload = self.factory.makePackageUpload(
 
950
                distroseries=distroseries, archive=distro.main_archive)
 
951
        component = self.factory.makeComponent()
 
952
        section = self.factory.makeSection()
 
953
        suite = "%s-%s" % (distroseries.name, "release")
 
954
        queue = None
 
955
        priority_name = "STANDARD"
 
956
        display = FakeMethod()
 
957
        terms = ['*']
 
958
        return QueueAction(
 
959
            distro.name, suite, queue, terms, component.name,
 
960
            section.name, priority_name, display)
 
961
 
 
962
    def test_display_actions_have_privileges_for_PackageCopyJob(self):
 
963
        # The methods that display uploads have privileges to work with
 
964
        # a PackageUpload that has a copy job.
 
965
        # Bundling tests for multiple operations into one test because
 
966
        # the database user change requires a costly commit.
 
967
        upload = self.factory.makeCopyJobPackageUpload()
 
968
        action = self.makeQueueAction(upload)
 
969
        self.layer.txn.commit()
 
970
        self.layer.switchDbUser(config.uploadqueue.dbuser)
 
971
 
 
972
        action.displayItem(upload)
 
973
        self.assertNotEqual(0, action.display.call_count)
 
974
        action.display.calls = []
 
975
        action.displayInfo(upload)
 
976
        self.assertNotEqual(0, action.display.call_count)
 
977
 
 
978
    def test_accept_actions_have_privileges_for_PackageCopyJob(self):
 
979
        # The script also has privileges to approve uploads that have
 
980
        # copy jobs.
 
981
        distroseries = self.factory.makeDistroSeries(
 
982
            status=SeriesStatus.CURRENT)
 
983
        upload = self.factory.makeCopyJobPackageUpload(distroseries)
 
984
        self.layer.txn.commit()
 
985
        self.layer.switchDbUser(config.uploadqueue.dbuser)
 
986
        upload.acceptFromQueue(DevNullLogger(), dry_run=True)
 
987
        # Flush changes to make sure we're not caching any updates that
 
988
        # the database won't allow.  If this passes, we've got the
 
989
        # privileges.
 
990
        IStore(upload).flush()
 
991
 
 
992
    def test_displayItem_displays_PackageUpload_with_source(self):
 
993
        # displayItem can display a source package upload.
 
994
        upload = self.factory.makeSourcePackageUpload()
 
995
        action = self.makeQueueAction(upload)
 
996
        action.displayItem(upload)
 
997
        self.assertNotEqual(0, action.display.call_count)
 
998
 
 
999
    def test_displayItem_displays_PackageUpload_with_PackageCopyJob(self):
 
1000
        # displayItem can display a copy-job package upload.
 
1001
        upload = self.factory.makeCopyJobPackageUpload()
 
1002
        action = self.makeQueueAction(upload)
 
1003
        action.displayItem(upload)
 
1004
        self.assertNotEqual(0, action.display.call_count)
 
1005
 
 
1006
    def test_displayInfo_displays_PackageUpload_with_source(self):
 
1007
        # displayInfo can display a source package upload.
 
1008
        upload = self.factory.makeSourcePackageUpload()
 
1009
        action = self.makeQueueAction(upload)
 
1010
        action.displayInfo(upload)
 
1011
        self.assertNotEqual(0, action.display.call_count)
 
1012
 
 
1013
    def test_displayInfo_displays_PackageUpload_with_PackageCopyJob(self):
 
1014
        # displayInfo can display a copy-job package upload.
 
1015
        upload = self.factory.makeCopyJobPackageUpload()
 
1016
        action = self.makeQueueAction(upload)
 
1017
        action.displayInfo(upload)
 
1018
        self.assertNotEqual(0, action.display.call_count)
 
1019
 
 
1020
 
927
1021
class TestQueuePageClosingBugs(TestCaseWithFactory):
928
1022
    # The distroseries +queue page can close bug when accepting
929
1023
    # packages.  Unit tests for that belong here.
954
1048
            self.assertEqual(bug_task.status, BugTaskStatus.FIXRELEASED)
955
1049
 
956
1050
 
957
 
class TestQueueToolInJail(TestQueueBase):
 
1051
class TestQueueToolInJail(TestQueueBase, TestCase):
958
1052
    layer = LaunchpadZopelessLayer
959
1053
    dbuser = config.uploadqueue.dbuser
960
1054